Skip to content

Commit

Permalink
feat: Expose set_wal_compression_type (rust-rocksdb#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr authored and zaidoon committed Feb 19, 2024
1 parent 25c0f68 commit b7e49cb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/db_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,31 @@ impl Options {
}
}

/// Sets the compression algorithm that will be used for compressing WAL.
///
/// At present, only ZSTD compression is supported!
///
/// Default: `DBCompressionType::None`
///
/// # Examples
///
/// ```
/// use speedb::{Options, DBCompressionType};
///
/// let mut opts = Options::default();
/// opts.set_wal_compression_type(DBCompressionType::Zstd);
/// // Or None to disable it
/// opts.set_wal_compression_type(DBCompressionType::None);
/// ```
pub fn set_wal_compression_type(&mut self, t: DBCompressionType) {
match t {
DBCompressionType::None | DBCompressionType::Zstd => unsafe {
ffi::rocksdb_options_set_wal_compression(self.inner, t as c_int);
},
other => unimplemented!("{:?} is not supported for WAL compression", other),
}
}

/// Sets the bottom-most compression algorithm that will be used for
/// compressing blocks at the bottom-most level.
///
Expand Down
22 changes: 22 additions & 0 deletions tests/test_rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,28 @@ fn set_compression_options_zstd_max_train_bytes() {
}
}

#[test]
fn set_wal_compression_zstd() {
let path = DBPath::new("_set_wal_compression_zstd");
{
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_wal_compression_type(DBCompressionType::None);
opts.set_wal_compression_type(DBCompressionType::Zstd);
let _db = DB::open(&opts, &path).unwrap();
}
}

#[test]
#[should_panic(expected = "Lz4 is not supported for WAL compression")]
fn set_wal_compression_unsupported() {
{
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_wal_compression_type(DBCompressionType::Lz4);
}
}

fn test_compression_type(ty: DBCompressionType) {
let path = DBPath::new("_test_compression_type");

Expand Down

0 comments on commit b7e49cb

Please sign in to comment.