initial database code (#6)
* commit to start the draft pull request.
added a space
* Please don't look to close.It might hurt your eyes
* impl associated types
* errors, docs & divided ro/rw tx
Added some more errors to DB_FAILURES, rewrited crates docs, and specified
WriteTransaction subtype which implement write mode method.
* more changes see description
changed blockchain_db folder by database. Implemented (just for test) get_block_hash, open, from to Interface.
Also rewrited a declarative macro for tables. Will have to add Dummy Tables later.
* small changes
* Organized modules & implemented get_block_hash
* write prototype & error
Added prototype functions for clear(), put() & delete() in mdbx implementation. They still don't
consider table flags. Also added a temporary DB_FAILURES::EncodingError for monero-rs consensus_encode
errors. Still have to rethink about it to resend a reference to the data that can't be encoded.
* Multiple changes
- hse.rs
Added hse.rs that will contain db implementations for HSE. Since the codebase can't welcome unsafe
code, the wrapper will be written outside of the project.
- lib.rs
Added a specific FailedToCommit error. (will investigate if really necessary).
Added DupTable trait, which is a Table with DUPSORT/DUPFIXED support and its declarative macro.
Added two other tables, blockheaders that give block's header with specified hash & blockbody that give block's body with specified hash
Added Cursor methods, that are likely to be deprecated if I found a way to implemen Iterator on top of it.
Added WriteCursor trait & methods, which is basically put & del.
Added mandatory type for Cursors in Transaction & WriteTransactions
Refactored get_block_hash interface method.
- mdbx.rs
Added partial implementation of Cursor & WriteCursor trait for libmdbx::Cursor. Only the first() & get() methods are implemented
Added implementation of get & commit for Transaction
* put mdbx as features with its dependency
* save
* refactored some method with macros
* more mdbx errors, docs correction, moved to error.rs
* finish nodup mdbx impl, errors.rs, macros, tables
Finished the initial implementation of Cursor, WriteCursor, Transaction and WriteTransaction in mdbx.rs. Corrected some macros in mdbx.rs to simplify the implementations. There is certainly rooms to more flexible macros. Also added 3 other tables. I started to divide errors into category to more easily handle them at higher-level. Due to the large number of errors i just moved them into another file. There is know DB_SERIAL enum for errors relating of decoding/encoding error & DB_FULL enum for every errors relating a component being overeaching its capacity.
* bye bye match statement in mdbx.rs
* defined all blockchain tables (not txpool)
* dupsort/fixed support, dupcursor, basic block interface
* tables, types, encoding and documentations
Redefined all the database types from @Boog900's monero-rs db branch and added the needed
implementations. The database now use bincode2 for encoding and decoding. We observe that bincode was
5 times faster at serializing than monero::consensus_encode. Since we still use monero-rs types but can't implement
foreign trait to them, the encoding module contain a compatibility layer, the time we switch from monero-rs to properly
implement it. All the tables are now defined. (can be subject to change if there is good reason for). added documentations
to modules and types.
* replaced macros and added hfversion table
* save
* multiple changes
* modified database schema. deprecated output global index and splited up pre-rct from rct output.
* Fixed DupCursor function to return subkey (thx to rust turbofish inference).
* Added some output functions
* Added two new DB_FAILURES, one to handle a prohibited None case and one for undefined case where a dev msg is needed.
* fixed TxOutputIdx, previously used global index, now is a tuple of amount/amount_index.
* i hate lifetimes
* read-only method now use read-only tx
* initial output fn
* some tx functions. Yes I'll refactor them
* moved interface in a module
* redefined errors, more tx fn, None->error
* corrected a table + started blk fns
* save
* fixed TxOutputIdx + pop_block
* IIRC I finished initial interface fns
* fixed table name const + db build/check/open fn
* switched important tables to dummy keys + rm blockhfversion
* minor docs correction
* fixed mentioned issues
* make a test bin, just for fun
* fixed issues + cargo fmt
* removed monerod part
* fixed a comment
2023-04-20 17:20:32 +00:00
|
|
|
[package]
|
Database (#35)
* rename `database` -> `old_database`
Keeping it around for reference until new implementation is complete.
* create new `database/` skeleton
* add `DATABASE.md` design doc skeleton
* move design doc to `database/README.md`
* add rough code
* `lib.rs` -> `gist.rs`
* database: use workspace deps
* workspace: include `database/` as member
CI will now include this crate.
* cargo fmt
* database: `AGPL` -> `MIT`
* readme: add `TODO`s
* add base files
* cargo.toml: add `heed` feature
* fix clippy
* lib.rs: add extremely pedantic lints
* readme: add `# Backends`
* cargo.toml: add `cfg-if`
* add `backend/` structure
* base `database.rs`
* cargo.toml: add `borsh`
* backend: add `DATABASE_BACKEND`
* base `error.rs`
* base `database.rs`
* base `transaction.rs`
* base `table.rs`
* lib.rs: add imports
* add `pod.rs`
* pod: use `Read/Write`, add tests for all primitive numbers
* pod: impl Pod for `Vec<u8>`, `[u8; N]`
* pod: add docs, add `private::Sealed`
* pod: `to_writer`, `from_reader`
The new `as_bytes` + `from_bytes` now allows (de)serializing from
bytes directly instead of going through Read/Write.
Different array return sizes are abstracted away with `-> impl AsRef<[u8]>`
* pod: impl Pod for `Box<[u8]>`
* pod: return `Err` on incorrect length in `from_bytes()`
* pod: docs
* pod: impl Pod for `Arc<[u8]>`
* readme: docs
* database: add `create_table()`, `get_table()`
* table: `Pod` bound
* backend: move into directories
* pod: add `into_bytes()`
* heed: impl `BytesEncode`, `BytesDecode`
* add `actor`, `service` features
The thread/actor system used will be gated behind `actor`,
and the `tower/tokio` integration will be gated behind `service`.
* add `lib.rs` docs
* service: add `service.rs`
* service: add `reader.rs`
* service: add `writer.rs`
* service: add `request.rs` & `response.rs`
* cargo.toml: add `crossbeam`
* service: add/use `enum Request`, `enum Response`
* service: basic signatures for thread-pools, `Writer` -> `Writers`
* service: split `tower::Service<ReadRequest/WriteRequest>`
* service: impl `tower::Service` for `Database(Reader|Writer)`
* service: add `init()`, impl basic `Reader/Writer` pools
* service: add example `Request`'s
* service: add example `ReadRequest` handling
* temporarily allow clippy lints
* readme: update file structure
* transaction: add `RoTx::get_range()`
* service: module docs
* cargo.toml: add `cuprate-helper`
* service: scale readers/writers based on thread count
* database: change lifetimes
* heed: impl Database for `heed`
* heed: add `ConcreteRoTx`, `ConcreteRwTx`, impl Tx traits
* docs
* service: `read.rs` docs
* service: `write.rs` docs
* service: request/response docs
* service: use `OnceLock` in `init()`, add `db_read()`, `db_write()`
* service: leak database into `&'static`
* database: add `#[inline]`, `#[cold]`
* service: `free.rs` docs, more `#[inline]` + `#[cold]`
* service: add `shutdown()`
* service: add `Request::Shutdown`
* service: `shutdown()` docs
* heed: hide concrete tx types
* lib.rs: add terms
* split `Env` <-> `Database`
* cargo.toml: add `paste`
* database: add `tables/`
* impl `serde/borsh` where possible
* tables: add `Tables`, add test docs
* make db backend mutually exclusive to fix `--all-features`
* tables: use `$()*` in `tables!()`
* cargo.toml: add `sanakirja 1.4.0`
* sanakirja: impl `Env`
* sanakirja: impl `Database`
* sanakirja: impl `Transaction`
* table: temporarily fix `sanakirja` K/V bounds
* table: fix `#[cfg]`
* cargo.toml: fix deps
* lib.rs: docs
* service: docs
* readme: add files, update `# Documentation`, add `# Layers`
* readme: `src/` file purpose
* readme: `src/service/` file purpose
* readme: `src/backend/` file purpose
* fix `Cargo.lock` merge conflict
* database: remove `gist.rs`
* add to `constants.rs`
* add top `//! comments` for files/modules
* constants: add sanity-check test
* service: add `only_one_database` test in `free.rs`
* service: add `tests.rs`
* remove unneeded markers + imports
* backend: fix `get_range()`'s trait `impl` return
* env: add `create_tables_if_needed()`, don't return `Option<Db>`
* sort imports by `CONTRIBUTING.md` rules
oops sorry boog
* add `monero.rs`
* monero: docs
* database: add missing `RoTx/RwTx` inputs
* backend: add missing `RoTx/RwTx` inputs
* `monero.rs` trait -> free functions in `ops/`
* pod: make methods infallible
* ci: add `rustup update` step
* service: use `Arc` instead of leaking, remove `db_read/db_write`
* service: use `InfallibleOneshotReceiver` for readers
* service: shutdown on error, add todos
* service: remove `Request`
* service: combine `ReadResponse` and `WriteResponse`
* service: use `InfallibleOneshotReceiver` for writer
* service: only spawn 1 writer, don't allow cloning writer handle
* table: add associated `const CONSTANT_SIZE`
* add `key.rs` + `trait Key`, add bound to `Table`
* fix typos
2024-02-13 17:43:25 +00:00
|
|
|
name = "cuprate-database"
|
|
|
|
version = "0.0.0"
|
|
|
|
edition = "2021"
|
|
|
|
description = "Cuprate's database abstraction"
|
|
|
|
license = "MIT"
|
|
|
|
authors = ["hinto-janai"]
|
|
|
|
repository = "https://github.com/Cuprate/cuprate/tree/main/database"
|
|
|
|
keywords = ["cuprate", "database"]
|
initial database code (#6)
* commit to start the draft pull request.
added a space
* Please don't look to close.It might hurt your eyes
* impl associated types
* errors, docs & divided ro/rw tx
Added some more errors to DB_FAILURES, rewrited crates docs, and specified
WriteTransaction subtype which implement write mode method.
* more changes see description
changed blockchain_db folder by database. Implemented (just for test) get_block_hash, open, from to Interface.
Also rewrited a declarative macro for tables. Will have to add Dummy Tables later.
* small changes
* Organized modules & implemented get_block_hash
* write prototype & error
Added prototype functions for clear(), put() & delete() in mdbx implementation. They still don't
consider table flags. Also added a temporary DB_FAILURES::EncodingError for monero-rs consensus_encode
errors. Still have to rethink about it to resend a reference to the data that can't be encoded.
* Multiple changes
- hse.rs
Added hse.rs that will contain db implementations for HSE. Since the codebase can't welcome unsafe
code, the wrapper will be written outside of the project.
- lib.rs
Added a specific FailedToCommit error. (will investigate if really necessary).
Added DupTable trait, which is a Table with DUPSORT/DUPFIXED support and its declarative macro.
Added two other tables, blockheaders that give block's header with specified hash & blockbody that give block's body with specified hash
Added Cursor methods, that are likely to be deprecated if I found a way to implemen Iterator on top of it.
Added WriteCursor trait & methods, which is basically put & del.
Added mandatory type for Cursors in Transaction & WriteTransactions
Refactored get_block_hash interface method.
- mdbx.rs
Added partial implementation of Cursor & WriteCursor trait for libmdbx::Cursor. Only the first() & get() methods are implemented
Added implementation of get & commit for Transaction
* put mdbx as features with its dependency
* save
* refactored some method with macros
* more mdbx errors, docs correction, moved to error.rs
* finish nodup mdbx impl, errors.rs, macros, tables
Finished the initial implementation of Cursor, WriteCursor, Transaction and WriteTransaction in mdbx.rs. Corrected some macros in mdbx.rs to simplify the implementations. There is certainly rooms to more flexible macros. Also added 3 other tables. I started to divide errors into category to more easily handle them at higher-level. Due to the large number of errors i just moved them into another file. There is know DB_SERIAL enum for errors relating of decoding/encoding error & DB_FULL enum for every errors relating a component being overeaching its capacity.
* bye bye match statement in mdbx.rs
* defined all blockchain tables (not txpool)
* dupsort/fixed support, dupcursor, basic block interface
* tables, types, encoding and documentations
Redefined all the database types from @Boog900's monero-rs db branch and added the needed
implementations. The database now use bincode2 for encoding and decoding. We observe that bincode was
5 times faster at serializing than monero::consensus_encode. Since we still use monero-rs types but can't implement
foreign trait to them, the encoding module contain a compatibility layer, the time we switch from monero-rs to properly
implement it. All the tables are now defined. (can be subject to change if there is good reason for). added documentations
to modules and types.
* replaced macros and added hfversion table
* save
* multiple changes
* modified database schema. deprecated output global index and splited up pre-rct from rct output.
* Fixed DupCursor function to return subkey (thx to rust turbofish inference).
* Added some output functions
* Added two new DB_FAILURES, one to handle a prohibited None case and one for undefined case where a dev msg is needed.
* fixed TxOutputIdx, previously used global index, now is a tuple of amount/amount_index.
* i hate lifetimes
* read-only method now use read-only tx
* initial output fn
* some tx functions. Yes I'll refactor them
* moved interface in a module
* redefined errors, more tx fn, None->error
* corrected a table + started blk fns
* save
* fixed TxOutputIdx + pop_block
* IIRC I finished initial interface fns
* fixed table name const + db build/check/open fn
* switched important tables to dummy keys + rm blockhfversion
* minor docs correction
* fixed mentioned issues
* make a test bin, just for fun
* fixed issues + cargo fmt
* removed monerod part
* fixed a comment
2023-04-20 17:20:32 +00:00
|
|
|
|
|
|
|
[features]
|
database: impl trait function bodies for `heed` & `redb` (#85)
* env: remove `T: Table` for `Env::create_tables()`
It creates _all_ tables, not a specific `T: Table`
* heed: half impl `Env::open()`, some TODOs
* heed: add `HeedTxR{o,w}<'env>`
* workspace/cargo: add `parking_lot`
* remove `parking_lot`
`MappedRwLockGuard` doesn't solve the `returning reference to
object owned by function` error when returning heed's lock guard
+ the tx so we'll be going with `std`
* env: add `{EnvInner,TxRoInput,TxRwInput}` and getter `fn()`s
* env: fix tx <-> table lifetimes, fix `Env::create_tables()`
* heed: impl `DatabaseRo`
* heed: impl `DatabaseRw`
* database: add `src/backend/${BACKEND}/tests.rs`
* heed: impl more of `Env::open()`
* redb: fix trait signatures, add `trait ValueGuard`
* accommodate `DatabaseRo` bounds for both `{heed,redb}`
* fold `get_range()` generic + bounds
* add `TxCreator`, add `heed` tests
* env: `TxCreator` -> `EnvInner` which doubles as DB/Table opener
* database: `DatabaseRw<'tx>` -> `DatabaseRw<'db, 'tx>`
* heed: `db_read_write()` test
* database: fix `get()` lifetimes, heed: add `db_read_write()` test
* database: remove `'env` lifetime from `DatabaseRo<'env, 'tx>`
not needed for immutable references
* redb: fix new `{Env, EnvInner, DatabaseR{o,w}}` bounds
* redb: impl `Database` traits
* redb: impl `TxR{o,w}` traits
* redb: impl `Env`
* redb: open/create tables in `Env::open`
* redb: enable tests, add tmp `Storable` printlns
* redb: fix alignment issue with `Cow` and `from_bytes_unaligned()`
* redb: only allocate bytes when alignment != 1
* heed: remove custom iterator from `range()`
* storable: conditionally allocat on misaligned bytes in `from_bytes`
* add database guard
* database: AccessGuard -> ValueGuard
* storable: add `ALIGN` and `from_bytes_unaligned()`
* redb: 1 serde type `StorableRedb`, fix impl
* cow serde, trait bounds, fix backend's where bounds
- Uses Cow for `redb`'s deserialization
- Conforms `heed` to use Cow (but not as the actual key/value)
- Conforms the `cuprate_database` trait API to use Cow
- Adds `ToOwned + Debug` (and permutation) trait bounds
- Solves 23098573148968945687345349657398 compiler errors due
to aforementioned trait bounds, causing `where` to be everywhere
* fix docs, use fully qualified Tx functions for tests
* backend: check value guard contains value in test
* add `Storable::ALIGN` tests, doc TODOs
* add `trait ToOwnedDebug`
* traits: `ToOwned + Debug` -> `ToOwnedDebug`
* heed: remove `ToOwned` + `Debug` bounds
* redb: remove `ToOwned` + `Debug` bounds
* add `ValueGuard`, replace signatures, fix `redb`
* heed: fix for `ValueGuard`
* docs, tests
* redb: add `CowRange` for `T::Key` -> `Cow<'_, T::Key>` conversion
* separate `config.rs` -> `config/`
* ci: combine tests, run both `heed` and `redb` tests
* ci: fix workflow
* backend: add `resize()` test
* ci: remove windows-specific update
* ci: remove update + windows default set
* backend: add `unreachable` tests, fix docs
* trait docs
* ci: fix
* Update database/src/backend/heed/env.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/env.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/transaction.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/transaction.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/transaction.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/redb/database.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/redb/database.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/database.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* readme: fix `value_guard.rs`
* heed: remove unneeded clippy + fix formatting
* heed: create and use `create_table()` in `Env::open()`
* redb: create and use `create_table()` in `Env::open()`
* redb: remove unneeded clippy
* fix clippy, remove `<[u8], [u8]>` docs
---------
Co-authored-by: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com>
Co-authored-by: Boog900 <boog900@tutanota.com>
2024-03-13 22:05:24 +00:00
|
|
|
default = ["heed", "redb", "service"]
|
|
|
|
# default = ["redb", "service"]
|
2024-02-29 17:40:15 +00:00
|
|
|
heed = ["dep:heed"]
|
|
|
|
redb = ["dep:redb"]
|
|
|
|
service = ["dep:crossbeam", "dep:tokio", "dep:tower"]
|
initial database code (#6)
* commit to start the draft pull request.
added a space
* Please don't look to close.It might hurt your eyes
* impl associated types
* errors, docs & divided ro/rw tx
Added some more errors to DB_FAILURES, rewrited crates docs, and specified
WriteTransaction subtype which implement write mode method.
* more changes see description
changed blockchain_db folder by database. Implemented (just for test) get_block_hash, open, from to Interface.
Also rewrited a declarative macro for tables. Will have to add Dummy Tables later.
* small changes
* Organized modules & implemented get_block_hash
* write prototype & error
Added prototype functions for clear(), put() & delete() in mdbx implementation. They still don't
consider table flags. Also added a temporary DB_FAILURES::EncodingError for monero-rs consensus_encode
errors. Still have to rethink about it to resend a reference to the data that can't be encoded.
* Multiple changes
- hse.rs
Added hse.rs that will contain db implementations for HSE. Since the codebase can't welcome unsafe
code, the wrapper will be written outside of the project.
- lib.rs
Added a specific FailedToCommit error. (will investigate if really necessary).
Added DupTable trait, which is a Table with DUPSORT/DUPFIXED support and its declarative macro.
Added two other tables, blockheaders that give block's header with specified hash & blockbody that give block's body with specified hash
Added Cursor methods, that are likely to be deprecated if I found a way to implemen Iterator on top of it.
Added WriteCursor trait & methods, which is basically put & del.
Added mandatory type for Cursors in Transaction & WriteTransactions
Refactored get_block_hash interface method.
- mdbx.rs
Added partial implementation of Cursor & WriteCursor trait for libmdbx::Cursor. Only the first() & get() methods are implemented
Added implementation of get & commit for Transaction
* put mdbx as features with its dependency
* save
* refactored some method with macros
* more mdbx errors, docs correction, moved to error.rs
* finish nodup mdbx impl, errors.rs, macros, tables
Finished the initial implementation of Cursor, WriteCursor, Transaction and WriteTransaction in mdbx.rs. Corrected some macros in mdbx.rs to simplify the implementations. There is certainly rooms to more flexible macros. Also added 3 other tables. I started to divide errors into category to more easily handle them at higher-level. Due to the large number of errors i just moved them into another file. There is know DB_SERIAL enum for errors relating of decoding/encoding error & DB_FULL enum for every errors relating a component being overeaching its capacity.
* bye bye match statement in mdbx.rs
* defined all blockchain tables (not txpool)
* dupsort/fixed support, dupcursor, basic block interface
* tables, types, encoding and documentations
Redefined all the database types from @Boog900's monero-rs db branch and added the needed
implementations. The database now use bincode2 for encoding and decoding. We observe that bincode was
5 times faster at serializing than monero::consensus_encode. Since we still use monero-rs types but can't implement
foreign trait to them, the encoding module contain a compatibility layer, the time we switch from monero-rs to properly
implement it. All the tables are now defined. (can be subject to change if there is good reason for). added documentations
to modules and types.
* replaced macros and added hfversion table
* save
* multiple changes
* modified database schema. deprecated output global index and splited up pre-rct from rct output.
* Fixed DupCursor function to return subkey (thx to rust turbofish inference).
* Added some output functions
* Added two new DB_FAILURES, one to handle a prohibited None case and one for undefined case where a dev msg is needed.
* fixed TxOutputIdx, previously used global index, now is a tuple of amount/amount_index.
* i hate lifetimes
* read-only method now use read-only tx
* initial output fn
* some tx functions. Yes I'll refactor them
* moved interface in a module
* redefined errors, more tx fn, None->error
* corrected a table + started blk fns
* save
* fixed TxOutputIdx + pop_block
* IIRC I finished initial interface fns
* fixed table name const + db build/check/open fn
* switched important tables to dummy keys + rm blockhfversion
* minor docs correction
* fixed mentioned issues
* make a test bin, just for fun
* fixed issues + cargo fmt
* removed monerod part
* fixed a comment
2023-04-20 17:20:32 +00:00
|
|
|
|
|
|
|
[dependencies]
|
2024-03-03 22:26:39 +00:00
|
|
|
bytemuck = { version = "1.14.3", features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] }
|
|
|
|
cfg-if = { workspace = true }
|
database: Resizes, Shutdown, Flushing (#68)
* error: add `NeedsResize`
accidently removed, was `MapFull` before.
We need this because we as the writer thread must
react to this error in order to resize.
The writer thread doesn't have access to `heed::Error`, but
`Runtime::Error`, so this variant must exist
* env/backend: add `MANUAL_RESIZE` and `resize()`
* heed: respect `ReadersFull`, comment errors
* free: add `resize_memory_map()`
* env: add `Env::current_map_size`
* service: add `resize_map()`
* database: make `Env` itself cheaply clonable + threadsafe
`heed::Env` already uses `Arc` internally, but `sanakirja` does
not, so abstract this at the `Env` level instead of wrapping
`ConcreteEnv` in `Arc` ourselves.
* service: `Arc<ConcreteEnv>` -> `ConcreteEnv: Clone`
* env: add `SYNCS_PER_TX`, `path()`, `shutdown()`
* database: add `src/service/state.rs`
* service: add to `state.rs`, add `DatabaseState` to readers/writer
* add `parking_lot`
Okay, turns out we need to take locks in
`database/src/service/state.rs`...
`std`'s lock fairness policies are not well defined and
depend on the OS implementation, `parking_lot` on the other hand
has a fairness policy which is important when the writer needs
the lock but readers keep pouring in, essentially never letting
the writer do stuff.
* state: use `crossbeam::atomic::AtomicCell`
We have crossbeam as a dep anyway.
* heed: `heed::Env` -> `Arc<RwLock<heed::Env>>`
* service: add reader shutdown handle, use `Select` for msgs
* service: remove `state.rs`
We don't need this, we will represent shutdowns with channel
messages and `Select`, and mutual exclusion with a `RwLock`.
* service: fix misc reader/writer stuff
* database: add `config.rs`
* service: use `ReaderThreads` when spawning readers
* service: impl `shutdown()` for readers/writer
* service: return `DatabaseReaderReceivers` on shutdown via `JoinHandle`
Solves the issue of unfortunately timed `Request`s
that come in _right_ as we are shutting down.
If we (Cuprate) drop the database channels too early the requesting
thread will probably panic as they probably use `.unwrap()`,
never expecting a channel failure.
Returning this structure containing all the channels allows the
final shutdown code to carry these channels until the very end
of the program, at which point, all threads exit - no panics.
* remove `parking_lot`
Could be used as the database mutual exclusion lock.
Needs to be tested against `std`.
* config: add `path`
* env: `path()` -> `config()`, backend: impl `Drop`
* `Arc<ConcreteEnv>`, shutdown `service` on channel disconnect
* backend: add `Config` to `ConcreteEnv`
* service: use `std::thread::Builder` for readers/writer
* config: `PathBuf` -> `Cow<'static, Path>`
* misc docs, remove `RuntimeError::ShuttingDown`
* service: init & shutdown docs
* heed: impl `Env::resize_map()`
* heed: impl `Env::current_map_size()`
* lib.rs: add example crate usage test
* heed: `RwLock` comment
* helper: add `cuprate_database_dir()`
* config: use `cuprate_database_dir()`
* lib.rs: TODO example test
* database: add `page_size`
The database memory map size must be a multiple of
the OS page size. Why doesn't `heed` re-expose this?
It calls it when checking anyway...
https://docs.rs/heed/0.20.0-alpha.9/src/heed/env.rs.html#772
* free: impl `resize_memory_map()`
* free: docs
* env: add `disk_size_bytes()`
* config: impl `From<$num>` for `ReaderThreads`
* move `fs`-related constants to `cuprate_helper::fs`
* docs
* add `resize.rs`, `ResizeAlgorithm`
* env: use `ResizeAlgorithm` in `resize_map()`
* TODO: account for LMDB reader limit
* resize: docs, add `page_size()`, impl `fixed_bytes()`
* resize: impl `percent()`
* resize: docs
* env: take `ResizeAlgorithm` by value (it impls `Copy`)
* heed: TODO for `MDB_MAP_FULL` & `MDB_MAP_RESIZED`
* config: `From<Into<usize>>` for `ReaderThreads`
Co-authored-by: Boog900 <boog900@tutanota.com>
* env: move mutual exclusion doc to backend
* free: update invariant doc
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/service/mod.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* fix `[allow(unused_imports)] // docs`
* move DB filename from `helper/` -> `database/`
* config: use `DATABASE_FILENAME`
* config: add `db_file_path()`
* lib: add non-`service` usage invariant docs
* table: seal `Table` trait, impl for all `crate::tables`
* fix docs
* fix docs pt.2
---------
Co-authored-by: Boog900 <boog900@tutanota.com>
2024-02-25 19:46:36 +00:00
|
|
|
# FIXME:
|
|
|
|
# We only need the `thread` feature if `service` is enabled.
|
|
|
|
# Figure out how to enable features of an already pulled in dependency conditionally.
|
|
|
|
cuprate-helper = { path = "../helper", features = ["fs", "thread"] }
|
database: impl trait function bodies for `heed` & `redb` (#85)
* env: remove `T: Table` for `Env::create_tables()`
It creates _all_ tables, not a specific `T: Table`
* heed: half impl `Env::open()`, some TODOs
* heed: add `HeedTxR{o,w}<'env>`
* workspace/cargo: add `parking_lot`
* remove `parking_lot`
`MappedRwLockGuard` doesn't solve the `returning reference to
object owned by function` error when returning heed's lock guard
+ the tx so we'll be going with `std`
* env: add `{EnvInner,TxRoInput,TxRwInput}` and getter `fn()`s
* env: fix tx <-> table lifetimes, fix `Env::create_tables()`
* heed: impl `DatabaseRo`
* heed: impl `DatabaseRw`
* database: add `src/backend/${BACKEND}/tests.rs`
* heed: impl more of `Env::open()`
* redb: fix trait signatures, add `trait ValueGuard`
* accommodate `DatabaseRo` bounds for both `{heed,redb}`
* fold `get_range()` generic + bounds
* add `TxCreator`, add `heed` tests
* env: `TxCreator` -> `EnvInner` which doubles as DB/Table opener
* database: `DatabaseRw<'tx>` -> `DatabaseRw<'db, 'tx>`
* heed: `db_read_write()` test
* database: fix `get()` lifetimes, heed: add `db_read_write()` test
* database: remove `'env` lifetime from `DatabaseRo<'env, 'tx>`
not needed for immutable references
* redb: fix new `{Env, EnvInner, DatabaseR{o,w}}` bounds
* redb: impl `Database` traits
* redb: impl `TxR{o,w}` traits
* redb: impl `Env`
* redb: open/create tables in `Env::open`
* redb: enable tests, add tmp `Storable` printlns
* redb: fix alignment issue with `Cow` and `from_bytes_unaligned()`
* redb: only allocate bytes when alignment != 1
* heed: remove custom iterator from `range()`
* storable: conditionally allocat on misaligned bytes in `from_bytes`
* add database guard
* database: AccessGuard -> ValueGuard
* storable: add `ALIGN` and `from_bytes_unaligned()`
* redb: 1 serde type `StorableRedb`, fix impl
* cow serde, trait bounds, fix backend's where bounds
- Uses Cow for `redb`'s deserialization
- Conforms `heed` to use Cow (but not as the actual key/value)
- Conforms the `cuprate_database` trait API to use Cow
- Adds `ToOwned + Debug` (and permutation) trait bounds
- Solves 23098573148968945687345349657398 compiler errors due
to aforementioned trait bounds, causing `where` to be everywhere
* fix docs, use fully qualified Tx functions for tests
* backend: check value guard contains value in test
* add `Storable::ALIGN` tests, doc TODOs
* add `trait ToOwnedDebug`
* traits: `ToOwned + Debug` -> `ToOwnedDebug`
* heed: remove `ToOwned` + `Debug` bounds
* redb: remove `ToOwned` + `Debug` bounds
* add `ValueGuard`, replace signatures, fix `redb`
* heed: fix for `ValueGuard`
* docs, tests
* redb: add `CowRange` for `T::Key` -> `Cow<'_, T::Key>` conversion
* separate `config.rs` -> `config/`
* ci: combine tests, run both `heed` and `redb` tests
* ci: fix workflow
* backend: add `resize()` test
* ci: remove windows-specific update
* ci: remove update + windows default set
* backend: add `unreachable` tests, fix docs
* trait docs
* ci: fix
* Update database/src/backend/heed/env.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/env.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/transaction.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/transaction.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/transaction.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/redb/database.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/redb/database.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/backend/heed/database.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* readme: fix `value_guard.rs`
* heed: remove unneeded clippy + fix formatting
* heed: create and use `create_table()` in `Env::open()`
* redb: create and use `create_table()` in `Env::open()`
* redb: remove unneeded clippy
* fix clippy, remove `<[u8], [u8]>` docs
---------
Co-authored-by: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com>
Co-authored-by: Boog900 <boog900@tutanota.com>
2024-03-13 22:05:24 +00:00
|
|
|
paste = { workspace = true }
|
|
|
|
page_size = { version = "0.6.0" } # Needed for database resizes, they must be a multiple of the OS page size.
|
|
|
|
thiserror = { workspace = true }
|
Database (#35)
* rename `database` -> `old_database`
Keeping it around for reference until new implementation is complete.
* create new `database/` skeleton
* add `DATABASE.md` design doc skeleton
* move design doc to `database/README.md`
* add rough code
* `lib.rs` -> `gist.rs`
* database: use workspace deps
* workspace: include `database/` as member
CI will now include this crate.
* cargo fmt
* database: `AGPL` -> `MIT`
* readme: add `TODO`s
* add base files
* cargo.toml: add `heed` feature
* fix clippy
* lib.rs: add extremely pedantic lints
* readme: add `# Backends`
* cargo.toml: add `cfg-if`
* add `backend/` structure
* base `database.rs`
* cargo.toml: add `borsh`
* backend: add `DATABASE_BACKEND`
* base `error.rs`
* base `database.rs`
* base `transaction.rs`
* base `table.rs`
* lib.rs: add imports
* add `pod.rs`
* pod: use `Read/Write`, add tests for all primitive numbers
* pod: impl Pod for `Vec<u8>`, `[u8; N]`
* pod: add docs, add `private::Sealed`
* pod: `to_writer`, `from_reader`
The new `as_bytes` + `from_bytes` now allows (de)serializing from
bytes directly instead of going through Read/Write.
Different array return sizes are abstracted away with `-> impl AsRef<[u8]>`
* pod: impl Pod for `Box<[u8]>`
* pod: return `Err` on incorrect length in `from_bytes()`
* pod: docs
* pod: impl Pod for `Arc<[u8]>`
* readme: docs
* database: add `create_table()`, `get_table()`
* table: `Pod` bound
* backend: move into directories
* pod: add `into_bytes()`
* heed: impl `BytesEncode`, `BytesDecode`
* add `actor`, `service` features
The thread/actor system used will be gated behind `actor`,
and the `tower/tokio` integration will be gated behind `service`.
* add `lib.rs` docs
* service: add `service.rs`
* service: add `reader.rs`
* service: add `writer.rs`
* service: add `request.rs` & `response.rs`
* cargo.toml: add `crossbeam`
* service: add/use `enum Request`, `enum Response`
* service: basic signatures for thread-pools, `Writer` -> `Writers`
* service: split `tower::Service<ReadRequest/WriteRequest>`
* service: impl `tower::Service` for `Database(Reader|Writer)`
* service: add `init()`, impl basic `Reader/Writer` pools
* service: add example `Request`'s
* service: add example `ReadRequest` handling
* temporarily allow clippy lints
* readme: update file structure
* transaction: add `RoTx::get_range()`
* service: module docs
* cargo.toml: add `cuprate-helper`
* service: scale readers/writers based on thread count
* database: change lifetimes
* heed: impl Database for `heed`
* heed: add `ConcreteRoTx`, `ConcreteRwTx`, impl Tx traits
* docs
* service: `read.rs` docs
* service: `write.rs` docs
* service: request/response docs
* service: use `OnceLock` in `init()`, add `db_read()`, `db_write()`
* service: leak database into `&'static`
* database: add `#[inline]`, `#[cold]`
* service: `free.rs` docs, more `#[inline]` + `#[cold]`
* service: add `shutdown()`
* service: add `Request::Shutdown`
* service: `shutdown()` docs
* heed: hide concrete tx types
* lib.rs: add terms
* split `Env` <-> `Database`
* cargo.toml: add `paste`
* database: add `tables/`
* impl `serde/borsh` where possible
* tables: add `Tables`, add test docs
* make db backend mutually exclusive to fix `--all-features`
* tables: use `$()*` in `tables!()`
* cargo.toml: add `sanakirja 1.4.0`
* sanakirja: impl `Env`
* sanakirja: impl `Database`
* sanakirja: impl `Transaction`
* table: temporarily fix `sanakirja` K/V bounds
* table: fix `#[cfg]`
* cargo.toml: fix deps
* lib.rs: docs
* service: docs
* readme: add files, update `# Documentation`, add `# Layers`
* readme: `src/` file purpose
* readme: `src/service/` file purpose
* readme: `src/backend/` file purpose
* fix `Cargo.lock` merge conflict
* database: remove `gist.rs`
* add to `constants.rs`
* add top `//! comments` for files/modules
* constants: add sanity-check test
* service: add `only_one_database` test in `free.rs`
* service: add `tests.rs`
* remove unneeded markers + imports
* backend: fix `get_range()`'s trait `impl` return
* env: add `create_tables_if_needed()`, don't return `Option<Db>`
* sort imports by `CONTRIBUTING.md` rules
oops sorry boog
* add `monero.rs`
* monero: docs
* database: add missing `RoTx/RwTx` inputs
* backend: add missing `RoTx/RwTx` inputs
* `monero.rs` trait -> free functions in `ops/`
* pod: make methods infallible
* ci: add `rustup update` step
* service: use `Arc` instead of leaking, remove `db_read/db_write`
* service: use `InfallibleOneshotReceiver` for readers
* service: shutdown on error, add todos
* service: remove `Request`
* service: combine `ReadResponse` and `WriteResponse`
* service: use `InfallibleOneshotReceiver` for writer
* service: only spawn 1 writer, don't allow cloning writer handle
* table: add associated `const CONSTANT_SIZE`
* add `key.rs` + `trait Key`, add bound to `Table`
* fix typos
2024-02-13 17:43:25 +00:00
|
|
|
|
|
|
|
# `service` feature.
|
2024-02-29 17:40:15 +00:00
|
|
|
crossbeam = { workspace = true, features = ["std"], optional = true }
|
|
|
|
tokio = { workspace = true, features = ["full"], optional = true }
|
|
|
|
tower = { workspace = true, features = ["full"], optional = true }
|
initial database code (#6)
* commit to start the draft pull request.
added a space
* Please don't look to close.It might hurt your eyes
* impl associated types
* errors, docs & divided ro/rw tx
Added some more errors to DB_FAILURES, rewrited crates docs, and specified
WriteTransaction subtype which implement write mode method.
* more changes see description
changed blockchain_db folder by database. Implemented (just for test) get_block_hash, open, from to Interface.
Also rewrited a declarative macro for tables. Will have to add Dummy Tables later.
* small changes
* Organized modules & implemented get_block_hash
* write prototype & error
Added prototype functions for clear(), put() & delete() in mdbx implementation. They still don't
consider table flags. Also added a temporary DB_FAILURES::EncodingError for monero-rs consensus_encode
errors. Still have to rethink about it to resend a reference to the data that can't be encoded.
* Multiple changes
- hse.rs
Added hse.rs that will contain db implementations for HSE. Since the codebase can't welcome unsafe
code, the wrapper will be written outside of the project.
- lib.rs
Added a specific FailedToCommit error. (will investigate if really necessary).
Added DupTable trait, which is a Table with DUPSORT/DUPFIXED support and its declarative macro.
Added two other tables, blockheaders that give block's header with specified hash & blockbody that give block's body with specified hash
Added Cursor methods, that are likely to be deprecated if I found a way to implemen Iterator on top of it.
Added WriteCursor trait & methods, which is basically put & del.
Added mandatory type for Cursors in Transaction & WriteTransactions
Refactored get_block_hash interface method.
- mdbx.rs
Added partial implementation of Cursor & WriteCursor trait for libmdbx::Cursor. Only the first() & get() methods are implemented
Added implementation of get & commit for Transaction
* put mdbx as features with its dependency
* save
* refactored some method with macros
* more mdbx errors, docs correction, moved to error.rs
* finish nodup mdbx impl, errors.rs, macros, tables
Finished the initial implementation of Cursor, WriteCursor, Transaction and WriteTransaction in mdbx.rs. Corrected some macros in mdbx.rs to simplify the implementations. There is certainly rooms to more flexible macros. Also added 3 other tables. I started to divide errors into category to more easily handle them at higher-level. Due to the large number of errors i just moved them into another file. There is know DB_SERIAL enum for errors relating of decoding/encoding error & DB_FULL enum for every errors relating a component being overeaching its capacity.
* bye bye match statement in mdbx.rs
* defined all blockchain tables (not txpool)
* dupsort/fixed support, dupcursor, basic block interface
* tables, types, encoding and documentations
Redefined all the database types from @Boog900's monero-rs db branch and added the needed
implementations. The database now use bincode2 for encoding and decoding. We observe that bincode was
5 times faster at serializing than monero::consensus_encode. Since we still use monero-rs types but can't implement
foreign trait to them, the encoding module contain a compatibility layer, the time we switch from monero-rs to properly
implement it. All the tables are now defined. (can be subject to change if there is good reason for). added documentations
to modules and types.
* replaced macros and added hfversion table
* save
* multiple changes
* modified database schema. deprecated output global index and splited up pre-rct from rct output.
* Fixed DupCursor function to return subkey (thx to rust turbofish inference).
* Added some output functions
* Added two new DB_FAILURES, one to handle a prohibited None case and one for undefined case where a dev msg is needed.
* fixed TxOutputIdx, previously used global index, now is a tuple of amount/amount_index.
* i hate lifetimes
* read-only method now use read-only tx
* initial output fn
* some tx functions. Yes I'll refactor them
* moved interface in a module
* redefined errors, more tx fn, None->error
* corrected a table + started blk fns
* save
* fixed TxOutputIdx + pop_block
* IIRC I finished initial interface fns
* fixed table name const + db build/check/open fn
* switched important tables to dummy keys + rm blockhfversion
* minor docs correction
* fixed mentioned issues
* make a test bin, just for fun
* fixed issues + cargo fmt
* removed monerod part
* fixed a comment
2023-04-20 17:20:32 +00:00
|
|
|
|
Database (#35)
* rename `database` -> `old_database`
Keeping it around for reference until new implementation is complete.
* create new `database/` skeleton
* add `DATABASE.md` design doc skeleton
* move design doc to `database/README.md`
* add rough code
* `lib.rs` -> `gist.rs`
* database: use workspace deps
* workspace: include `database/` as member
CI will now include this crate.
* cargo fmt
* database: `AGPL` -> `MIT`
* readme: add `TODO`s
* add base files
* cargo.toml: add `heed` feature
* fix clippy
* lib.rs: add extremely pedantic lints
* readme: add `# Backends`
* cargo.toml: add `cfg-if`
* add `backend/` structure
* base `database.rs`
* cargo.toml: add `borsh`
* backend: add `DATABASE_BACKEND`
* base `error.rs`
* base `database.rs`
* base `transaction.rs`
* base `table.rs`
* lib.rs: add imports
* add `pod.rs`
* pod: use `Read/Write`, add tests for all primitive numbers
* pod: impl Pod for `Vec<u8>`, `[u8; N]`
* pod: add docs, add `private::Sealed`
* pod: `to_writer`, `from_reader`
The new `as_bytes` + `from_bytes` now allows (de)serializing from
bytes directly instead of going through Read/Write.
Different array return sizes are abstracted away with `-> impl AsRef<[u8]>`
* pod: impl Pod for `Box<[u8]>`
* pod: return `Err` on incorrect length in `from_bytes()`
* pod: docs
* pod: impl Pod for `Arc<[u8]>`
* readme: docs
* database: add `create_table()`, `get_table()`
* table: `Pod` bound
* backend: move into directories
* pod: add `into_bytes()`
* heed: impl `BytesEncode`, `BytesDecode`
* add `actor`, `service` features
The thread/actor system used will be gated behind `actor`,
and the `tower/tokio` integration will be gated behind `service`.
* add `lib.rs` docs
* service: add `service.rs`
* service: add `reader.rs`
* service: add `writer.rs`
* service: add `request.rs` & `response.rs`
* cargo.toml: add `crossbeam`
* service: add/use `enum Request`, `enum Response`
* service: basic signatures for thread-pools, `Writer` -> `Writers`
* service: split `tower::Service<ReadRequest/WriteRequest>`
* service: impl `tower::Service` for `Database(Reader|Writer)`
* service: add `init()`, impl basic `Reader/Writer` pools
* service: add example `Request`'s
* service: add example `ReadRequest` handling
* temporarily allow clippy lints
* readme: update file structure
* transaction: add `RoTx::get_range()`
* service: module docs
* cargo.toml: add `cuprate-helper`
* service: scale readers/writers based on thread count
* database: change lifetimes
* heed: impl Database for `heed`
* heed: add `ConcreteRoTx`, `ConcreteRwTx`, impl Tx traits
* docs
* service: `read.rs` docs
* service: `write.rs` docs
* service: request/response docs
* service: use `OnceLock` in `init()`, add `db_read()`, `db_write()`
* service: leak database into `&'static`
* database: add `#[inline]`, `#[cold]`
* service: `free.rs` docs, more `#[inline]` + `#[cold]`
* service: add `shutdown()`
* service: add `Request::Shutdown`
* service: `shutdown()` docs
* heed: hide concrete tx types
* lib.rs: add terms
* split `Env` <-> `Database`
* cargo.toml: add `paste`
* database: add `tables/`
* impl `serde/borsh` where possible
* tables: add `Tables`, add test docs
* make db backend mutually exclusive to fix `--all-features`
* tables: use `$()*` in `tables!()`
* cargo.toml: add `sanakirja 1.4.0`
* sanakirja: impl `Env`
* sanakirja: impl `Database`
* sanakirja: impl `Transaction`
* table: temporarily fix `sanakirja` K/V bounds
* table: fix `#[cfg]`
* cargo.toml: fix deps
* lib.rs: docs
* service: docs
* readme: add files, update `# Documentation`, add `# Layers`
* readme: `src/` file purpose
* readme: `src/service/` file purpose
* readme: `src/backend/` file purpose
* fix `Cargo.lock` merge conflict
* database: remove `gist.rs`
* add to `constants.rs`
* add top `//! comments` for files/modules
* constants: add sanity-check test
* service: add `only_one_database` test in `free.rs`
* service: add `tests.rs`
* remove unneeded markers + imports
* backend: fix `get_range()`'s trait `impl` return
* env: add `create_tables_if_needed()`, don't return `Option<Db>`
* sort imports by `CONTRIBUTING.md` rules
oops sorry boog
* add `monero.rs`
* monero: docs
* database: add missing `RoTx/RwTx` inputs
* backend: add missing `RoTx/RwTx` inputs
* `monero.rs` trait -> free functions in `ops/`
* pod: make methods infallible
* ci: add `rustup update` step
* service: use `Arc` instead of leaking, remove `db_read/db_write`
* service: use `InfallibleOneshotReceiver` for readers
* service: shutdown on error, add todos
* service: remove `Request`
* service: combine `ReadResponse` and `WriteResponse`
* service: use `InfallibleOneshotReceiver` for writer
* service: only spawn 1 writer, don't allow cloning writer handle
* table: add associated `const CONSTANT_SIZE`
* add `key.rs` + `trait Key`, add bound to `Table`
* fix typos
2024-02-13 17:43:25 +00:00
|
|
|
# Optional features.
|
2024-03-03 22:26:39 +00:00
|
|
|
heed = { version = "0.20.0-alpha.9", optional = true }
|
2024-02-29 17:40:15 +00:00
|
|
|
redb = { version = "1.5.0", optional = true }
|
|
|
|
serde = { workspace = true, optional = true }
|
database: Resizes, Shutdown, Flushing (#68)
* error: add `NeedsResize`
accidently removed, was `MapFull` before.
We need this because we as the writer thread must
react to this error in order to resize.
The writer thread doesn't have access to `heed::Error`, but
`Runtime::Error`, so this variant must exist
* env/backend: add `MANUAL_RESIZE` and `resize()`
* heed: respect `ReadersFull`, comment errors
* free: add `resize_memory_map()`
* env: add `Env::current_map_size`
* service: add `resize_map()`
* database: make `Env` itself cheaply clonable + threadsafe
`heed::Env` already uses `Arc` internally, but `sanakirja` does
not, so abstract this at the `Env` level instead of wrapping
`ConcreteEnv` in `Arc` ourselves.
* service: `Arc<ConcreteEnv>` -> `ConcreteEnv: Clone`
* env: add `SYNCS_PER_TX`, `path()`, `shutdown()`
* database: add `src/service/state.rs`
* service: add to `state.rs`, add `DatabaseState` to readers/writer
* add `parking_lot`
Okay, turns out we need to take locks in
`database/src/service/state.rs`...
`std`'s lock fairness policies are not well defined and
depend on the OS implementation, `parking_lot` on the other hand
has a fairness policy which is important when the writer needs
the lock but readers keep pouring in, essentially never letting
the writer do stuff.
* state: use `crossbeam::atomic::AtomicCell`
We have crossbeam as a dep anyway.
* heed: `heed::Env` -> `Arc<RwLock<heed::Env>>`
* service: add reader shutdown handle, use `Select` for msgs
* service: remove `state.rs`
We don't need this, we will represent shutdowns with channel
messages and `Select`, and mutual exclusion with a `RwLock`.
* service: fix misc reader/writer stuff
* database: add `config.rs`
* service: use `ReaderThreads` when spawning readers
* service: impl `shutdown()` for readers/writer
* service: return `DatabaseReaderReceivers` on shutdown via `JoinHandle`
Solves the issue of unfortunately timed `Request`s
that come in _right_ as we are shutting down.
If we (Cuprate) drop the database channels too early the requesting
thread will probably panic as they probably use `.unwrap()`,
never expecting a channel failure.
Returning this structure containing all the channels allows the
final shutdown code to carry these channels until the very end
of the program, at which point, all threads exit - no panics.
* remove `parking_lot`
Could be used as the database mutual exclusion lock.
Needs to be tested against `std`.
* config: add `path`
* env: `path()` -> `config()`, backend: impl `Drop`
* `Arc<ConcreteEnv>`, shutdown `service` on channel disconnect
* backend: add `Config` to `ConcreteEnv`
* service: use `std::thread::Builder` for readers/writer
* config: `PathBuf` -> `Cow<'static, Path>`
* misc docs, remove `RuntimeError::ShuttingDown`
* service: init & shutdown docs
* heed: impl `Env::resize_map()`
* heed: impl `Env::current_map_size()`
* lib.rs: add example crate usage test
* heed: `RwLock` comment
* helper: add `cuprate_database_dir()`
* config: use `cuprate_database_dir()`
* lib.rs: TODO example test
* database: add `page_size`
The database memory map size must be a multiple of
the OS page size. Why doesn't `heed` re-expose this?
It calls it when checking anyway...
https://docs.rs/heed/0.20.0-alpha.9/src/heed/env.rs.html#772
* free: impl `resize_memory_map()`
* free: docs
* env: add `disk_size_bytes()`
* config: impl `From<$num>` for `ReaderThreads`
* move `fs`-related constants to `cuprate_helper::fs`
* docs
* add `resize.rs`, `ResizeAlgorithm`
* env: use `ResizeAlgorithm` in `resize_map()`
* TODO: account for LMDB reader limit
* resize: docs, add `page_size()`, impl `fixed_bytes()`
* resize: impl `percent()`
* resize: docs
* env: take `ResizeAlgorithm` by value (it impls `Copy`)
* heed: TODO for `MDB_MAP_FULL` & `MDB_MAP_RESIZED`
* config: `From<Into<usize>>` for `ReaderThreads`
Co-authored-by: Boog900 <boog900@tutanota.com>
* env: move mutual exclusion doc to backend
* free: update invariant doc
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/service/mod.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* fix `[allow(unused_imports)] // docs`
* move DB filename from `helper/` -> `database/`
* config: use `DATABASE_FILENAME`
* config: add `db_file_path()`
* lib: add non-`service` usage invariant docs
* table: seal `Table` trait, impl for all `crate::tables`
* fix docs
* fix docs pt.2
---------
Co-authored-by: Boog900 <boog900@tutanota.com>
2024-02-25 19:46:36 +00:00
|
|
|
|
|
|
|
[dev-dependencies]
|
2024-03-03 22:26:39 +00:00
|
|
|
bytemuck = { version = "1.14.3", features = ["must_cast", "derive", "min_const_generics", "extern_crate_alloc"] }
|
2024-02-26 23:40:13 +00:00
|
|
|
cuprate-helper = { path = "../helper", features = ["thread"] }
|
database: Resizes, Shutdown, Flushing (#68)
* error: add `NeedsResize`
accidently removed, was `MapFull` before.
We need this because we as the writer thread must
react to this error in order to resize.
The writer thread doesn't have access to `heed::Error`, but
`Runtime::Error`, so this variant must exist
* env/backend: add `MANUAL_RESIZE` and `resize()`
* heed: respect `ReadersFull`, comment errors
* free: add `resize_memory_map()`
* env: add `Env::current_map_size`
* service: add `resize_map()`
* database: make `Env` itself cheaply clonable + threadsafe
`heed::Env` already uses `Arc` internally, but `sanakirja` does
not, so abstract this at the `Env` level instead of wrapping
`ConcreteEnv` in `Arc` ourselves.
* service: `Arc<ConcreteEnv>` -> `ConcreteEnv: Clone`
* env: add `SYNCS_PER_TX`, `path()`, `shutdown()`
* database: add `src/service/state.rs`
* service: add to `state.rs`, add `DatabaseState` to readers/writer
* add `parking_lot`
Okay, turns out we need to take locks in
`database/src/service/state.rs`...
`std`'s lock fairness policies are not well defined and
depend on the OS implementation, `parking_lot` on the other hand
has a fairness policy which is important when the writer needs
the lock but readers keep pouring in, essentially never letting
the writer do stuff.
* state: use `crossbeam::atomic::AtomicCell`
We have crossbeam as a dep anyway.
* heed: `heed::Env` -> `Arc<RwLock<heed::Env>>`
* service: add reader shutdown handle, use `Select` for msgs
* service: remove `state.rs`
We don't need this, we will represent shutdowns with channel
messages and `Select`, and mutual exclusion with a `RwLock`.
* service: fix misc reader/writer stuff
* database: add `config.rs`
* service: use `ReaderThreads` when spawning readers
* service: impl `shutdown()` for readers/writer
* service: return `DatabaseReaderReceivers` on shutdown via `JoinHandle`
Solves the issue of unfortunately timed `Request`s
that come in _right_ as we are shutting down.
If we (Cuprate) drop the database channels too early the requesting
thread will probably panic as they probably use `.unwrap()`,
never expecting a channel failure.
Returning this structure containing all the channels allows the
final shutdown code to carry these channels until the very end
of the program, at which point, all threads exit - no panics.
* remove `parking_lot`
Could be used as the database mutual exclusion lock.
Needs to be tested against `std`.
* config: add `path`
* env: `path()` -> `config()`, backend: impl `Drop`
* `Arc<ConcreteEnv>`, shutdown `service` on channel disconnect
* backend: add `Config` to `ConcreteEnv`
* service: use `std::thread::Builder` for readers/writer
* config: `PathBuf` -> `Cow<'static, Path>`
* misc docs, remove `RuntimeError::ShuttingDown`
* service: init & shutdown docs
* heed: impl `Env::resize_map()`
* heed: impl `Env::current_map_size()`
* lib.rs: add example crate usage test
* heed: `RwLock` comment
* helper: add `cuprate_database_dir()`
* config: use `cuprate_database_dir()`
* lib.rs: TODO example test
* database: add `page_size`
The database memory map size must be a multiple of
the OS page size. Why doesn't `heed` re-expose this?
It calls it when checking anyway...
https://docs.rs/heed/0.20.0-alpha.9/src/heed/env.rs.html#772
* free: impl `resize_memory_map()`
* free: docs
* env: add `disk_size_bytes()`
* config: impl `From<$num>` for `ReaderThreads`
* move `fs`-related constants to `cuprate_helper::fs`
* docs
* add `resize.rs`, `ResizeAlgorithm`
* env: use `ResizeAlgorithm` in `resize_map()`
* TODO: account for LMDB reader limit
* resize: docs, add `page_size()`, impl `fixed_bytes()`
* resize: impl `percent()`
* resize: docs
* env: take `ResizeAlgorithm` by value (it impls `Copy`)
* heed: TODO for `MDB_MAP_FULL` & `MDB_MAP_RESIZED`
* config: `From<Into<usize>>` for `ReaderThreads`
Co-authored-by: Boog900 <boog900@tutanota.com>
* env: move mutual exclusion doc to backend
* free: update invariant doc
Co-authored-by: Boog900 <boog900@tutanota.com>
* Update database/src/service/mod.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* fix `[allow(unused_imports)] // docs`
* move DB filename from `helper/` -> `database/`
* config: use `DATABASE_FILENAME`
* config: add `db_file_path()`
* lib: add non-`service` usage invariant docs
* table: seal `Table` trait, impl for all `crate::tables`
* fix docs
* fix docs pt.2
---------
Co-authored-by: Boog900 <boog900@tutanota.com>
2024-02-25 19:46:36 +00:00
|
|
|
page_size = { version = "0.6.0" }
|
2024-03-03 22:26:39 +00:00
|
|
|
tempfile = { version = "3.10.0" }
|