From d51b3c87073c201a7b187077145ff37db2de8def Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sun, 30 Dec 2018 16:54:07 +0100 Subject: [PATCH 1/3] Add test to verify that the file is allocated sparsly. This will fail on older versions of LMDB on Windows that doesn't have the ITS#3824 fix --- src/lib.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 3d2d406e..36aef188 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,4 +120,36 @@ mod test_utils { tx.commit().expect("tx.commit") } } + + // verify that the map file is sparsly allocated + // this used to fail on earlier versions of LMDB on Windows, before ITS#8324 + #[test] + fn verify_sparse() { + const HEIGHT_KEY: [u8; 1] = [0]; + + let dir = TempDir::new("test").unwrap(); + + { + let env = { + let mut builder = Environment::new(); + builder.set_map_size(1_000_000_000); + builder.open(dir.path()).expect("open lmdb env") + }; + let db = env.open_db(None).unwrap(); + + for height in 0..1000 { + let mut value = [0u8; 8]; + LittleEndian::write_u64(&mut value, height); + let mut tx = env.begin_rw_txn().expect("begin_rw_txn"); + tx.put(db, &HEIGHT_KEY, &value, WriteFlags::empty()) + .expect("tx.put"); + tx.commit().expect("tx.commit") + } + } + + let size = std::fs::metadata(dir.path().join("data.mdb")) + .expect("get file size") + .len(); + assert!(size < 1_000_000); + } } From bca6f3e7a9eb8fc5acac829ee53a70e71f98430c Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sun, 30 Dec 2018 16:55:56 +0100 Subject: [PATCH 2/3] Update to latest master version of LMDB (2018-09-19). This includes important improvements such as ITS#8324 which enables sparse file allocation on Windows --- lmdb-sys/lmdb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lmdb-sys/lmdb b/lmdb-sys/lmdb index 60d50020..223c5607 160000 --- a/lmdb-sys/lmdb +++ b/lmdb-sys/lmdb @@ -1 +1 @@ -Subproject commit 60d500206a108b2c64ca7e36b0113b2cd3711b98 +Subproject commit 223c56076b2961f6518fcb98cd84cc9f60bb67a5 From c5abf05a9e11ef187ef22d6941ae1c4a6a747f4b Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sun, 30 Dec 2018 17:01:11 +0100 Subject: [PATCH 3/3] Switch to use our lmdb-sys from this repo instead of creates.io version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 495a2ecd..6dd16711 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ members = [ [dependencies] bitflags = "1" libc = "0.2" -lmdb-sys = "0.8.0" +lmdb-sys = { path = "lmdb-sys" } [dev-dependencies] rand = "0.4"