Skip to content

Commit

Permalink
support bottom level compression (#3634)
Browse files Browse the repository at this point in the history
* support bottom level compression

* address liuyu85cn's comments
  • Loading branch information
panda-sheep authored Jan 5, 2022
1 parent b3da209 commit 40adfab
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/kvstore/RocksEngineConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ DEFINE_bool(enable_partitioned_index_filter, false, "True for partitioned index
DEFINE_string(rocksdb_compression,
"snappy",
"Compression algorithm used by RocksDB, "
"options: no,snappy,lz4,lz4hc,zstd,zlib,bzip2");
"options: no, snappy, lz4, lz4hc, zstd, zlib, bzip2, xpress");

DEFINE_string(rocksdb_bottommost_compression,
"disable",
"Specify the bottommost level compression algorithm"
"options: no, snappy, lz4, lz4hc, zstd, zlib, bzip2, xpress, disable");

DEFINE_string(rocksdb_compression_per_level,
"",
"Specify per level compression algorithm, "
Expand Down Expand Up @@ -142,7 +148,9 @@ static const std::unordered_map<std::string, rocksdb::CompressionType> kCompress
{"lz4hc", rocksdb::kLZ4HCCompression},
{"zstd", rocksdb::kZSTD},
{"zlib", rocksdb::kZlibCompression},
{"bzip2", rocksdb::kBZip2Compression}};
{"bzip2", rocksdb::kBZip2Compression},
{"xpress", rocksdb::kXpressCompression},
{"disable", rocksdb::kDisableCompressionOption}};

static rocksdb::Status initRocksdbCompression(rocksdb::Options& baseOpts) {
// Set the general compression algorithm
Expand All @@ -153,6 +161,13 @@ static rocksdb::Status initRocksdbCompression(rocksdb::Options& baseOpts) {
return rocksdb::Status::InvalidArgument();
}
baseOpts.compression = it->second;

it = kCompressionTypeMap.find(FLAGS_rocksdb_bottommost_compression);
if (it == kCompressionTypeMap.end()) {
LOG(ERROR) << "Unsupported compression type: " << FLAGS_rocksdb_bottommost_compression;
return rocksdb::Status::InvalidArgument();
}
baseOpts.bottommost_compression = it->second;
}
if (FLAGS_rocksdb_compression_per_level.empty()) {
return rocksdb::Status::OK();
Expand Down
1 change: 1 addition & 0 deletions src/kvstore/RocksEngineConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ DECLARE_string(part_man_type);

DECLARE_string(rocksdb_compression_per_level);
DECLARE_string(rocksdb_compression);
DECLARE_string(rocksdb_bottommost_compression);

DECLARE_bool(enable_rocksdb_statistics);
DECLARE_string(rocksdb_stats_level);
Expand Down
20 changes: 20 additions & 0 deletions src/kvstore/test/RocksEngineConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ TEST(RocksEngineConfigTest, CompressionConfigTest) {
ASSERT_EQ(rocksdb::Status::kInvalidArgument, status.code());
}

{
FLAGS_rocksdb_compression = "lz4";
FLAGS_rocksdb_compression_per_level = "";
FLAGS_rocksdb_bottommost_compression = "zstd";
rocksdb::Options options;
auto status = initRocksdbOptions(options, 1);
ASSERT_TRUE(status.ok()) << status.ToString();
ASSERT_EQ(rocksdb::kLZ4Compression, options.compression);
ASSERT_EQ(rocksdb::kZSTD, options.bottommost_compression);

rocksdb::DB* db = nullptr;
SCOPE_EXIT {
delete db;
};
options.create_if_missing = true;
fs::TempDir rootPath("/tmp/RocksDBCompressionConfigTest.XXXXXX");
status = rocksdb::DB::Open(options, rootPath.path(), &db);
ASSERT_TRUE(status.ok()) << status.ToString();
}

{
FLAGS_rocksdb_compression = "lz4";
FLAGS_rocksdb_compression_per_level = "no:no::snappy::zstd";
Expand Down

0 comments on commit 40adfab

Please sign in to comment.