diff --git a/include/rocksdb/table_properties.h b/include/rocksdb/table_properties.h index dacfd1436..70e8d2cba 100644 --- a/include/rocksdb/table_properties.h +++ b/include/rocksdb/table_properties.h @@ -53,6 +53,7 @@ struct TablePropertiesNames { static const std::string kPrefixExtractorName; static const std::string kPropertyCollectors; static const std::string kCompression; + static const std::string kCompressionOptions; static const std::string kCreationTime; static const std::string kOldestKeyTime; }; @@ -209,6 +210,9 @@ struct TableProperties { // The compression algo used to compress the SST files. std::string compression_name; + // Compression options used to compress the SST files. + std::string compression_options; + // 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 dff23c916..479311f5b 100644 --- a/table/block_based_table_builder.cc +++ b/table/block_based_table_builder.cc @@ -924,6 +924,8 @@ void BlockBasedTableBuilder::WritePropertiesBlock( : "nullptr"; rep_->props.compression_name = CompressionTypeToString(rep_->compression_type); + rep_->props.compression_options = + CompressionOptionsToString(rep_->compression_opts); rep_->props.prefix_extractor_name = rep_->moptions.prefix_extractor != nullptr ? rep_->moptions.prefix_extractor->Name() diff --git a/table/meta_blocks.cc b/table/meta_blocks.cc index 6c04d079a..57111cfeb 100644 --- a/table/meta_blocks.cc +++ b/table/meta_blocks.cc @@ -115,6 +115,9 @@ void PropertyBlockBuilder::AddTableProperty(const TableProperties& props) { if (!props.compression_name.empty()) { Add(TablePropertiesNames::kCompression, props.compression_name); } + if (!props.compression_options.empty()) { + Add(TablePropertiesNames::kCompressionOptions, props.compression_options); + } } Slice PropertyBlockBuilder::Finish() { @@ -313,6 +316,8 @@ Status ReadProperties(const Slice& handle_value, RandomAccessFileReader* file, new_table_properties->property_collectors_names = raw_val.ToString(); } else if (key == TablePropertiesNames::kCompression) { new_table_properties->compression_name = raw_val.ToString(); + } else if (key == TablePropertiesNames::kCompressionOptions) { + new_table_properties->compression_options = 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 56e1d03f1..b7aaea481 100644 --- a/table/table_properties.cc +++ b/table/table_properties.cc @@ -153,6 +153,11 @@ std::string TableProperties::ToString( compression_name.empty() ? std::string("N/A") : compression_name, prop_delim, kv_delim); + AppendProperty( + result, "SST file compression options", + compression_options.empty() ? std::string("N/A") : compression_options, + prop_delim, kv_delim); + AppendProperty(result, "creation time", creation_time, prop_delim, kv_delim); AppendProperty(result, "time stamp of earliest key", oldest_key_time, @@ -223,6 +228,8 @@ const std::string TablePropertiesNames::kPrefixExtractorName = const std::string TablePropertiesNames::kPropertyCollectors = "rocksdb.property.collectors"; const std::string TablePropertiesNames::kCompression = "rocksdb.compression"; +const std::string TablePropertiesNames::kCompressionOptions = + "rocksdb.compression_options"; const std::string TablePropertiesNames::kCreationTime = "rocksdb.creation.time"; const std::string TablePropertiesNames::kOldestKeyTime = "rocksdb.oldest.key.time"; diff --git a/util/compression.h b/util/compression.h index b568238e6..b901ceb35 100644 --- a/util/compression.h +++ b/util/compression.h @@ -25,6 +25,7 @@ #include "util/coding.h" #include "util/compression_context_cache.h" #include "util/memory_allocator.h" +#include "util/string_util.h" #ifdef SNAPPY #include @@ -508,6 +509,31 @@ inline std::string CompressionTypeToString(CompressionType compression_type) { } } +inline std::string CompressionOptionsToString( + CompressionOptions& compression_options) { + std::string result; + result.reserve(512); + result.append("window_bits=") + .append(ToString(compression_options.window_bits)) + .append("; "); + result.append("level=") + .append(ToString(compression_options.level)) + .append("; "); + result.append("strategy=") + .append(ToString(compression_options.strategy)) + .append("; "); + result.append("max_dict_bytes=") + .append(ToString(compression_options.max_dict_bytes)) + .append("; "); + result.append("zstd_max_train_bytes=") + .append(ToString(compression_options.zstd_max_train_bytes)) + .append("; "); + result.append("enabled=") + .append(ToString(compression_options.enabled)) + .append("; "); + return result; +} + // compress_format_version can have two values: // 1 -- decompressed sizes for BZip2 and Zlib are not included in the compressed // block. Also, decompressed sizes for LZ4 are encoded in platform-dependent