Skip to content

Commit

Permalink
feat(config): add rocksdb.wal_compression to allow enable wal compr…
Browse files Browse the repository at this point in the history
…ession (#2607)

Co-authored-by: Twice <[email protected]>
Co-authored-by: hulk <[email protected]>
  • Loading branch information
3 people authored Oct 18, 2024
1 parent 576c431 commit 4709734
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kvrocks.conf
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,16 @@ rocksdb.max_background_flushes -1
# Default: 2
rocksdb.max_subcompactions 2

# If enabled WAL records will be compressed before they are written. Only
# ZSTD (= kZSTD) is supported (until streaming support is adapted for other
# compression types). Compressed WAL records will be read in supported
# versions (>= RocksDB 7.4.0 for ZSTD) regardless of this setting when
# the WAL is read.
#
# Accept value: "no", "zstd"
# Default is no
rocksdb.wal_compression no

# In order to limit the size of WALs, RocksDB uses DBOptions::max_total_wal_size
# as the trigger of column family flush. Once WALs exceed this size, RocksDB
# will start forcing the flush of column families to allow deletion of some
Expand Down
12 changes: 12 additions & 0 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ const std::vector<ConfigEnum<rocksdb::CompressionType>> compression_types{[] {
return res;
}()};

const std::vector<ConfigEnum<rocksdb::CompressionType>> wal_compression_types{[] {
std::vector<ConfigEnum<rocksdb::CompressionType>> res;
res.reserve(engine::WalCompressionOptions.size());
for (const auto &e : engine::WalCompressionOptions) {
res.push_back({e.name, e.type});
}
return res;
}()};

const std::vector<ConfigEnum<BlockCacheType>> cache_types{[] {
std::vector<ConfigEnum<BlockCacheType>> res;
res.reserve(engine::CacheOptions.size());
Expand Down Expand Up @@ -211,6 +220,9 @@ Config::Config() {
{"rocksdb.max_background_flushes", true, new IntField(&rocks_db.max_background_flushes, 2, -1, 32)},
{"rocksdb.max_subcompactions", false, new IntField(&rocks_db.max_subcompactions, 2, 0, 16)},
{"rocksdb.delayed_write_rate", false, new Int64Field(&rocks_db.delayed_write_rate, 0, 0, INT64_MAX)},
{"rocksdb.wal_compression", true,
new EnumField<rocksdb::CompressionType>(&rocks_db.wal_compression, wal_compression_types,
rocksdb::CompressionType::kNoCompression)},
{"rocksdb.wal_ttl_seconds", true, new IntField(&rocks_db.wal_ttl_seconds, 3 * 3600, 0, INT_MAX)},
{"rocksdb.wal_size_limit_mb", true, new IntField(&rocks_db.wal_size_limit_mb, 16384, 0, INT_MAX)},
{"rocksdb.max_total_wal_size", false, new IntField(&rocks_db.max_total_wal_size, 64 * 4 * 2, 0, INT_MAX)},
Expand Down
1 change: 1 addition & 0 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ struct Config {
int64_t delayed_write_rate;
int compaction_readahead_size;
int target_file_size_base;
rocksdb::CompressionType wal_compression;
int wal_ttl_seconds;
int wal_size_limit_mb;
int max_total_wal_size;
Expand Down
1 change: 1 addition & 0 deletions src/storage/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ rocksdb::Options Storage::InitRocksDBOptions() {
options.num_levels = 7;
options.compression_opts.level = config_->rocks_db.compression_level;
options.compression_per_level.resize(options.num_levels);
options.wal_compression = config_->rocks_db.wal_compression;
// only compress levels >= 2
for (int i = 0; i < options.num_levels; ++i) {
if (i < 2) {
Expand Down
5 changes: 5 additions & 0 deletions src/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ inline const std::vector<CompressionOption> CompressionOptions = {
{rocksdb::kZSTD, "zstd", "kZSTD"},
};

inline const std::vector<CompressionOption> WalCompressionOptions = {
{rocksdb::kNoCompression, "no", "kNoCompression"},
{rocksdb::kZSTD, "zstd", "kZSTD"},
};

struct CacheOption {
BlockCacheType type;
const std::string name;
Expand Down
1 change: 1 addition & 0 deletions tests/cppunit/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ TEST(Config, GetAndSet) {
{"rocksdb.row_cache_size", "100"},
{"rocksdb.rate_limiter_auto_tuned", "yes"},
{"rocksdb.compression_level", "32767"},
{"rocksdb.wal_compression", "no"},
};
for (const auto &iter : immutable_cases) {
s = config.Set(nullptr, iter.first, iter.second);
Expand Down

0 comments on commit 4709734

Please sign in to comment.