add compression options to table properties (#5081)

Summary:
Since we are planning to use dictionary compression and to use different compression level, it is quite useful to add compression options to TableProperties. For example, in MyRocks, if the feature is available, we can query from information_schema.rocksdb_sst_props to see if all sst files are converted to ZSTD dictionary compressions. Resolves https://github.com/facebook/rocksdb/issues/4992

With this PR, user can query table properties through `GetPropertiesOfAllTables` API and get compression options as std::string:
`window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0;`
or table_properties->ToString() will also contain it
`# data blocks=1; # entries=13; # deletions=0; # merge operands=0; # range deletions=0; raw key size=143; raw average key size=11.000000; raw value size=39; raw average value size=3.000000; data block size=120; index block size (user-key? 0, delta-value? 0)=27; filter block size=0; (estimated) table size=147; filter policy name=N/A; prefix extractor name=nullptr; column family ID=0; column family name=default; comparator name=leveldb.BytewiseComparator; merge operator name=nullptr; property collectors names=[]; SST file compression algo=Snappy; SST file compression options=window_bits=-14; level=32767; strategy=0; max_dict_bytes=0; zstd_max_train_bytes=0; enabled=0; ; creation time=1552946632; time stamp of earliest key=1552946632;`
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5081

Differential Revision: D14716692

Pulled By: miasantreble

fbshipit-source-id: 7d2f2cf84e052bff876e71b4212cfdebf5be32dd
main
Zhongyi Xie 6 years ago committed by Facebook Github Bot
parent 14b3f683a1
commit 26015f3b48
  1. 4
      include/rocksdb/table_properties.h
  2. 2
      table/block_based_table_builder.cc
  3. 5
      table/meta_blocks.cc
  4. 7
      table/table_properties.cc
  5. 26
      util/compression.h

@ -53,6 +53,7 @@ struct TablePropertiesNames {
static const std::string kPrefixExtractorName; static const std::string kPrefixExtractorName;
static const std::string kPropertyCollectors; static const std::string kPropertyCollectors;
static const std::string kCompression; static const std::string kCompression;
static const std::string kCompressionOptions;
static const std::string kCreationTime; static const std::string kCreationTime;
static const std::string kOldestKeyTime; static const std::string kOldestKeyTime;
}; };
@ -209,6 +210,9 @@ struct TableProperties {
// The compression algo used to compress the SST files. // The compression algo used to compress the SST files.
std::string compression_name; std::string compression_name;
// Compression options used to compress the SST files.
std::string compression_options;
// user collected properties // user collected properties
UserCollectedProperties user_collected_properties; UserCollectedProperties user_collected_properties;
UserCollectedProperties readable_properties; UserCollectedProperties readable_properties;

@ -924,6 +924,8 @@ void BlockBasedTableBuilder::WritePropertiesBlock(
: "nullptr"; : "nullptr";
rep_->props.compression_name = rep_->props.compression_name =
CompressionTypeToString(rep_->compression_type); CompressionTypeToString(rep_->compression_type);
rep_->props.compression_options =
CompressionOptionsToString(rep_->compression_opts);
rep_->props.prefix_extractor_name = rep_->props.prefix_extractor_name =
rep_->moptions.prefix_extractor != nullptr rep_->moptions.prefix_extractor != nullptr
? rep_->moptions.prefix_extractor->Name() ? rep_->moptions.prefix_extractor->Name()

@ -115,6 +115,9 @@ void PropertyBlockBuilder::AddTableProperty(const TableProperties& props) {
if (!props.compression_name.empty()) { if (!props.compression_name.empty()) {
Add(TablePropertiesNames::kCompression, props.compression_name); Add(TablePropertiesNames::kCompression, props.compression_name);
} }
if (!props.compression_options.empty()) {
Add(TablePropertiesNames::kCompressionOptions, props.compression_options);
}
} }
Slice PropertyBlockBuilder::Finish() { Slice PropertyBlockBuilder::Finish() {
@ -313,6 +316,8 @@ Status ReadProperties(const Slice& handle_value, RandomAccessFileReader* file,
new_table_properties->property_collectors_names = raw_val.ToString(); new_table_properties->property_collectors_names = raw_val.ToString();
} else if (key == TablePropertiesNames::kCompression) { } else if (key == TablePropertiesNames::kCompression) {
new_table_properties->compression_name = raw_val.ToString(); new_table_properties->compression_name = raw_val.ToString();
} else if (key == TablePropertiesNames::kCompressionOptions) {
new_table_properties->compression_options = raw_val.ToString();
} else { } else {
// handle user-collected properties // handle user-collected properties
new_table_properties->user_collected_properties.insert( new_table_properties->user_collected_properties.insert(

@ -153,6 +153,11 @@ std::string TableProperties::ToString(
compression_name.empty() ? std::string("N/A") : compression_name, compression_name.empty() ? std::string("N/A") : compression_name,
prop_delim, kv_delim); 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, "creation time", creation_time, prop_delim, kv_delim);
AppendProperty(result, "time stamp of earliest key", oldest_key_time, AppendProperty(result, "time stamp of earliest key", oldest_key_time,
@ -223,6 +228,8 @@ const std::string TablePropertiesNames::kPrefixExtractorName =
const std::string TablePropertiesNames::kPropertyCollectors = const std::string TablePropertiesNames::kPropertyCollectors =
"rocksdb.property.collectors"; "rocksdb.property.collectors";
const std::string TablePropertiesNames::kCompression = "rocksdb.compression"; 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::kCreationTime = "rocksdb.creation.time";
const std::string TablePropertiesNames::kOldestKeyTime = const std::string TablePropertiesNames::kOldestKeyTime =
"rocksdb.oldest.key.time"; "rocksdb.oldest.key.time";

@ -25,6 +25,7 @@
#include "util/coding.h" #include "util/coding.h"
#include "util/compression_context_cache.h" #include "util/compression_context_cache.h"
#include "util/memory_allocator.h" #include "util/memory_allocator.h"
#include "util/string_util.h"
#ifdef SNAPPY #ifdef SNAPPY
#include <snappy.h> #include <snappy.h>
@ -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: // compress_format_version can have two values:
// 1 -- decompressed sizes for BZip2 and Zlib are not included in the compressed // 1 -- decompressed sizes for BZip2 and Zlib are not included in the compressed
// block. Also, decompressed sizes for LZ4 are encoded in platform-dependent // block. Also, decompressed sizes for LZ4 are encoded in platform-dependent

Loading…
Cancel
Save