Skip to content

Commit 68a02a2

Browse files
authored
Merge pull request #302 from meilisearch/fix-notls-documentation
Fix the `MDB_NOTLS` documentation
2 parents f76bfc6 + 6f5a480 commit 68a02a2

File tree

8 files changed

+67
-64
lines changed

8 files changed

+67
-64
lines changed

Diff for: heed/src/cookbook.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,9 @@
341341
//!
342342
//! # Advanced Multithreaded Access of Entries
343343
//!
344-
//! LMDB disallow sharing cursors amongs threads. It is only possible to send
345-
//! them between threads when the heed `read-txn-no-tls` feature is enabled.
344+
//! LMDB disallows sharing cursors among threads. It is only possible to send
345+
//! them between threads when the environment has been opened with
346+
//! [`EnvOpenOptions::read_txn_without_tls`] method.
346347
//!
347348
//! Please note that this should not be utilized with an encrypted heed3 database. These
348349
//! types of databases employ an internal cycling buffer for decrypting entries, which

Diff for: heed/src/databases/database.rs

+21-14
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
378378

379379
/// Returns an iterator over all of the values of a single key.
380380
///
381-
/// You can make this iterator `Send`able between threads by
382-
/// using the `read-txn-no-tls` crate feature.
381+
/// You can make this iterator `Send`able between threads by opening
382+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
383+
/// method.
383384
///
384385
/// ```
385386
/// # use std::fs;
@@ -986,8 +987,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
986987

987988
/// Return an ordered iterator of all key-value pairs in this database.
988989
///
989-
/// You can make this iterator `Send`able between threads by
990-
/// using the `read-txn-no-tls` crate feature.
990+
/// You can make this iterator `Send`able between threads by opening
991+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
992+
/// method.
991993
///
992994
/// ```
993995
/// # use std::fs;
@@ -1087,8 +1089,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
10871089

