Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/database"
keywords = ["cuprate", "database"]

[features]
default = ["heed", "redb", "service"]
# default = ["heed", "redb", "service"]
# default = ["redb", "service"]
heed = ["dep:heed"]
redb = ["dep:redb"]
service = ["dep:crossbeam", "dep:futures", "dep:tokio", "dep:tokio-util", "dep:tower", "dep:rayon"]
default = ["redb-memory", "service"]
heed = ["dep:heed"]
redb = ["dep:redb"]
redb-memory = ["redb"]
service = ["dep:crossbeam", "dep:futures", "dep:tokio", "dep:tokio-util", "dep:tower", "dep:rayon"]

[dependencies]
bytemuck = { version = "1.14.3", features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] }
Expand Down
6 changes: 6 additions & 0 deletions database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Cuprate's database implementation.
1. [Backends](#backends)
- [`heed`](#heed)
- [`redb`](#redb)
- [`redb-memory`](#redb-memory)
- [`sanakirja`](#sanakirja)
- [`MDBX`](#mdbx)
1. [Layers](#layers)
Expand Down Expand Up @@ -165,6 +166,11 @@ The upstream versions from [`crates.io`](https://crates.io/crates/redb) are used

TODO: document DB on remote filesystem (does redb allow this?)

## `redb-memory`
This backend is 100% the same as `redb`, although, it uses `redb::backend::InMemoryBackend` which is a key-value store that completely resides in memory instead of a file.

All other details about this should be the same as the normal `redb` backend.

## `sanakirja`
[`sanakirja`](https://docs.rs/sanakirja) was a candidate as a backend, however there were problems with maximum value sizes.

Expand Down
26 changes: 16 additions & 10 deletions database/src/backend/redb/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,22 @@ impl Env for ConcreteEnv {
// TODO: we can set cache sizes with:
// env_builder.set_cache(bytes);

// Create the database directory if it doesn't exist.
std::fs::create_dir_all(config.db_directory())?;

// Open the database file, create if needed.
let db_file = std::fs::OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(config.db_file())?;
let mut env = env_builder.create_file(db_file)?;
// Use the in-memory backend if the feature is enabled.
let mut env = if cfg!(feature = "redb-memory") {
env_builder.create_with_backend(redb::backends::InMemoryBackend::new())?
} else {
// Create the database directory if it doesn't exist.
std::fs::create_dir_all(config.db_directory())?;

// Open the database file, create if needed.
let db_file = std::fs::OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(config.db_file())?;

env_builder.create_file(db_file)?
};

// Create all database tables.
// `redb` creates tables if they don't exist.
Expand Down