Skip to content

Commit

Permalink
Merge pull request #241 from meilisearch/read-txn-no-tls-cursor
Browse files Browse the repository at this point in the history
Make the iterators `Send` when `read-txn-no-tls` is enabled
  • Loading branch information
Kerollmops authored Feb 16, 2024
2 parents 7eb3340 + 4fa64b5 commit 2c6c857
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
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

0 comments on commit 2c6c857

Please sign in to comment.