From 76d54640475018c1d938ac48ad9eb9d9d72e06c1 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Thu, 23 Jul 2020 11:21:27 +0200 Subject: [PATCH 1/3] Use a btreemap for tracking unstable batches --- src/pagecache/iobuf.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pagecache/iobuf.rs b/src/pagecache/iobuf.rs index ff51884fc..46af0597f 100644 --- a/src/pagecache/iobuf.rs +++ b/src/pagecache/iobuf.rs @@ -192,14 +192,18 @@ impl IoBuf { ) -> std::result::Result { debug_delay(); let res = self.header.compare_and_swap(old, new, SeqCst); - if res == old { Ok(new) } else { Err(res) } + if res == old { + Ok(new) + } else { + Err(res) + } } } #[derive(Debug)] pub(crate) struct StabilityIntervals { fsynced_ranges: Vec<(Lsn, Lsn)>, - batches: Vec<(Lsn, Lsn)>, + batches: BTreeMap, stable_lsn: Lsn, } @@ -208,15 +212,13 @@ impl StabilityIntervals { StabilityIntervals { stable_lsn: lsn, fsynced_ranges: vec![], - batches: vec![], + batches: BTreeMap::default(), } } pub(crate) fn mark_batch(&mut self, interval: (Lsn, Lsn)) { assert!(interval.0 > self.stable_lsn); - self.batches.push(interval); - // reverse sort - self.batches.sort_unstable_by(|a, b| b.cmp(a)); + self.batches.insert(interval.0, interval.1); } fn mark_fsync(&mut self, interval: (Lsn, Lsn)) -> Option { @@ -274,7 +276,9 @@ impl StabilityIntervals { // batch has been stabilized before any parts // of the batch are allowed to be reused // due to having marked them as stable. - while let Some(&(low, high)) = self.batches.last() { + while let Some((low, high)) = + self.batches.iter().map(|(l, h)| (*l, *h)).next() + { assert!( low < high, "expected batch low mark {} to be below high mark {}", @@ -290,7 +294,7 @@ impl StabilityIntervals { assert!(bsl < high); } batch_stable_lsn = Some(high); - self.batches.pop().unwrap(); + self.batches.remove(&low).unwrap(); } else { if low <= self.stable_lsn { // the batch has not been fully written From 8bfacb023ba33e7015891532e1998220b64e4d05 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Thu, 23 Jul 2020 11:24:54 +0200 Subject: [PATCH 2/3] Don't create a non-temporary db directory for testing tree pops --- tests/test_tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tree.rs b/tests/test_tree.rs index 4afe791ec..64380bef6 100644 --- a/tests/test_tree.rs +++ b/tests/test_tree.rs @@ -92,7 +92,7 @@ fn test_varied_compression_ratios() { fn concurrent_tree_pops() -> sled::Result<()> { use std::thread; - let db = sled::open("db")?; + let db = sled::Config::new().temporary(true).open()?; // Insert values 0..5 for x in 0u32..5 { From dbb5cb3dddc73110198394a82be13ab98f7f76e4 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Wed, 29 Jul 2020 11:01:27 +0200 Subject: [PATCH 3/3] Cut 0.34.2 --- CHANGELOG.md | 8 ++++++++ Cargo.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32bc31485..5b00e44b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.34.2 + +## Improvements + +* #1133 transactions and writebatch performance has been + significantly improved by removing a bottleneck in + the atomic batch stability tracking code. + # 0.34.1 ## New Features diff --git a/Cargo.toml b/Cargo.toml index 53685a73e..67470f1f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sled" -version = "0.34.1" +version = "0.34.2" authors = ["Tyler Neely "] description = "a modern embedded database" license = "MIT/Apache-2.0"