Skip to content

Commit 8bfa87e

Browse files
authored
Merge pull request #1128 from spacejam/tyler_0.33
Cut 0.33. Fix atomicity bug in Tree::pop_min and Tree::pop_max
2 parents 21975b8 + 9cc2d10 commit 8bfa87e

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
# Unreleased
1+
# 0.33
22

33
## Breaking Changes
44

5-
* the backtrace crate has been made optional, which cuts
6-
several seconds off compilation time, but may cause
5+
* #1125 the backtrace crate has been made optional, which
6+
cuts several seconds off compilation time, but may cause
77
breakage if you interacted with the backtrace field
88
of corruption-related errors.
99

10+
## Bug Fixes
11+
12+
* #1128 `Tree::pop_min` and `Tree::pop_max` had a bug where
13+
they were not atomic.
14+
1015
# 0.32.1
1116

1217
## New Features

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sled"
3-
version = "0.32.1"
3+
version = "0.33.0"
44
authors = ["Tyler Neely <[email protected]>"]
55
description = "a modern embedded database"
66
license = "MIT/Apache-2.0"

src/tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ impl Tree {
13151315
&first.0,
13161316
Some(&first.1),
13171317
None,
1318-
)
1318+
)?
13191319
.is_ok()
13201320
{
13211321
return Ok(Some(first));
@@ -1362,7 +1362,7 @@ impl Tree {
13621362
&first.0,
13631363
Some(&first.1),
13641364
None,
1365-
)
1365+
)?
13661366
.is_ok()
13671367
{
13681368
return Ok(Some(first));

tests/test_tree.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,41 @@ fn test_varied_compression_ratios() {
8787
let _ = std::fs::remove_dir_all("compression_db_test");
8888
}
8989

90+
#[test]
91+
#[cfg(not(miri))] // can't create threads
92+
fn concurrent_tree_pops() -> sled::Result<()> {
93+
use std::thread;
94+
95+
let db = sled::open("db")?;
96+
97+
// Insert values 0..5
98+
for x in 0u32..5 {
99+
db.insert(x.to_be_bytes(), &[])?;
100+
}
101+
102+
let mut threads = vec![];
103+
104+
// Pop 5 values using multiple threads
105+
for _ in 0..5 {
106+
let db = db.clone();
107+
threads.push(thread::spawn(move || {
108+
db.pop_min().unwrap().unwrap();
109+
}));
110+
}
111+
112+
for thread in threads.into_iter() {
113+
thread.join().unwrap();
114+
}
115+
116+
assert!(
117+
db.is_empty(),
118+
"elements left in database: {:?}",
119+
db.iter().collect::<Vec<_>>()
120+
);
121+
122+
Ok(())
123+
}
124+
90125
#[test]
91126
#[cfg(not(miri))] // can't create threads
92127
fn concurrent_tree_ops() {

0 commit comments

Comments
 (0)