mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-22 19:49:28 +00:00
database: add redb-memory
backend (#97)
* add `redb-memory` feature * redb: use `redb::backend::InMemoryBackend` if enabled * readme: add `redb-memory` section * ci: add `redb-memory` testing * ci: remove `redb-memory` testing probably not worth adding time to CI for this
This commit is contained in:
parent
d503548716
commit
ae0d9ff36a
3 changed files with 27 additions and 13 deletions
|
@ -9,10 +9,12 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/database"
|
|||
keywords = ["cuprate", "database"]
|
||||
|
||||
[features]
|
||||
default = ["heed", "redb", "service"]
|
||||
# default = ["heed", "redb", "service"]
|
||||
# default = ["redb", "service"]
|
||||
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]
|
||||
|
|
|
@ -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)
|
||||
|
@ -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.
|
||||
|
||||
|
|
|
@ -72,6 +72,10 @@ impl Env for ConcreteEnv {
|
|||
// TODO: we can set cache sizes with:
|
||||
// env_builder.set_cache(bytes);
|
||||
|
||||
// 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())?;
|
||||
|
||||
|
@ -81,7 +85,9 @@ impl Env for ConcreteEnv {
|
|||
.write(true)
|
||||
.create(true)
|
||||
.open(config.db_file())?;
|
||||
let mut env = env_builder.create_file(db_file)?;
|
||||
|
||||
env_builder.create_file(db_file)?
|
||||
};
|
||||
|
||||
// Create all database tables.
|
||||
// `redb` creates tables if they don't exist.
|
||||
|
|
Loading…
Reference in a new issue