Skip to content

Conversation

Kerollmops
Copy link
Member

@Kerollmops Kerollmops commented Jan 23, 2025

This PR is a first attempt at patching LMDB to generate multiple RoTxn from an RwTxn and, therefore, be able to read the content of an uncommitted RwTxn in parallel. You can find the LMDB patch in the dedicated fork. We can run many algorithms in Meilisearch to process the written content and generate new data structures before committing the transaction.

Warning

We found a memory leak in the underlying LMDB PR. We need to take time to investigate the matter and fix it.

This PR is open, but we also have it on crates.io under the v0.22.1-nested-rtxns version. This version is experimental and will not be maintained in this state until we merge the changes into upstream LMDB. For the time being, we will continue to maintain it in this manner.

// opening a write transaction
let mut wtxn = env.write_txn()?;

// [use the RwTxn to write into the env]

// opening multiple read-only transactions without committing beforehand
let rtxns = (0..1000).map(|_| env.nested_read_txn(&wtxn)).collect::<heed::Result<Vec<_>>>()?;

// [use the RoTxns and move them onto different threads]

This first attempt uses a broken fork of LMDB that ignores the number of nested write transactions associated with the parent one. Therefore, it lets heed create multiple nested write transactions from the parent one (dangerous). We store those write transactions in RoTxns shells to disallow writing anything with them at the compilation level.

However, while thinking about this, it is probably still possible to open databases (already existing) and commit them from multiple threads concurrently. It should be either disallowed or will, anyway, be fixed by the correct LMDB patch later.

To fix the Windows CI we will have to use the experimental stdatomic headers. Actually, no. We had to enable the /std:c11 and /experimental:c11atomics features.

Note that the CI is broken, but it works locally, so it's maybe a submodule issue (it's always a submodule issue) 🤔 It was...

To do

  • Speed up the new nested-rtxns example in the CI (build it in release)

@Kerollmops Kerollmops added the experimental Is unstable and must be tested more thoroughly label Mar 6, 2025
@Kerollmops Kerollmops force-pushed the allow-nested-rtxn-from-wtxn branch from 9a94c8a to 1d1926b Compare March 7, 2025 13:13
@Kerollmops Kerollmops force-pushed the allow-nested-rtxn-from-wtxn branch 6 times, most recently from a54defd to 05d9f22 Compare April 1, 2025 15:11
@Kerollmops Kerollmops mentioned this pull request Sep 30, 2025
3 tasks
@Kerollmops Kerollmops force-pushed the allow-nested-rtxn-from-wtxn branch from 5028766 to 9cb3ad2 Compare September 30, 2025 13:55
@Kerollmops Kerollmops force-pushed the allow-nested-rtxn-from-wtxn branch 2 times, most recently from 484b166 to 95a3907 Compare October 1, 2025 11:56
@Kerollmops Kerollmops force-pushed the allow-nested-rtxn-from-wtxn branch from a0fa0e6 to 3759cfc Compare October 8, 2025 09:27
@Kerollmops Kerollmops force-pushed the allow-nested-rtxn-from-wtxn branch from 9dfc1cd to 6eb0384 Compare October 13, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experimental Is unstable and must be tested more thoroughly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant