Skip to content

Commit

Permalink
Switch from SpeeDB to RocksDB (#7075)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-ubskii committed May 29, 2024
1 parent 5bc66a8 commit b7e80e9
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion database/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rust_library(
"//durability",

"@crates//:itertools",
"@crates//:speedb",
"@crates//:rocksdb",
"@crates//:tracing",
],
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion database/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rust_test(
"//storage",
"//util/test:test_utils",

"@crates//:speedb",
"@crates//:rocksdb",
"@crates//:tracing",
]
)
Expand Down
4 changes: 2 additions & 2 deletions dependencies/vaticle/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def vaticle_bazel_distribution():
def vaticle_dependencies():
git_repository(
name = "vaticle_dependencies",
remote = "https://github.com/dmitrii-ubskii/vaticle-dependencies",
commit = "7c5728efafff9ac1224e6aff50b392be7e4a166c", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
remote = "https://github.com/vaticle/dependencies",
commit = "8ae7fdfb5564bf9750f5dfbcc35a139e2d990aaa", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
)

def vaticle_typeql():
Expand Down
2 changes: 1 addition & 1 deletion storage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ rust_library(
"@crates//:itertools",
"@crates//:same-file",
"@crates//:serde",
"@crates//:speedb",
"@crates//:rocksdb",
"@crates//:tracing",
]
)
Expand Down
2 changes: 1 addition & 1 deletion storage/benches/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ rust_test(
]),
deps = [
"@crates//:rand",
"@crates//:speedb",
"@crates//:rocksdb",
"@crates//:rand_core",
"@crates//:xoshiro",
"@crates//:itertools",
Expand Down
12 changes: 6 additions & 6 deletions storage/benches/bench_rocks_impl/rocks_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

use non_transactional_rocks::NonTransactionalRocks;
use speedb::{Options, WriteOptions};
use rocksdb::{Options, WriteOptions};
use storage::StorageOpenError;

use crate::{bench_rocks_impl::rocks_database::typedb_database::TypeDBDatabase, CLIArgs};
Expand All @@ -30,7 +30,7 @@ fn write_options(args: &CLIArgs) -> WriteOptions {
write_options
}

pub fn rocks<const N_DATABASES: usize>(args: &CLIArgs) -> Result<NonTransactionalRocks<N_DATABASES>, speedb::Error> {
pub fn rocks<const N_DATABASES: usize>(args: &CLIArgs) -> Result<NonTransactionalRocks<N_DATABASES>, rocksdb::Error> {
NonTransactionalRocks::<N_DATABASES>::setup(database_options(args), write_options(args))
}

Expand All @@ -41,7 +41,7 @@ pub fn create_typedb<const N_DATABASES: usize>() -> Result<TypeDBDatabase<N_DATA
mod non_transactional_rocks {
use std::iter::zip;

use speedb::{Options, WriteBatch, WriteOptions, DB};
use rocksdb::{Options, WriteBatch, WriteOptions, DB};
use test_utils::{create_tmp_dir, TempDir};

use crate::{RocksDatabase, RocksWriteBatch};
Expand All @@ -53,7 +53,7 @@ mod non_transactional_rocks {
}

impl<const N_DATABASES: usize> NonTransactionalRocks<N_DATABASES> {
pub(super) fn setup(options: Options, write_options: WriteOptions) -> Result<Self, speedb::Error> {
pub(super) fn setup(options: Options, write_options: WriteOptions) -> Result<Self, rocksdb::Error> {
let path = create_tmp_dir();
let databases = core::array::from_fn(|i| DB::open(&options, path.join(format!("db_{i}"))).unwrap());

Expand All @@ -74,12 +74,12 @@ mod non_transactional_rocks {
}

impl<'this, const N_DATABASES: usize> RocksWriteBatch for NonTransactionalWriteBatch<'this, N_DATABASES> {
type CommitError = speedb::Error;
type CommitError = rocksdb::Error;
fn put(&mut self, database_index: usize, key: [u8; crate::KEY_SIZE]) {
self.write_batches[database_index].put(key, [])
}

fn commit(self) -> Result<(), speedb::Error> {
fn commit(self) -> Result<(), rocksdb::Error> {
let write_options = &self.database.write_options;
for (db, write_batch) in zip(&self.database.databases, self.write_batches) {
db.write_opt(write_batch, write_options)?
Expand Down
10 changes: 5 additions & 5 deletions storage/keyspace/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use lending_iterator::{
LendingIterator, Peekable, Seekable,
};
use logger::result::ResultExt;
use speedb::DB;
use rocksdb::DB;

use super::{
keyspace::{Keyspace, KeyspaceError},
Expand All @@ -23,10 +23,10 @@ use crate::key_range::{KeyRange, RangeEnd};
pub struct KeyspaceRangeIterator {
iterator: Peekable<
SeekableMap<
TakeWhile<raw_iterator::DBIterator, Box<dyn FnMut(&Result<(&[u8], &[u8]), speedb::Error>) -> bool>>,
TakeWhile<raw_iterator::DBIterator, Box<dyn FnMut(&Result<(&[u8], &[u8]), rocksdb::Error>) -> bool>>,
Box<
dyn for<'a> Fn(
Result<(&'a [u8], &'a [u8]), speedb::Error>,
Result<(&'a [u8], &'a [u8]), rocksdb::Error>,
) -> Result<(&'a [u8], &'a [u8]), KeyspaceError>,
>,
fn(&[u8]) -> &[u8],
Expand Down Expand Up @@ -58,7 +58,7 @@ impl KeyspaceRangeIterator {
let keyspace_name = keyspace.name();

let range_iterator = iterator
.take_while(Box::new(move |res: &Result<(&[u8], &[u8]), speedb::Error>| match res {
.take_while(Box::new(move |res: &Result<(&[u8], &[u8]), rocksdb::Error>| match res {
Ok((key, _)) => range.within_end(&ByteArray::copy(key)),
Err(_) => true,
}) as Box<_>)
Expand All @@ -79,7 +79,7 @@ fn identity(input: &[u8]) -> &[u8] {

fn error_mapper(
keyspace_name: &'static str,
) -> Box<dyn for<'a> Fn(Result<(&'a [u8], &'a [u8]), speedb::Error>) -> Result<(&'a [u8], &'a [u8]), KeyspaceError>> {
) -> Box<dyn for<'a> Fn(Result<(&'a [u8], &'a [u8]), rocksdb::Error>) -> Result<(&'a [u8], &'a [u8]), KeyspaceError>> {
Box::new(move |res| res.map_err(|error| KeyspaceError::Iterate { name: keyspace_name, source: error }))
}

Expand Down
14 changes: 7 additions & 7 deletions storage/keyspace/keyspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
use bytes::Bytes;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use speedb::{checkpoint::Checkpoint, Options, ReadOptions, WriteBatch, WriteOptions, DB};
use rocksdb::{checkpoint::Checkpoint, Options, ReadOptions, WriteBatch, WriteOptions, DB};

use super::iterator;
use crate::{key_range::KeyRange, write_batches::WriteBatches};
Expand Down Expand Up @@ -287,7 +287,7 @@ impl fmt::Debug for Keyspace {

#[derive(Debug)]
pub enum KeyspaceOpenError {
SpeeDB { name: &'static str, source: speedb::Error },
SpeeDB { name: &'static str, source: rocksdb::Error },
Validation { source: KeyspaceValidationError },
}

Expand All @@ -309,7 +309,7 @@ impl Error for KeyspaceOpenError {
#[derive(Debug)]
pub enum KeyspaceCheckpointError {
CheckpointExists { name: &'static str, dir: PathBuf },
CreateSpeeDBCheckpoint { name: &'static str, source: speedb::Error },
CreateSpeeDBCheckpoint { name: &'static str, source: rocksdb::Error },
}

impl fmt::Display for KeyspaceCheckpointError {
Expand Down Expand Up @@ -348,10 +348,10 @@ impl Error for KeyspaceDeleteError {

#[derive(Clone, Debug)]
pub enum KeyspaceError {
Get { name: &'static str, source: speedb::Error },
Put { name: &'static str, source: speedb::Error },
BatchWrite { name: &'static str, source: speedb::Error },
Iterate { name: &'static str, source: speedb::Error },
Get { name: &'static str, source: rocksdb::Error },
Put { name: &'static str, source: rocksdb::Error },
BatchWrite { name: &'static str, source: rocksdb::Error },
Iterate { name: &'static str, source: rocksdb::Error },
}

impl fmt::Display for KeyspaceError {
Expand Down
6 changes: 3 additions & 3 deletions storage/keyspace/raw_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use std::{cmp::Ordering, mem::transmute};

use lending_iterator::{LendingIterator, Seekable};
use speedb::DBRawIterator;
use rocksdb::DBRawIterator;

type KeyValue<'a> = Result<(&'a [u8], &'a [u8]), speedb::Error>;
type KeyValue<'a> = Result<(&'a [u8], &'a [u8]), rocksdb::Error>;

/// SAFETY NOTE: `'static` here represents that the `DBIterator` owns the data.
/// The item's lifetime is in fact invalidated when `iterator` is advanced.
Expand Down Expand Up @@ -41,7 +41,7 @@ impl DBIterator {
}

impl LendingIterator for DBIterator {
type Item<'a> = Result<(&'a [u8], &'a [u8]), speedb::Error>
type Item<'a> = Result<(&'a [u8], &'a [u8]), rocksdb::Error>
where
Self: 'a;

Expand Down
2 changes: 1 addition & 1 deletion storage/write_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
sync::atomic::Ordering,
};

use speedb::WriteBatch;
use rocksdb::WriteBatch;

use super::{MVCCKey, StorageOperation};
use crate::{
Expand Down

0 comments on commit b7e80e9

Please sign in to comment.