mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-01-25 12:05:51 +00:00
heed: use read-txn-no-tls
for Send
read transactions
This commit is contained in:
parent
ba1d96522f
commit
6a0a17aead
3 changed files with 23 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -623,6 +623,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
"thread_local",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tower",
|
"tower",
|
||||||
|
|
|
@ -40,10 +40,14 @@ futures = { workspace = true, optional = true }
|
||||||
tokio = { workspace = true, features = ["full"], optional = true }
|
tokio = { workspace = true, features = ["full"], optional = true }
|
||||||
tokio-util = { workspace = true, features = ["full"], optional = true }
|
tokio-util = { workspace = true, features = ["full"], optional = true }
|
||||||
tower = { workspace = true, features = ["full"], optional = true }
|
tower = { workspace = true, features = ["full"], optional = true }
|
||||||
|
thread_local = { workspace = true }
|
||||||
rayon = { workspace = true, optional = true }
|
rayon = { workspace = true, optional = true }
|
||||||
|
|
||||||
# Optional features.
|
# Optional features.
|
||||||
heed = { version = "0.20.0-alpha.9", optional = true }
|
# SAFETY: Do not remove the `read-txn-no-tls` feature.
|
||||||
|
# Required for `heed`'s read transaction to be `Send`.
|
||||||
|
# See <TODO: link_to_safety_commit_line> for more info.
|
||||||
|
heed = { version = "0.20.0-alpha.9", features = ["read-txn-no-tls"], optional = true }
|
||||||
redb = { version = "2.0.0", optional = true }
|
redb = { version = "2.0.0", optional = true }
|
||||||
serde = { workspace = true, optional = true }
|
serde = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,17 @@ pub(super) struct HeedTableRw<'env, 'tx, T: Table> {
|
||||||
pub(super) tx_rw: &'tx RefCell<heed::RwTxn<'env>>,
|
pub(super) tx_rw: &'tx RefCell<heed::RwTxn<'env>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// SAFETY: `cuprate_database`'s Cargo.toml enables a feature
|
||||||
|
/// for `heed` that turns on the `MDB_NOTLS` flag for LMDB.
|
||||||
|
///
|
||||||
|
/// This makes read transactions `Send`, but only if that flag is enabled.
|
||||||
|
///
|
||||||
|
/// This is required as in `crate::service` we must put our transactions and
|
||||||
|
/// tables inside `ThreadLocal`'s to use across multiple threads.
|
||||||
|
///
|
||||||
|
/// `ThreadLocal<T>` requires that `T: Send`.
|
||||||
|
unsafe impl<T: Table> Send for HeedTableRo<'_, T> {}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Shared functions
|
//---------------------------------------------------------------------------------------------------- Shared functions
|
||||||
// FIXME: we cannot just deref `HeedTableRw -> HeedTableRo` and
|
// FIXME: we cannot just deref `HeedTableRw -> HeedTableRo` and
|
||||||
// call the functions since the database is held by value, so
|
// call the functions since the database is held by value, so
|
||||||
|
|
Loading…
Reference in a new issue