Skip to content

Commit

Permalink
Remove data directories before and after running benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiemh committed Sep 23, 2024
1 parent 6c1a766 commit c82873f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
10 changes: 10 additions & 0 deletions crud-bench/src/redb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub(crate) struct ReDBClientProvider {

impl ReDBClientProvider {
pub(crate) async fn setup() -> Result<Self, Error> {
// Cleanup the data directory
let _ = std::fs::remove_dir_all("redb");
// Create the store
Ok(Self {
db: Arc::new(Database::create("redb")?),
})
Expand All @@ -34,6 +37,13 @@ pub(crate) struct ReDBClient {
}

impl BenchmarkClient for ReDBClient {
async fn shutdown(&mut self) -> Result<()> {
// Cleanup the data directory
let _ = std::fs::remove_dir_all("redb");
// Ok
Ok(())
}

async fn read(&mut self, key: i32) -> Result<()> {
let key = &key.to_ne_bytes();
// Create a new transaction
Expand Down
14 changes: 5 additions & 9 deletions crud-bench/src/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use anyhow::Error;
use anyhow::Result;
use rocksdb::{
DBCompactionStyle, DBCompressionType, FlushOptions, LogLevel, OptimisticTransactionDB,
DBCompactionStyle, DBCompressionType, LogLevel, OptimisticTransactionDB,
OptimisticTransactionOptions, Options, ReadOptions, WriteOptions,
};
use std::sync::Arc;
Expand All @@ -16,6 +16,8 @@ pub(crate) struct RocksDBClientProvider {

impl RocksDBClientProvider {
pub(crate) async fn setup() -> Result<Self, Error> {
// Cleanup the data directory
let _ = std::fs::remove_dir_all("rocksdb");
// Configure custom options
let mut opts = Options::default();
// Ensure we use fdatasync
Expand Down Expand Up @@ -75,14 +77,8 @@ pub(crate) struct RocksDBClient {

impl BenchmarkClient for RocksDBClient {
async fn shutdown(&mut self) -> Result<()> {
// Flush WAL to storage
self.db.flush_wal(true)?;
// Flush data to storage
let mut opt = FlushOptions::new();
opt.set_wait(true);
self.db.flush_opt(&opt)?;
// Compact the data
self.db.compact_range::<Vec<u8>, Vec<u8>>(None, None);
// Cleanup the data directory
let _ = std::fs::remove_dir_all("rocksdb");
// Ok
Ok(())
}
Expand Down
9 changes: 9 additions & 0 deletions crud-bench/src/surrealkv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub(crate) struct SurrealKVClientProvider {

impl SurrealKVClientProvider {
pub(crate) async fn setup() -> Result<Self, Error> {
// Cleanup the data directory
let _ = std::fs::remove_dir_all("surrealkv");
// Configure custom options
let mut opts = Options::new();
// Set the directory location
Expand All @@ -40,6 +42,13 @@ pub(crate) struct SurrealKVClient {
}

impl BenchmarkClient for SurrealKVClient {
async fn shutdown(&mut self) -> Result<()> {
// Cleanup the data directory
let _ = std::fs::remove_dir_all("surrealkv");
// Ok
Ok(())
}

async fn read(&mut self, key: i32) -> Result<()> {
let key = &key.to_ne_bytes();
let txn = self.db.begin_with_mode(Mode::ReadOnly)?;
Expand Down

0 comments on commit c82873f

Please sign in to comment.