10881090
/// Return a reverse ordered iterator of all key-value pairs in this database.
10891091
///
1090-
/// You can make this iterator `Send`able between threads by
1091-
/// using the `read-txn-no-tls` crate feature.
1092+
/// You can make this iterator `Send`able between threads by opening
1093+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
1094+
/// method.
10921095
///
10931096
/// ```
10941097
/// # use std::fs;
@@ -1192,8 +1195,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
11921195
///
11931196
/// Comparisons are made by using the comparator `C`.
11941197
///
1195-
/// You can make this iterator `Send`able between threads by
1196-
/// using the `read-txn-no-tls` crate feature.
1198+
/// You can make this iterator `Send`able between threads by opening
1199+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
1200+
/// method.
11971201
///
11981202
/// ```
11991203
/// # use std::fs;
@@ -1364,8 +1368,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
13641368
///
13651369
/// Comparisons are made by using the comparator `C`.
13661370
///
1367-
/// You can make this iterator `Send`able between threads by
1368-
/// using the `read-txn-no-tls` crate feature.
1371+
/// You can make this iterator `Send`able between threads by opening
1372+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
1373+
/// method.
13691374
///
13701375
/// ```
13711376
/// # use std::fs;
@@ -1537,8 +1542,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
15371542
///
15381543
/// Comparisons are made by using the bytes representation of the key.
15391544
///
1540-
/// You can make this iterator `Send`able between threads by
1541-
/// using the `read-txn-no-tls` crate feature.
1545+
/// You can make this iterator `Send`able between threads by opening
1546+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
1547+
/// method.
15421548
///
15431549
/// ```
15441550
/// # use std::fs;
@@ -1669,8 +1675,9 @@ impl<KC, DC, C> Database<KC, DC, C> {
16691675
///
16701676
/// Comparisons are made by using the bytes representation of the key.
16711677
///
1672-
/// You can make this iterator `Send`able between threads by
1673-
/// using the `read-txn-no-tls` crate feature.
1678+
/// You can make this iterator `Send`able between threads by opening
1679+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
1680+
/// method.
16741681
///
16751682
/// ```
16761683
/// # use std::fs;

Diff for: heed/src/databases/encrypted_database.rs

+21-14
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
319319

320320
/// Returns an iterator over all of the values of a single key.
321321
///
322-
/// You can make this iterator `Send`able between threads by
323-
/// using the `read-txn-no-tls` crate feature.
322+
/// You can make this iterator `Send`able between threads by opening
323+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
324+
/// method.
324325
///
325326
/// ```
326327
/// # use std::fs;
@@ -822,8 +823,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
822823

823824
/// Return a lexicographically ordered iterator of all key-value pairs in this database.
824825
///
825-
/// You can make this iterator `Send`able between threads by
826-
/// using the `read-txn-no-tls` crate feature.
826+
/// You can make this iterator `Send`able between threads by opening
827+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
828+
/// method.
827829
///
828830
/// ```
829831
/// # use std::fs;
@@ -920,8 +922,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
920922

921923
/// Return a reversed lexicographically ordered iterator of all key-value pairs in this database.
922924
///
923-
/// You can make this iterator `Send`able between threads by
924-
/// using the `read-txn-no-tls` crate feature.
925+
/// You can make this iterator `Send`able between threads by opening
926+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
927+
/// method.
925928
///
926929
/// ```
927930
/// # use std::fs;
@@ -1021,8 +1024,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
10211024
///
10221025
/// Comparisons are made by using the comparator `C`.
10231026
///
1024-
/// You can make this iterator `Send`able between threads by
1025-
/// using the `read-txn-no-tls` crate feature.
1027+
/// You can make this iterator `Send`able between threads by opening
1028+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
1029+
/// method.
10261030
///
10271031
/// ```
10281032
/// # use std::fs;
@@ -1143,8 +1147,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
11431147
///
11441148
/// Comparisons are made by using the comparator `C`.
11451149
///
1146-
/// You can make this iterator `Send`able between threads by
1147-
/// using the `read-txn-no-tls` crate feature.
1150+
/// You can make this iterator `Send`able between threads by opening
1151+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
1152+
/// method.
11481153
///
11491154
/// ```
11501155
/// # use std::fs;
@@ -1265,8 +1270,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
12651270
///
12661271
/// Comparisons are made by using the bytes representation of the key.
12671272
///
1268-
/// You can make this iterator `Send`able between threads by
1269-
/// using the `read-txn-no-tls` crate feature.
1273+
/// You can make this iterator `Send`able between threads by opening
1274+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
1275+
/// method.
12701276
///
12711277
/// ```
12721278
/// # use std::fs;
@@ -1389,8 +1395,9 @@ impl<KC, DC, C> EncryptedDatabase<KC, DC, C> {
13891395
///
13901396
/// Comparisons are made by using the bytes representation of the key.
13911397
///
1392-
/// You can make this iterator `Send`able between threads by
1393-
/// using the `read-txn-no-tls` crate feature.
1398+
/// You can make this iterator `Send`able between threads by opening
1399+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
1400+
/// method.
13941401
///
13951402
/// ```
13961403
/// # use std::fs;

Diff for: heed/src/envs/encrypted_env.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ impl<T> EncryptedEnv<T> {
191191

192192
/// Create a transaction with read-only access for use with the environment.
193193
///
194-
/// You can make this transaction `Send`able between threads by
195-
/// using the `read-txn-no-tls` crate feature.
194+
/// You can make this transaction `Send`able between threads by opening
195+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
196+
/// method.
197+
///
196198
/// See [`Self::static_read_txn`] if you want the txn to own the environment.
197199
///
198200
/// ## LMDB Limitations
@@ -221,8 +223,9 @@ impl<T> EncryptedEnv<T> {
221223
/// Contrary to [`Self::read_txn`], this version **owns** the environment, which
222224
/// means you won't be able to close the environment while this transaction is alive.
223225
///
224-
/// You can make this transaction `Send`able between threads by
225-
/// using the `read-txn-no-tls` crate feature.
226+
/// You can make this transaction `Send`able between threads by opening
227+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
228+
/// method.
226229
///
227230
/// ## LMDB Limitations
228231
///

Diff for: heed/src/envs/env.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ impl<T> Env<T> {
341341

342342
/// Create a transaction with read-only access for use with the environment.
343343
///
344-
/// You can make this transaction `Send`able between threads by
345-
/// using the `read-txn-no-tls` crate feature.
344+
/// You can make this transaction `Send`able between threads by opening
345+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
346+
/// method.
347+
///
346348
/// See [`Self::static_read_txn`] if you want the txn to own the environment.
347349
///
348350
/// ## LMDB Limitations
@@ -371,8 +373,9 @@ impl<T> Env<T> {
371373
/// Contrary to [`Self::read_txn`], this version **owns** the environment, which
372374
/// means you won't be able to close the environment while this transaction is alive.
373375
///
374-
/// You can make this transaction `Send`able between threads by
375-
/// using the `read-txn-no-tls` crate feature.
376+
/// You can make this transaction `Send`able between threads by opening
377+
/// the environment with the [`EnvOpenOptions::read_txn_without_tls`]
378+
/// method.
376379
///
377380
/// ## LMDB Limitations
378381
///

Diff for: heed/src/envs/env_open_options.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<T: TlsUsage> EnvOpenOptions<T> {
161161
///
162162
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
163163
/// let mut env_builder = EnvOpenOptions::new();
164-
/// unsafe { env_builder.flags(EnvFlags::NO_TLS | EnvFlags::NO_META_SYNC); }
164+
/// unsafe { env_builder.flags(EnvFlags::NO_META_SYNC); }
165165
/// let dir = tempfile::tempdir().unwrap();
166166
/// let env = unsafe { env_builder.open(dir.path())? };
167167
///
@@ -457,16 +457,11 @@ impl<T: TlsUsage> EnvOpenOptions<T> {
457457
mdb_result(ffi::mdb_env_set_maxdbs(env, dbs))?;
458458
}
459459

460-
// When the `read-txn-no-tls` feature is enabled, we must force LMDB
461-
// to avoid using the thread local storage, this way we allow users
462-
// to use references of RoTxn between threads safely.
463-
#[allow(deprecated)] // NO_TLS is inside of the crate
464-
let flags = if T::ENABLED {
465-
// TODO make this a ZST flag on the Env and on RoTxn (make them Send when we can)
466-
self.flags
467-
} else {
468-
self.flags | EnvFlags::NO_TLS
469-
};
460+
// When the `<T as TlsUsage>::ENABLED` is true, we must tell
461+
// LMDB to avoid using the thread local storage, this way we
462+
// allow users to move RoTxn between threads safely.
463+
#[allow(deprecated)] // ok because NO_TLS is inside of the crate
464+
let flags = if T::ENABLED { self.flags } else { self.flags | EnvFlags::NO_TLS };
470465

471466
let result = ffi::mdb_env_open(env, path_str.as_ptr(), flags.bits(), 0o600);
472467
match mdb_result(result) {

Diff for: heed/src/mdb/lmdb_flags.rs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ bitflags! {
2828
/// Use asynchronous msync when MDB_WRITEMAP is used.
2929
const MAP_ASYNC = ffi::MDB_MAPASYNC;
3030
/// Tie reader locktable slots to MDB_txn objects instead of to threads.
31+
// Note to self: When removing this flag from here, we must introduce an
32+
// internal-only AllEnvFlags akin to the AllDatabaseFlags bitflags.
3133
#[deprecated(since="0.22.0", note="please use `EnvOpenOptions::read_txn_with_tls` or `EnvOpenOptions::read_txn_without_tls` instead")]
3234
const NO_TLS = ffi::MDB_NOTLS;
3335
/// Don't do any locking, caller must manage their own locks.

Diff for: heed3/Cargo.toml

-15
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@ url = "2.5.4"
4545
default = ["serde", "serde-bincode", "serde-json"]
4646
serde = ["bitflags/serde", "dep:serde"]
4747

48-
# The #MDB_NOTLS flag is automatically set on Env opening,
49-
# RoTxn and RoCursors implements the Send trait. This allows the
50-
# user to move RoTxns and RoCursors between threads as read transactions
51-
# will no more use thread local storage and will tie reader locktable
52-
# slots to #MDB_txn objects instead of to threads.
53-
#
54-
# According to the LMDB documentation, when this feature is not enabled:
55-
# A thread can only use one transaction at a time, plus any child
56-
# transactions. Each transaction belongs to one thread. [...]
57-
# The #MDB_NOTLS flag changes this for read-only transactions.
58-
#
59-
# And a #MDB_BAD_RSLOT error will be thrown when multiple read
60-
# transactions exists on the same thread
61-
read-txn-no-tls = []
62-
6348
# Enable the serde en/decoders for bincode, serde_json, or rmp_serde
6449
serde-bincode = ["heed-types/serde-bincode"]
6550
serde-json = ["heed-types/serde-json"]

0 commit comments

Comments
 (0)