Skip to content

Commit

Permalink
Rename StdMemory storage engine to Memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Aug 31, 2023
1 parent dc8904b commit 20658a6
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions config/toydb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ sync: true
storage_raft: hybrid

# SQL key-value storage engine
# - bitcask (default): uses BitCask, an append-only log-structure store.
# - stdmemory: uses the Rust standard library BTreeMap.
# - bitcask (default): an append-only log-structured store.
# - memory: an in-memory store using the Rust standard library's BTreeMap.
storage_sql: bitcask
2 changes: 1 addition & 1 deletion src/bin/toydb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn main() -> Result<()> {
"bitcask" | "" => {
Box::new(storage::kv::BitCask::new_compact(path.join("state"), cfg.compact_threshold)?)
}
"stdmemory" => Box::new(storage::kv::StdMemory::new()),
"memory" => Box::new(storage::kv::Memory::new()),
name => return Err(Error::Config(format!("Unknown SQL storage engine {}", name))),
};

Expand Down
12 changes: 6 additions & 6 deletions src/storage/kv/std_memory.rs → src/storage/kv/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ use std::collections::BTreeMap;
use std::fmt::Display;

/// In-memory key-value store using the Rust standard library B-tree implementation.
pub struct StdMemory {
pub struct Memory {
data: BTreeMap<Vec<u8>, Vec<u8>>,
}

impl StdMemory {
impl Memory {
/// Creates a new Memory key-value storage engine.
pub fn new() -> Self {
Self { data: BTreeMap::new() }
}
}

impl Display for StdMemory {
impl Display for Memory {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "stdmemory")
write!(f, "memory")
}
}

impl Store for StdMemory {
impl Store for Memory {
fn flush(&mut self) -> Result<()> {
Ok(())
}
Expand Down Expand Up @@ -50,5 +50,5 @@ impl Store for StdMemory {
mod tests {
use super::*;

super::super::tests::test_store!(StdMemory::new());
super::super::tests::test_store!(Memory::new());
}
4 changes: 2 additions & 2 deletions src/storage/kv/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mod bitcask;
pub mod encoding;
mod memory;
pub mod mvcc;
mod std_memory;
#[cfg(test)]
mod test;

pub use bitcask::BitCask;
pub use memory::Memory;
pub use mvcc::MVCC;
pub use std_memory::StdMemory;
#[cfg(test)]
pub use test::Test;

Expand Down
6 changes: 3 additions & 3 deletions src/storage/kv/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Range, Scan, StdMemory, Store};
use super::{Memory, Range, Scan, Store};
use crate::error::Result;

use std::fmt::Display;
Expand All @@ -8,13 +8,13 @@ use std::sync::{Arc, Mutex};
/// be cloned and inspected.
#[derive(Clone)]
pub struct Test {
kv: Arc<Mutex<StdMemory>>,
kv: Arc<Mutex<Memory>>,
}

impl Test {
/// Creates a new Test key-value storage engine.
pub fn new() -> Self {
Self { kv: Arc::new(Mutex::new(StdMemory::new())) }
Self { kv: Arc::new(Mutex::new(Memory::new())) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async fn status() -> Result<()> {
storage: "hybrid".into(),
storage_size: 3239,
},
mvcc: kv::mvcc::Status { txns: 1, txns_active: 0, storage: "stdmemory".into() },
mvcc: kv::mvcc::Status { txns: 1, txns_active: 0, storage: "memory".into() },
}
);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub async fn server(
id,
peers,
Box::new(storage::log::Hybrid::new(dir.path(), false)?),
Box::new(storage::kv::StdMemory::new()),
Box::new(storage::kv::Memory::new()),
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion tests/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use toydb::storage::kv;

/// Sets up a basic in-memory SQL engine with an initial dataset.
fn setup(queries: Vec<&str>) -> Result<KV> {
let engine = KV::new(kv::MVCC::new(Box::new(kv::StdMemory::new())));
let engine = KV::new(kv::MVCC::new(Box::new(kv::Memory::new())));
let mut session = engine.session()?;
session.execute("BEGIN")?;
for query in queries {
Expand Down

0 comments on commit 20658a6

Please sign in to comment.