diff --git a/HISTORY.md b/HISTORY.md index 7e20a0105..bb01abd92 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -48,6 +48,7 @@ * Extended `FlushJobInfo` and `CompactionJobInfo` in listener.h to provide information about the blob files generated by a flush/compaction and garbage collected during compaction in Integrated BlobDB. Added struct members `blob_file_addition_infos` and `blob_file_garbage_infos` that contain this information. * Extended parameter `output_file_names` of `CompactFiles` API to also include paths of the blob files generated by the compaction in Integrated BlobDB. * Most `BackupEngine` functions now return `IOStatus` instead of `Status`. Most existing code should be compatible with this change but some calls might need to be updated. +* Add a new field `level_at_creation` in `TablePropertiesCollectorFactory::Context` to capture the level at creating the SST file (i.e, table), of which the properties are being collected. ### Miscellaneous * Add a paranoid check where in case FileSystem layer doesn't fill the buffer but returns succeed, checksum is unlikely to match even if buffer contains a previous block. The byte modified is not useful anyway, so it isn't expected to change any behavior when FileSystem is satisfying its contract. diff --git a/db/table_properties_collector.h b/db/table_properties_collector.h index f80570e4a..5b3d5b56c 100644 --- a/db/table_properties_collector.h +++ b/db/table_properties_collector.h @@ -42,7 +42,7 @@ class IntTblPropCollectorFactory { virtual ~IntTblPropCollectorFactory() {} // has to be thread-safe virtual IntTblPropCollector* CreateIntTblPropCollector( - uint32_t column_family_id) = 0; + uint32_t column_family_id, int level_at_creation) = 0; // The name of the properties collector can be used for debugging purpose. virtual const char* Name() const = 0; @@ -92,9 +92,10 @@ class UserKeyTablePropertiesCollectorFactory std::shared_ptr user_collector_factory) : user_collector_factory_(user_collector_factory) {} virtual IntTblPropCollector* CreateIntTblPropCollector( - uint32_t column_family_id) override { + uint32_t column_family_id, int level_at_creation) override { TablePropertiesCollectorFactory::Context context; context.column_family_id = column_family_id; + context.level_at_creation = level_at_creation; return new UserKeyTablePropertiesCollector( user_collector_factory_->CreateTablePropertiesCollector(context)); } diff --git a/db/table_properties_collector_test.cc b/db/table_properties_collector_test.cc index 301302bae..e6f88aca9 100644 --- a/db/table_properties_collector_test.cc +++ b/db/table_properties_collector_test.cc @@ -40,6 +40,7 @@ class TablePropertiesTest : public testing::Test, namespace { static const uint32_t kTestColumnFamilyId = 66; static const std::string kTestColumnFamilyName = "test_column_fam"; +static const int kTestLevel = 1; void MakeBuilder( const Options& options, const ImmutableOptions& ioptions, @@ -51,11 +52,10 @@ void MakeBuilder( std::unique_ptr wf(new test::StringSink); writable->reset( new WritableFileWriter(std::move(wf), "" /* don't care */, EnvOptions())); - int unknown_level = -1; TableBuilderOptions tboptions( ioptions, moptions, internal_comparator, int_tbl_prop_collector_factories, options.compression, options.compression_opts, kTestColumnFamilyId, - kTestColumnFamilyName, unknown_level); + kTestColumnFamilyName, kTestLevel); builder->reset(NewTableBuilder(tboptions, writable->get())); } } // namespace @@ -199,6 +199,7 @@ class RegularKeysStartWithAFactory : public IntTblPropCollectorFactory, TablePropertiesCollector* CreateTablePropertiesCollector( TablePropertiesCollectorFactory::Context context) override { EXPECT_EQ(kTestColumnFamilyId, context.column_family_id); + EXPECT_EQ(kTestLevel, context.level_at_creation); if (!backward_mode_) { return new RegularKeysStartWithA(); } else { @@ -206,7 +207,7 @@ class RegularKeysStartWithAFactory : public IntTblPropCollectorFactory, } } IntTblPropCollector* CreateIntTblPropCollector( - uint32_t /*column_family_id*/) override { + uint32_t /*column_family_id*/, int /* level_at_creation */) override { return new RegularKeysStartWithAInternal(); } const char* Name() const override { return "RegularKeysStartWithA"; } diff --git a/include/rocksdb/table_properties.h b/include/rocksdb/table_properties.h index 569f745f9..ad7c7fb37 100644 --- a/include/rocksdb/table_properties.h +++ b/include/rocksdb/table_properties.h @@ -137,7 +137,11 @@ class TablePropertiesCollectorFactory : public Customizable { public: struct Context { uint32_t column_family_id; + // The level at creating the SST file (i.e, table), of which the + // properties are being collected. + int level_at_creation = kUnknownLevelAtCreation; static const uint32_t kUnknownColumnFamily; + static const int kUnknownLevelAtCreation = -1; }; virtual ~TablePropertiesCollectorFactory() {} diff --git a/table/block_based/block_based_table_builder.cc b/table/block_based/block_based_table_builder.cc index 0dd864fc3..afedc91d6 100644 --- a/table/block_based/block_based_table_builder.cc +++ b/table/block_based/block_based_table_builder.cc @@ -507,7 +507,8 @@ struct BlockBasedTableBuilder::Rep { assert(factory); table_properties_collectors.emplace_back( - factory->CreateIntTblPropCollector(tbo.column_family_id)); + factory->CreateIntTblPropCollector(tbo.column_family_id, + tbo.level_at_creation)); } table_properties_collectors.emplace_back( new BlockBasedTablePropertiesCollector( diff --git a/table/plain/plain_table_builder.cc b/table/plain/plain_table_builder.cc index 79e5fbfb3..c3b2e4687 100644 --- a/table/plain/plain_table_builder.cc +++ b/table/plain/plain_table_builder.cc @@ -59,8 +59,8 @@ extern const uint64_t kLegacyPlainTableMagicNumber = 0x4f3418eb7a8f13b8ull; PlainTableBuilder::PlainTableBuilder( const ImmutableOptions& ioptions, const MutableCFOptions& moptions, const IntTblPropCollectorFactories* int_tbl_prop_collector_factories, - uint32_t column_family_id, WritableFileWriter* file, uint32_t user_key_len, - EncodingType encoding_type, size_t index_sparseness, + uint32_t column_family_id, int level_at_creation, WritableFileWriter* file, + uint32_t user_key_len, EncodingType encoding_type, size_t index_sparseness, uint32_t bloom_bits_per_key, const std::string& column_family_name, uint32_t num_probes, size_t huge_page_tlb_size, double hash_table_ratio, bool store_index_in_file, const std::string& db_id, @@ -119,7 +119,8 @@ PlainTableBuilder::PlainTableBuilder( assert(factory); table_properties_collectors_.emplace_back( - factory->CreateIntTblPropCollector(column_family_id)); + factory->CreateIntTblPropCollector(column_family_id, + level_at_creation)); } } diff --git a/table/plain/plain_table_builder.h b/table/plain/plain_table_builder.h index 860554f14..d281fdb16 100644 --- a/table/plain/plain_table_builder.h +++ b/table/plain/plain_table_builder.h @@ -39,13 +39,14 @@ class PlainTableBuilder: public TableBuilder { PlainTableBuilder( const ImmutableOptions& ioptions, const MutableCFOptions& moptions, const IntTblPropCollectorFactories* int_tbl_prop_collector_factories, - uint32_t column_family_id, WritableFileWriter* file, - uint32_t user_key_size, EncodingType encoding_type, - size_t index_sparseness, uint32_t bloom_bits_per_key, - const std::string& column_family_name, uint32_t num_probes = 6, - size_t huge_page_tlb_size = 0, double hash_table_ratio = 0, - bool store_index_in_file = false, const std::string& db_id = "", - const std::string& db_session_id = "", uint64_t file_number = 0); + uint32_t column_family_id, int level_at_creation, + WritableFileWriter* file, uint32_t user_key_size, + EncodingType encoding_type, size_t index_sparseness, + uint32_t bloom_bits_per_key, const std::string& column_family_name, + uint32_t num_probes = 6, size_t huge_page_tlb_size = 0, + double hash_table_ratio = 0, bool store_index_in_file = false, + const std::string& db_id = "", const std::string& db_session_id = "", + uint64_t file_number = 0); // No copying allowed PlainTableBuilder(const PlainTableBuilder&) = delete; void operator=(const PlainTableBuilder&) = delete; diff --git a/table/plain/plain_table_factory.cc b/table/plain/plain_table_factory.cc index 22844bee6..737b6b58f 100644 --- a/table/plain/plain_table_factory.cc +++ b/table/plain/plain_table_factory.cc @@ -80,9 +80,10 @@ TableBuilder* PlainTableFactory::NewTableBuilder( return new PlainTableBuilder( table_builder_options.ioptions, table_builder_options.moptions, table_builder_options.int_tbl_prop_collector_factories, - table_builder_options.column_family_id, file, table_options_.user_key_len, - table_options_.encoding_type, table_options_.index_sparseness, - table_options_.bloom_bits_per_key, + table_builder_options.column_family_id, + table_builder_options.level_at_creation, file, + table_options_.user_key_len, table_options_.encoding_type, + table_options_.index_sparseness, table_options_.bloom_bits_per_key, table_builder_options.column_family_name, 6, table_options_.huge_page_tlb_size, table_options_.hash_table_ratio, table_options_.store_index_in_file, table_builder_options.db_id, diff --git a/table/sst_file_writer_collectors.h b/table/sst_file_writer_collectors.h index 2dbd611ab..44cd84116 100644 --- a/table/sst_file_writer_collectors.h +++ b/table/sst_file_writer_collectors.h @@ -78,7 +78,7 @@ class SstFileWriterPropertiesCollectorFactory : version_(version), global_seqno_(global_seqno) {} virtual IntTblPropCollector* CreateIntTblPropCollector( - uint32_t /*column_family_id*/) override { + uint32_t /*column_family_id*/, int /* level_at_creation */) override { return new SstFileWriterPropertiesCollector(version_, global_seqno_); }