-
Notifications
You must be signed in to change notification settings - Fork 67
Introduce the Env::nested_read_txn from an RwTxn
#307
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
Open
Kerollmops
wants to merge
23
commits into
main
Choose a base branch
from
allow-nested-rtxn-from-wtxn
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
606f6d8
Introduce the Env::nested_read_txn from a wtxn
Kerollmops 1143451
Make nested_read_txn only available on heed not heed3
Kerollmops 09db14e
Add an example to check if LMDB leaks
Kerollmops b7f2557
Fix the rebase
Kerollmops 706ca9a
Assert the env and parent txn corresponds
Kerollmops d0865bf
Better documentation
Kerollmops 142632e
Fix the example path
Kerollmops a6cdfd9
Build and run the nested-rtxns in release
Kerollmops b65d660
Make cargo fmt happy
Kerollmops 3bd3069
Update correct submodule
Kerollmops d8b628a
Use C11 on Windows to enable atomics
Kerollmops e0ecf15
Enable atomics on Windows
Kerollmops 2a8b3f1
Bump versions to -nested-rtxns
Kerollmops 7529f9c
Expose a method to get the inner env file
Kerollmops 769057c
Bump the version to v0.22.1-nested-rtxns-2
Kerollmops 19edab4
Make it work on env opened with WRITEMAP
Kerollmops 79e097b
Begin the nested rtxns with the MDB_RDONLY flag
Kerollmops ea81ce5
Bump lmdb to a better version
Kerollmops 7a99ad4
Bump versions
Kerollmops 4f3bc2d
Use the latest patched LMDB version
Kerollmops 5f56c97
Bump versions
Kerollmops 05d4d85
Move to the latest version of our LMDB fork
Kerollmops 8a77109
Bump the version to 0.2.6-nested-rtxns-6
Kerollmops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [package] | ||
| name = "heed" | ||
| version = "0.22.0" | ||
| version = "0.22.1-nested-rtxns-6" | ||
| authors = ["Kerollmops <[email protected]>"] | ||
| description = "A fully typed LMDB (mdb.master) wrapper with minimum overhead" | ||
| license = "MIT" | ||
|
|
@@ -16,14 +16,17 @@ byteorder = { version = "1.5.0", default-features = false } | |
| heed-traits = { version = "0.20.0", path = "../heed-traits" } | ||
| heed-types = { version = "0.21.0", default-features = false, path = "../heed-types" } | ||
| libc = "0.2.175" | ||
| lmdb-master-sys = { version = "0.2.5", path = "../lmdb-master-sys" } | ||
| lmdb-master-sys = { version = "0.2.6-nested-rtxns-6", path = "../lmdb-master-sys" } | ||
| once_cell = "1.21.3" | ||
| page_size = "0.6.0" | ||
| serde = { version = "1.0.223", features = ["derive"], optional = true } | ||
| synchronoise = "1.0.1" | ||
|
|
||
| [dev-dependencies] | ||
| memchr = "2.7.5" | ||
| rand = "0.9.0" | ||
| rayon = "1.10.0" | ||
| roaring = "0.10.10" | ||
| serde = { version = "1.0.223", features = ["derive"] } | ||
| tempfile = "3.22.0" | ||
|
|
||
|
|
@@ -122,6 +125,9 @@ name = "custom-dupsort-comparator" | |
| [[example]] | ||
| name = "multi-env" | ||
|
|
||
| [[example]] | ||
| name = "nested-rtxns" | ||
|
|
||
| [[example]] | ||
| name = "nested" | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use heed::types::*; | ||
| use heed::{Database, EnvFlags, EnvOpenOptions}; | ||
| use rand::prelude::*; | ||
| use rayon::prelude::*; | ||
| use roaring::RoaringBitmap; | ||
|
|
||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| let dir = tempfile::tempdir()?; | ||
| let env = unsafe { | ||
| let mut options = EnvOpenOptions::new().read_txn_without_tls(); | ||
| #[cfg(not(windows))] | ||
| options.flags(EnvFlags::WRITE_MAP); | ||
| options | ||
| .map_size(2 * 1024 * 1024 * 1024) // 2 GiB | ||
| .open(dir.path())? | ||
| }; | ||
|
|
||
| // opening a write transaction | ||
| let mut wtxn = env.write_txn()?; | ||
| // we will open the default unnamed database | ||
| let db: Database<U32<byteorder::BigEndian>, Bytes> = env.create_database(&mut wtxn, None)?; | ||
|
|
||
| let mut buffer = Vec::new(); | ||
| for i in 0..1000 { | ||
| let mut rng = StdRng::seed_from_u64(i as u64); | ||
| let max = rng.random_range(10_000..=100_000); | ||
| let roaring = RoaringBitmap::from_sorted_iter(0..max)?; | ||
| buffer.clear(); | ||
| roaring.serialize_into(&mut buffer)?; | ||
| db.put(&mut wtxn, &i, &buffer)?; | ||
| } | ||
|
|
||
| // opening multiple read-only transactions | ||
| // to check if those values are now available | ||
| // without committing beforehand | ||
| let rtxns = (0..1000).map(|_| env.nested_read_txn(&wtxn)).collect::<heed::Result<Vec<_>>>()?; | ||
|
|
||
| rtxns.into_par_iter().enumerate().for_each(|(i, rtxn)| { | ||
| let mut rng = StdRng::seed_from_u64(i as u64); | ||
| let max = rng.random_range(10_000..=100_000); | ||
| let roaring = RoaringBitmap::from_sorted_iter(0..max).unwrap(); | ||
|
|
||
| let mut buffer = Vec::new(); | ||
| roaring.serialize_into(&mut buffer).unwrap(); | ||
|
|
||
| let i = i as u32; | ||
| let ret = db.get(&rtxn, &i).unwrap(); | ||
| assert_eq!(ret, Some(&buffer[..])); | ||
| }); | ||
|
|
||
| for i in 1000..10_000 { | ||
| let mut rng = StdRng::seed_from_u64(i as u64); | ||
| let max = rng.random_range(10_000..=100_000); | ||
| let roaring = RoaringBitmap::from_sorted_iter(0..max)?; | ||
| buffer.clear(); | ||
| roaring.serialize_into(&mut buffer)?; | ||
| db.put(&mut wtxn, &i, &buffer)?; | ||
| } | ||
|
|
||
| // opening multiple read-only transactions | ||
| // to check if those values are now available | ||
| // without committing beforehand | ||
| let rtxns = | ||
| (1000..10_000).map(|_| env.nested_read_txn(&wtxn)).collect::<heed::Result<Vec<_>>>()?; | ||
|
|
||
| rtxns.into_par_iter().enumerate().for_each(|(i, rtxn)| { | ||
| let mut rng = StdRng::seed_from_u64(i as u64); | ||
| let max = rng.random_range(10_000..=100_000); | ||
| let roaring = RoaringBitmap::from_sorted_iter(0..max).unwrap(); | ||
|
|
||
| let mut buffer = Vec::new(); | ||
| roaring.serialize_into(&mut buffer).unwrap(); | ||
|
|
||
| let i = i as u32; | ||
| let ret = db.get(&rtxn, &i).unwrap(); | ||
| assert_eq!(ret, Some(&buffer[..])); | ||
| }); | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| [package] | ||
| name = "lmdb-master-sys" | ||
| # NB: When modifying, also modify html_root_url in lib.rs | ||
| version = "0.2.5" | ||
| version = "0.2.6-nested-rtxns-6" | ||
| authors = [ | ||
| "Kerollmops <[email protected]>", | ||
| "Dan Burkert <[email protected]>", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.