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

Unable to create database when MDB_WRITEMAP is set #95

Closed
akhilles opened this issue Jan 22, 2021 · 5 comments · Fixed by #128
Closed

Unable to create database when MDB_WRITEMAP is set #95

akhilles opened this issue Jan 22, 2021 · 5 comments · Fixed by #128
Milestone

Comments

@akhilles
Copy link

To reproduce:

let path = Path::new("target").join("test.mdb");
fs::create_dir_all(&path)?;
let mut env_builder = EnvOpenOptions::new();
unsafe {
    env_builder.flag(Flags::MdbNoSync);
    env_builder.flag(Flags::MdbWriteMap);
}
let env = env_builder.map_size(10 * 1024 * 1024 * 1024).max_dbs(1000).open(path)?;
let db: Database<ByteSlice, Unit> = env.create_database(Some("test"))?;

fails with:

Error: Mdb(BadTxn)

Works fine if env_builder.flag(Flags::MdbWriteMap); is commented out.

@Kerollmops
Copy link
Member

Hey, I am not sure why as I only call the LMDB methods under the hood.

@akhilles
Copy link
Author

Hey, I am not sure why as I only call the LMDB methods under the hood.

Will try to reproduce using only the C library.

@akhilles
Copy link
Author

Wasn't able to reproduce using the C library. I think the issue is with nested write transactions. The following patch fixes the issue:

diff --git a/heed/src/env.rs b/heed/src/env.rs
index a8305c5..d126cc9 100644
--- a/heed/src/env.rs
+++ b/heed/src/env.rs
@@ -318,23 +318,20 @@ impl Env {
         KC: 'static,
         DC: 'static,
     {
-        let mut parent_wtxn = self.write_txn()?;
-        let db = self.create_database_with_txn(name, &mut parent_wtxn)?;
-        parent_wtxn.commit()?;
+        let db = self.create_database_with_txn(name)?;
         Ok(db)
     }
 
     pub fn create_database_with_txn<KC, DC>(
         &self,
         name: Option<&str>,
-        parent_wtxn: &mut RwTxn,
     ) -> Result<Database<KC, DC>>
     where
         KC: 'static,
         DC: 'static,
     {
         let types = (TypeId::of::<KC>(), TypeId::of::<DC>());
-        self.raw_create_database(name, types, parent_wtxn)
+        self.raw_create_database(name, types)
             .map(|db| Database::new(self.env_mut_ptr() as _, db))
     }
 
@@ -342,9 +339,8 @@ impl Env {
         &self,
         name: Option<&str>,
         types: (TypeId, TypeId),
-        parent_wtxn: &mut RwTxn,
     ) -> Result<u32> {
-        let wtxn = self.nested_write_txn(parent_wtxn)?;
+        let wtxn = self.write_txn()?;
 
         let mut dbi = 0;
         let name = name.map(|n| CString::new(n).unwrap());

@Kerollmops
Copy link
Member

Kerollmops commented Jul 30, 2021

@timokoesters that's indeed a duplicate of the the issue you opened recently but I have no plan to fix it.

Maybe you could submit a PR, it you do please make sur to start from the right branch (v0.12). It depends on the version you were using you could also start from v0.11.

@Kerollmops
Copy link
Member

Closed by #128.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants