Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the iterators Send when read-txn-no-tls is enabled #241

Merged
merged 2 commits into from
Feb 16, 2024
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: 5 additions & 5 deletions heed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ url = "2.3.1"
default = ["serde", "serde-bincode", "serde-json"]
serde = ["bitflags/serde", "dep:serde"]

# The #MDB_NOTLS flag is automatically set on Env opening and
# RoTxn implements the Send trait. This allows the user to move
# a RoTxn between threads as read transactions will no more use
# thread local storage and will tie reader locktable slots to
# #MDB_txn objects instead of to threads.
# The #MDB_NOTLS flag is automatically set on Env opening,
# RoTxn and RoCursors implements the Send trait. This allows the
# user to move RoTxns and RoCursors between threads as read transactions
# will no more use thread local storage and will tie reader locktable
# slots to #MDB_txn objects instead of to threads.
#
# According to the LMDB documentation, when this feature is not enabled:
# A thread can only use one transaction at a time, plus any child
Expand Down
21 changes: 21 additions & 0 deletions heed/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ impl<KC, DC, C> Database<KC, DC, C> {

/// Returns an iterator over all of the values of a single key.
///
/// You can make this iterator `Send`able between threads by
/// using the `read-txn-no-tls` crate feature.
///
/// ```
/// # use std::fs;
/// # use std::path::Path;
Expand Down Expand Up @@ -960,6 +963,9 @@ impl<KC, DC, C> Database<KC, DC, C> {

/// Return a lexicographically ordered iterator of all key-value pairs in this database.
///
/// You can make this iterator `Send`able between threads by
/// using the `read-txn-no-tls` crate feature.
///
/// ```
/// # use std::fs;
/// # use std::path::Path;
Expand Down Expand Up @@ -1056,6 +1062,9 @@ impl<KC, DC, C> Database<KC, DC, C> {

/// Return a reversed lexicographically ordered iterator of all key-value pairs in this database.
///
/// You can make this iterator `Send`able between threads by
/// using the `read-txn-no-tls` crate feature.
///
/// ```
/// # use std::fs;
/// # use std::path::Path;
Expand Down Expand Up @@ -1156,6 +1165,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
///
/// Comparisons are made by using the bytes representation of the key.
///
/// You can make this iterator `Send`able between threads by
/// using the `read-txn-no-tls` crate feature.
///
/// ```
/// # use std::fs;
/// # use std::path::Path;
Expand Down Expand Up @@ -1325,6 +1337,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
///
/// Comparisons are made by using the bytes representation of the key.
///
/// You can make this iterator `Send`able between threads by
/// using the `read-txn-no-tls` crate feature.
///
/// ```
/// # use std::fs;
/// # use std::path::Path;
Expand Down Expand Up @@ -1494,6 +1509,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
///
/// Comparisons are made by using the bytes representation of the key.
///
/// You can make this iterator `Send`able between threads by
/// using the `read-txn-no-tls` crate feature.
///
/// ```
/// # use std::fs;
/// # use std::path::Path;
Expand Down Expand Up @@ -1621,6 +1639,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
///
/// Comparisons are made by using the bytes representation of the key.
///
/// You can make this iterator `Send`able between threads by
/// using the `read-txn-no-tls` crate feature.
///
/// ```
/// # use std::fs;
/// # use std::path::Path;
Expand Down
3 changes: 3 additions & 0 deletions heed/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ impl Env {

/// Create a transaction with read-only access for use with the environment.
///
/// You can make this transaction `Send`able between threads by
/// using the `read-txn-no-tls` crate feature.
///
/// ## LMDB Limitations
///
/// It's possible to have multiple read transactions in the same environment
Expand Down
6 changes: 6 additions & 0 deletions heed/src/iterator/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ impl<KC, DC, IM> fmt::Debug for RoIter<'_, KC, DC, IM> {
}
}

#[cfg(feature = "read-txn-no-tls")]
unsafe impl<KC, DC, IM> Send for RoIter<'_, KC, DC, IM> {}

/// A read-write iterator structure.
pub struct RwIter<'txn, KC, DC, IM = MoveThroughDuplicateValues> {
cursor: RwCursor<'txn>,
Expand Down Expand Up @@ -552,6 +555,9 @@ impl<KC, DC, IM> fmt::Debug for RoRevIter<'_, KC, DC, IM> {
}
}

#[cfg(feature = "read-txn-no-tls")]
unsafe impl<KC, DC, IM> Send for RoRevIter<'_, KC, DC, IM> {}

/// A reverse read-write iterator structure.
pub struct RwRevIter<'txn, KC, DC, IM = MoveThroughDuplicateValues> {
cursor: RwCursor<'txn>,
Expand Down
6 changes: 6 additions & 0 deletions heed/src/iterator/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ impl<KC, DC, C, IM> fmt::Debug for RoPrefix<'_, KC, DC, C, IM> {
}
}

#[cfg(feature = "read-txn-no-tls")]
unsafe impl<KC, DC, IM> Send for RoPrefix<'_, KC, DC, IM> {}

/// A read-write prefix iterator structure.
pub struct RwPrefix<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> {
cursor: RwCursor<'txn>,
Expand Down Expand Up @@ -587,6 +590,9 @@ impl<KC, DC, C, IM> fmt::Debug for RoRevPrefix<'_, KC, DC, C, IM> {
}
}

#[cfg(feature = "read-txn-no-tls")]
unsafe impl<KC, DC, IM> Send for RoRevPrefix<'_, KC, DC, IM> {}

/// A reverse read-write prefix iterator structure.
pub struct RwRevPrefix<'txn, KC, DC, C = DefaultComparator, IM = MoveThroughDuplicateValues> {
cursor: RwCursor<'txn>,
Expand Down
6 changes: 6 additions & 0 deletions heed/src/iterator/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ impl<KC, DC, IM> fmt::Debug for RoRange<'_, KC, DC, IM> {
}
}

#[cfg(feature = "read-txn-no-tls")]
unsafe impl<KC, DC, IM> Send for RoRange<'_, KC, DC, IM> {}

/// A read-write range iterator structure.
pub struct RwRange<'txn, KC, DC, IM = MoveThroughDuplicateValues> {
cursor: RwCursor<'txn>,
Expand Down Expand Up @@ -632,6 +635,9 @@ impl<KC, DC, IM> fmt::Debug for RoRevRange<'_, KC, DC, IM> {
}
}

#[cfg(feature = "read-txn-no-tls")]
unsafe impl<KC, DC, IM> Send for RoRevRange<'_, KC, DC, IM> {}

/// A reverse read-write range iterator structure.
pub struct RwRevRange<'txn, KC, DC, IM = MoveThroughDuplicateValues> {
cursor: RwCursor<'txn>,
Expand Down
Loading