You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had following code that tries to test a compaction_filter set on a column family that should be triggered at compaction, I manually trigger it in test with compact_range / compact_range_cf but seem the filter function of customized compaction filter is not triggered which leads to the test fails. What did I do wrong?
// This is how I opened the db
pub fn create_db(path: &Path) -> StoreResult<DB> {
let compaction_filter = move |_level: u32, _key: &[u8], _value: &[u8]| {
println!("reach");
CompactionDecision::Remove
};
let mut opts = Options::default();
opts.set_compaction_filter("test", compaction_filter);
let cf_descriptors = vec![ColumnFamilyDescriptor::new("block", opts)];
// Configure db opening options
let mut db_opts = Options::default();
db_opts.create_if_missing(true);
db_opts.create_missing_column_families(true);
let db =
DB::open_cf_descriptors(&db_opts, path, cf_descriptors).map_err(StoreError::DBError)?;
Ok(db)
}
// This test fails
#[tokio::test]
async fn test_compact_filter_called() {
use tokio::time::Duration;
let db = create_db(tempfile::tempdir().unwrap().path()).unwrap();
db.put_cf(&db.cf_handle("block").unwrap(), b"a", b"1").unwrap();
db.compact_range_cf(&db.cf_handle("block").unwrap(), None::<&[u8]>, None::<&[u8]>);
db.compact_range(None::<&[u8]>, None::<&[u8]>);
tokio::time::sleep(Duration::from_secs(5)).await;
assert!(db.get_cf(&db.cf_handle("block").unwrap(), b"a").unwrap().is_none())
}
The text was updated successfully, but these errors were encountered:
kidcooky
changed the title
How to trigger compaction_filter set on a column family?
compaction_filter not triggered defined on a column family with compact_range?
Apr 4, 2024
kidcooky
changed the title
compaction_filter not triggered defined on a column family with compact_range?
compaction_filter on a column family not triggered by compact_range(None::<&[u8]>, None::<&[u8]>)?
Apr 4, 2024
kidcooky
changed the title
compaction_filter on a column family not triggered by compact_range(None::<&[u8]>, None::<&[u8]>)?
compaction_filter on a column family not triggered
Apr 4, 2024
@kidcooky, your test code isn't doing what you think it is. Here's the deal:
tempfile::tempdir().unwrap().path()
This line is pretty much the same as doing:
let path = "/tmp/bla";
std::fs::create_dir_all(path);create_db(path);
std::fs::remove_dir_all(path);
What happens here is that RocksDB sets up all its configurations and dumps them to disk. Then, tempfile drop code nukes the directory and everything in it. When it comes time to write, RocksDB tries to recreate all its settings, but it misses the compaction filter.
Writing your test as
let path = tempfile::tempdir()?;create_db(path.path());
I had following code that tries to test a
compaction_filter
set on a column family that should be triggered at compaction, I manually trigger it in test withcompact_range
/compact_range_cf
but seem the filter function of customized compaction filter is not triggered which leads to the test fails. What did I do wrong?The text was updated successfully, but these errors were encountered: