Skip to content

Commit

Permalink
use explicit manual wal flushes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jevolk committed Mar 19, 2024
1 parent 9fd3eb0 commit 1bc68ab
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/database/abstraction/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fn db_options(
db_opts.set_max_subcompactions(threads.try_into().unwrap());

// IO
db_opts.set_manual_wal_flush(false);
db_opts.set_use_direct_reads(true);
db_opts.set_row_cache(row_cache);
db_opts.set_use_direct_io_for_flush_and_compaction(true);
Expand Down Expand Up @@ -308,6 +309,7 @@ impl KvTree for RocksDbEngineTree<'_> {
let lock = self.write_lock.read().unwrap();

self.db.rocks.put_cf_opt(&self.cf(), key, value, &writeoptions)?;
self.db.flush()?;

drop(lock);

Expand All @@ -325,13 +327,19 @@ impl KvTree for RocksDbEngineTree<'_> {
batch.put_cf(&self.cf(), key, value);
}

Ok(self.db.rocks.write_opt(batch, &writeoptions)?)
self.db.rocks.write_opt(batch, &writeoptions)?;
self.db.flush()?;

Ok(())
}

fn remove(&self, key: &[u8]) -> Result<()> {
let writeoptions = rust_rocksdb::WriteOptions::default();

Ok(self.db.rocks.delete_cf_opt(&self.cf(), key, &writeoptions)?)
self.db.rocks.delete_cf_opt(&self.cf(), key, &writeoptions)?;
self.db.flush()?;

Ok(())
}

fn remove_batch(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()> {
Expand All @@ -343,7 +351,10 @@ impl KvTree for RocksDbEngineTree<'_> {
batch.delete_cf(&self.cf(), key);
}

Ok(self.db.rocks.write_opt(batch, &writeoptions)?)
self.db.rocks.write_opt(batch, &writeoptions)?;
self.db.flush()?;

Ok(())
}

fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a> {
Expand Down Expand Up @@ -393,6 +404,7 @@ impl KvTree for RocksDbEngineTree<'_> {
let old = self.db.rocks.get_cf_opt(&self.cf(), key, &readoptions)?;
let new = utils::increment(old.as_deref()).unwrap();
self.db.rocks.put_cf_opt(&self.cf(), key, &new, &writeoptions)?;
self.db.flush()?;

drop(lock);
Ok(new)
Expand All @@ -414,6 +426,7 @@ impl KvTree for RocksDbEngineTree<'_> {
}

self.db.rocks.write_opt(batch, &writeoptions)?;
self.db.flush()?;

drop(lock);

Expand Down

0 comments on commit 1bc68ab

Please sign in to comment.