2016-10-18 23:59:37 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2016-10-18 23:59:37 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
2021-09-29 11:01:57 +00:00
|
|
|
|
2019-03-26 17:15:43 +00:00
|
|
|
#include "db/table_properties_collector.h"
|
2016-10-18 23:59:37 +00:00
|
|
|
#include "rocksdb/types.h"
|
2021-09-29 11:01:57 +00:00
|
|
|
#include "util/coding.h"
|
2016-10-18 23:59:37 +00:00
|
|
|
#include "util/string_util.h"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2016-10-18 23:59:37 +00:00
|
|
|
|
|
|
|
// Table Properties that are specific to tables created by SstFileWriter.
|
|
|
|
struct ExternalSstFilePropertyNames {
|
|
|
|
// value of this property is a fixed uint32 number.
|
|
|
|
static const std::string kVersion;
|
|
|
|
// value of this property is a fixed uint64 number.
|
|
|
|
static const std::string kGlobalSeqno;
|
|
|
|
};
|
|
|
|
|
|
|
|
// PropertiesCollector used to add properties specific to tables
|
|
|
|
// generated by SstFileWriter
|
|
|
|
class SstFileWriterPropertiesCollector : public IntTblPropCollector {
|
|
|
|
public:
|
|
|
|
explicit SstFileWriterPropertiesCollector(int32_t version,
|
|
|
|
SequenceNumber global_seqno)
|
|
|
|
: version_(version), global_seqno_(global_seqno) {}
|
|
|
|
|
2018-03-05 21:08:17 +00:00
|
|
|
virtual Status InternalAdd(const Slice& /*key*/, const Slice& /*value*/,
|
|
|
|
uint64_t /*file_size*/) override {
|
2016-10-18 23:59:37 +00:00
|
|
|
// Intentionally left blank. Have no interest in collecting stats for
|
|
|
|
// individual key/value pairs.
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
Refactor to avoid confusing "raw block" (#10408)
Summary:
We have a lot of confusing code because of mixed, sometimes
completely opposite uses of of the term "raw block" or "raw contents",
sometimes within the same source file. For example, in `BlockBasedTableBuilder`,
`raw_block_contents` and `raw_size` generally referred to uncompressed block
contents and size, while `WriteRawBlock` referred to writing a block that
is already compressed if it is going to be. Meanwhile, in
`BlockBasedTable`, `raw_block_contents` either referred to a (maybe
compressed) block with trailer, or a maybe compressed block maybe
without trailer. (Note: left as follow-up work to use C++ typing to
better sort out the various kinds of BlockContents.)
This change primarily tries to apply some consistent terminology around
the kinds of block representations, avoiding the unclear "raw". (Any
meaning of "raw" assumes some bias toward the storage layer or toward
the logical data layer.) Preferred terminology:
* **Serialized block** - bytes that go into storage. For block-based table
(usually the case) this includes the block trailer. WART: block `size` may or
may not include the trailer; need to be clear about whether it does or not.
* **Maybe compressed block** - like a serialized block, but without the
trailer (or no promise of including a trailer). Must be accompanied by a
CompressionType.
* **Uncompressed block** - "payload" bytes that are either stored with no
compression, used as input to compression function, or result of
decompression function.
* **Parsed block** - an in-memory form of a block in block cache, as it is
used by the table reader. Different C++ types are used depending on the
block type (see block_like_traits.h).
Other refactorings:
* Misc corrections/improvements of internal API comments
* Remove a few misleading / unhelpful / redundant comments.
* Use move semantics in some places to simplify contracts
* Use better parameter names to indicate which parameters are used for
outputs
* Remove some extraneous `extern`
* Various clean-ups to `CacheDumperImpl` (mostly unnecessary code)
Pull Request resolved: https://github.com/facebook/rocksdb/pull/10408
Test Plan: existing tests
Reviewed By: akankshamahajan15
Differential Revision: D38172617
Pulled By: pdillinger
fbshipit-source-id: ccb99299f324ac5ca46996d34c5089621a4f260c
2022-09-22 18:25:32 +00:00
|
|
|
virtual void BlockAdd(uint64_t /* block_uncomp_bytes */,
|
2021-03-25 21:58:23 +00:00
|
|
|
uint64_t /* block_compressed_bytes_fast */,
|
|
|
|
uint64_t /* block_compressed_bytes_slow */) override {
|
2019-03-18 19:07:35 +00:00
|
|
|
// Intentionally left blank. No interest in collecting stats for
|
|
|
|
// blocks.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-18 23:59:37 +00:00
|
|
|
virtual Status Finish(UserCollectedProperties* properties) override {
|
|
|
|
// File version
|
|
|
|
std::string version_val;
|
|
|
|
PutFixed32(&version_val, static_cast<uint32_t>(version_));
|
|
|
|
properties->insert({ExternalSstFilePropertyNames::kVersion, version_val});
|
|
|
|
|
|
|
|
// Global Sequence number
|
|
|
|
std::string seqno_val;
|
|
|
|
PutFixed64(&seqno_val, static_cast<uint64_t>(global_seqno_));
|
|
|
|
properties->insert({ExternalSstFilePropertyNames::kGlobalSeqno, seqno_val});
|
|
|
|
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const char* Name() const override {
|
|
|
|
return "SstFileWriterPropertiesCollector";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual UserCollectedProperties GetReadableProperties() const override {
|
2022-05-06 20:03:58 +00:00
|
|
|
return {{ExternalSstFilePropertyNames::kVersion, std::to_string(version_)}};
|
2016-10-18 23:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t version_;
|
|
|
|
SequenceNumber global_seqno_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SstFileWriterPropertiesCollectorFactory
|
|
|
|
: public IntTblPropCollectorFactory {
|
|
|
|
public:
|
|
|
|
explicit SstFileWriterPropertiesCollectorFactory(int32_t version,
|
|
|
|
SequenceNumber global_seqno)
|
|
|
|
: version_(version), global_seqno_(global_seqno) {}
|
|
|
|
|
|
|
|
virtual IntTblPropCollector* CreateIntTblPropCollector(
|
2021-09-28 19:33:03 +00:00
|
|
|
uint32_t /*column_family_id*/, int /* level_at_creation */) override {
|
2016-10-18 23:59:37 +00:00
|
|
|
return new SstFileWriterPropertiesCollector(version_, global_seqno_);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const char* Name() const override {
|
|
|
|
return "SstFileWriterPropertiesCollector";
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t version_;
|
|
|
|
SequenceNumber global_seqno_;
|
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|