From a3c24bcc31fbfaf50bb4248adafdaf9a86034622 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 13 Mar 2024 22:38:30 -0400 Subject: [PATCH] add rocksdb_bottommost_compression_level config option Signed-off-by: strawberry --- conduwuit-example.toml | 10 ++++++++++ src/config/mod.rs | 11 +++++++++++ src/database/abstraction/rocksdb.rs | 2 +- src/service/globals/mod.rs | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/conduwuit-example.toml b/conduwuit-example.toml index 4d186f67..7947ebc5 100644 --- a/conduwuit-example.toml +++ b/conduwuit-example.toml @@ -325,6 +325,16 @@ url_preview_check_root_domain = false # #rocksdb_compression_level = 32767 +# Level of compression the specified compression algorithm for the bottommost level/data for RocksDB to use. +# Default is 32767, which is internally read by RocksDB as the default magic number and +# translated to the library's default compression level as they all differ. +# See their `kDefaultCompressionLevel`. +# +# Since this is the bottommost level (generally old and least used data), it may be desirable to have a very +# high compression level here as it's lesss likely for this data to be used. Research your chosen compression algorithm. +# +#rocksdb_bottommost_compression_level = 32767 + # Whether to enable RocksDB "bottommost_compression". # At the expense of more CPU usage, this will further compress the database to reduce more storage. # It is recommended to use ZSTD compression with this for best compression results. diff --git a/src/config/mod.rs b/src/config/mod.rs index 02ff745c..b8eb00f6 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -123,6 +123,8 @@ pub struct Config { pub rocksdb_compression_algo: String, #[serde(default = "default_rocksdb_compression_level")] pub rocksdb_compression_level: i32, + #[serde(default = "default_rocksdb_bottommost_compression_level")] + pub rocksdb_bottommost_compression_level: i32, #[serde(default)] pub rocksdb_bottommost_compression: bool, @@ -368,6 +370,10 @@ impl fmt::Display for Config { ("RocksDB Compression Algorithm", &self.rocksdb_compression_algo), #[cfg(feature = "rocksdb")] ("RocksDB Compression Level", &self.rocksdb_compression_level.to_string()), + ( + "RocksDB Bottommost Compression Level", + &self.rocksdb_bottommost_compression_level.to_string(), + ), #[cfg(feature = "rocksdb")] ( "RocksDB Bottommost Level Compression", @@ -479,6 +485,11 @@ fn default_rocksdb_compression_algo() -> String { "zstd".to_owned() } /// compression level as they all differ. See their `kDefaultCompressionLevel`. fn default_rocksdb_compression_level() -> i32 { 32767 } +/// Default RocksDB compression level is 32767, which is internally read by +/// RocksDB as the default magic number and translated to the library's default +/// compression level as they all differ. See their `kDefaultCompressionLevel`. +fn default_rocksdb_bottommost_compression_level() -> i32 { 32767 } + // I know, it's a great name pub(crate) fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 } diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index fbeb29f3..1511e980 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -89,7 +89,7 @@ fn db_options(rocksdb_cache: &rust_rocksdb::Cache, config: &Config) -> rust_rock db_opts.set_bottommost_zstd_max_train_bytes(0, true); // -14 w_bits is only read by zlib. - db_opts.set_bottommost_compression_options(-14, config.rocksdb_compression_level, 0, 0, true); + db_opts.set_bottommost_compression_options(-14, config.rocksdb_bottommost_compression_level, 0, 0, true); } // -14 w_bits is only read by zlib. diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index bb4e0f6c..9f45539d 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -373,6 +373,8 @@ impl Service<'_> { pub fn rocksdb_compression_level(&self) -> i32 { self.config.rocksdb_compression_level } + pub fn rocksdb_bottommost_compression_level(&self) -> i32 { self.config.rocksdb_bottommost_compression_level } + pub fn prevent_media_downloads_from(&self) -> &[OwnedServerName] { &self.config.prevent_media_downloads_from } pub fn ip_range_denylist(&self) -> &[String] { &self.config.ip_range_denylist }