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
|
2024-02-02 22:14:43 +00:00
|
|
|
class SstFileWriterPropertiesCollector : public InternalTblPropColl {
|
2016-10-18 23:59:37 +00:00
|
|
|
public:
|
|
|
|
explicit SstFileWriterPropertiesCollector(int32_t version,
|
|
|
|
SequenceNumber global_seqno)
|
|
|
|
: version_(version), global_seqno_(global_seqno) {}
|
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
void BlockAdd(uint64_t /* block_uncomp_bytes */,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
Status Finish(UserCollectedProperties* properties) override {
|
2016-10-18 23:59:37 +00:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
const char* Name() const override {
|
2016-10-18 23:59:37 +00:00
|
|
|
return "SstFileWriterPropertiesCollector";
|
|
|
|
}
|
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
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
|
2024-02-02 22:14:43 +00:00
|
|
|
: public InternalTblPropCollFactory {
|
2016-10-18 23:59:37 +00:00
|
|
|
public:
|
|
|
|
explicit SstFileWriterPropertiesCollectorFactory(int32_t version,
|
|
|
|
SequenceNumber global_seqno)
|
|
|
|
: version_(version), global_seqno_(global_seqno) {}
|
|
|
|
|
2024-02-02 22:14:43 +00:00
|
|
|
InternalTblPropColl* CreateInternalTblPropColl(
|
2024-06-18 17:51:29 +00:00
|
|
|
uint32_t /*column_family_id*/, int /* level_at_creation */,
|
|
|
|
int /* num_levels */,
|
|
|
|
SequenceNumber /* last_level_inclusive_max_seqno_threshold */) override {
|
2016-10-18 23:59:37 +00:00
|
|
|
return new SstFileWriterPropertiesCollector(version_, global_seqno_);
|
|
|
|
}
|
|
|
|
|
2024-01-31 21:14:42 +00:00
|
|
|
const char* Name() const override {
|
2016-10-18 23:59:37 +00:00
|
|
|
return "SstFileWriterPropertiesCollector";
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t version_;
|
|
|
|
SequenceNumber global_seqno_;
|
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|