Skip to content

Commit

Permalink
Merge pull request #1128 from spacejam/tyler_0.33
Browse files Browse the repository at this point in the history
Cut 0.33. Fix atomicity bug in Tree::pop_min and Tree::pop_max
  • Loading branch information
spacejam authored Jul 15, 2020
2 parents 21975b8 + 9cc2d10 commit 8bfa87e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Unreleased
# 0.33

## Breaking Changes

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

## Bug Fixes

* #1128 `Tree::pop_min` and `Tree::pop_max` had a bug where
they were not atomic.

# 0.32.1

## New Features
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sled"
version = "0.32.1"
version = "0.33.0"
authors = ["Tyler Neely <t@jujit.su>"]
description = "a modern embedded database"
license = "MIT/Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ impl Tree {
&first.0,
Some(&first.1),
None,
)
)?
.is_ok()
{
return Ok(Some(first));
Expand Down Expand Up @@ -1362,7 +1362,7 @@ impl Tree {
&first.0,
Some(&first.1),
None,
)
)?
.is_ok()
{
return Ok(Some(first));
Expand Down
35 changes: 35 additions & 0 deletions tests/test_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,41 @@ fn test_varied_compression_ratios() {
let _ = std::fs::remove_dir_all("compression_db_test");
}

#[test]
#[cfg(not(miri))] // can't create threads
fn concurrent_tree_pops() -> sled::Result<()> {
use std::thread;

let db = sled::open("db")?;

// Insert values 0..5
for x in 0u32..5 {
db.insert(x.to_be_bytes(), &[])?;
}

let mut threads = vec![];

// Pop 5 values using multiple threads
for _ in 0..5 {
let db = db.clone();
threads.push(thread::spawn(move || {
db.pop_min().unwrap().unwrap();
}));
}

for thread in threads.into_iter() {
thread.join().unwrap();
}

assert!(
db.is_empty(),
"elements left in database: {:?}",
db.iter().collect::<Vec<_>>()
);

Ok(())
}

#[test]
#[cfg(not(miri))] // can't create threads
fn concurrent_tree_ops() {
Expand Down

0 comments on commit 8bfa87e

Please sign in to comment.