From fa3536d20280fd35904c463348487c3ac5a7ad3b Mon Sep 17 00:00:00 2001 From: Ashish Shenoy Date: Thu, 12 May 2016 09:47:16 -0700 Subject: [PATCH] Store SST file compression algorithm as a TableProperty Summary: Store SST file compression algorithm as a TableProperty. Test Plan: Modified and ran the table_test UT that checks for TableProperties Reviewers: IslamAbdelRahman Reviewed By: IslamAbdelRahman Subscribers: lgalanis, andrewkr, dhruba, IslamAbdelRahman Differential Revision: https://reviews.facebook.net/D58017 --- include/rocksdb/table_properties.h | 4 ++++ table/block_based_table_builder.cc | 1 + table/meta_blocks.cc | 6 ++++++ table/table_properties.cc | 6 ++++++ table/table_test.cc | 3 +++ 5 files changed, 20 insertions(+) diff --git a/include/rocksdb/table_properties.h b/include/rocksdb/table_properties.h index db7dede60..af6c43815 100644 --- a/include/rocksdb/table_properties.h +++ b/include/rocksdb/table_properties.h @@ -44,6 +44,7 @@ struct TablePropertiesNames { static const std::string kComparator; static const std::string kMergeOperator; static const std::string kPropertyCollectors; + static const std::string kCompression; }; extern const std::string kPropertiesBlock; @@ -170,6 +171,9 @@ struct TableProperties { // {collector_name[1]},{collector_name[2]},{collector_name[3]} .. std::string property_collectors_names; + // The compression algo used to compress the SST files. + std::string compression_name; + // user collected properties UserCollectedProperties user_collected_properties; UserCollectedProperties readable_properties; diff --git a/table/block_based_table_builder.cc b/table/block_based_table_builder.cc index 32aabcf9a..46a4b1403 100644 --- a/table/block_based_table_builder.cc +++ b/table/block_based_table_builder.cc @@ -830,6 +830,7 @@ Status BlockBasedTableBuilder::Finish() { r->props.merge_operator_name = r->ioptions.merge_operator != nullptr ? r->ioptions.merge_operator->Name() : "nullptr"; + r->props.compression_name = CompressionTypeToString(r->compression_type); std::string property_collectors_names = "["; property_collectors_names = "["; diff --git a/table/meta_blocks.cc b/table/meta_blocks.cc index 360d0c376..7028d106c 100644 --- a/table/meta_blocks.cc +++ b/table/meta_blocks.cc @@ -88,6 +88,10 @@ void PropertyBlockBuilder::AddTableProperty(const TableProperties& props) { if (!props.column_family_name.empty()) { Add(TablePropertiesNames::kColumnFamilyName, props.column_family_name); } + + if (!props.compression_name.empty()) { + Add(TablePropertiesNames::kCompression, props.compression_name); + } } Slice PropertyBlockBuilder::Finish() { @@ -228,6 +232,8 @@ Status ReadProperties(const Slice& handle_value, RandomAccessFileReader* file, new_table_properties->merge_operator_name = raw_val.ToString(); } else if (key == TablePropertiesNames::kPropertyCollectors) { new_table_properties->property_collectors_names = raw_val.ToString(); + } else if (key == TablePropertiesNames::kCompression) { + new_table_properties->compression_name = raw_val.ToString(); } else { // handle user-collected properties new_table_properties->user_collected_properties.insert( diff --git a/table/table_properties.cc b/table/table_properties.cc index 7ca2072f2..12e9054ad 100644 --- a/table/table_properties.cc +++ b/table/table_properties.cc @@ -113,6 +113,11 @@ std::string TableProperties::ToString( : property_collectors_names, prop_delim, kv_delim); + AppendProperty( + result, "SST file compression algo", + compression_name.empty() ? std::string("N/A") : compression_name, + prop_delim, kv_delim); + return result; } @@ -155,6 +160,7 @@ const std::string TablePropertiesNames::kMergeOperator = "rocksdb.merge.operator"; const std::string TablePropertiesNames::kPropertyCollectors = "rocksdb.property.collectors"; +const std::string TablePropertiesNames::kCompression = "rocksdb.compression"; extern const std::string kPropertiesBlock = "rocksdb.properties"; // Old property block name for backward compatibility diff --git a/table/table_test.cc b/table/table_test.cc index 4a3f4ed07..d027dfd99 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -1071,6 +1071,7 @@ TEST_F(BlockBasedTableTest, BlockBasedTableProperties2) { { Options options; + options.compression = CompressionType::kNoCompression; BlockBasedTableOptions table_options; options.table_factory.reset(NewBlockBasedTableFactory(table_options)); @@ -1088,6 +1089,8 @@ TEST_F(BlockBasedTableTest, BlockBasedTableProperties2) { ASSERT_EQ("[]", props.property_collectors_names); // No filter policy is used ASSERT_EQ("", props.filter_policy_name); + // Compression type == that set: + ASSERT_EQ("NoCompression", props.compression_name); c.ResetTableReader(); }