Skip to content

Commit

Permalink
Merge pull request #1149 from spacejam/0.34.3
Browse files Browse the repository at this point in the history
Cut 0.34.3
  • Loading branch information
spacejam committed Aug 22, 2020
2 parents c8578a0 + 741014f commit e048de8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.34.3

## New Features

* #1146 added TransactionalTree::generate_id

# 0.34.2

## Improvements
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.34.2"
version = "0.34.3"
authors = ["Tyler Neely <t@jujit.su>"]
description = "a modern embedded database"
license = "MIT/Apache-2.0"
Expand Down
42 changes: 30 additions & 12 deletions tests/test_crash_recovery.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod common;

use std::convert::TryFrom;
use std::env::{self, VarError};
use std::mem::size_of;
use std::process::{exit, Child, Command, ExitStatus};
Expand Down Expand Up @@ -552,6 +553,7 @@ fn run_tx() {

db.insert(b"k1", b"cats").unwrap();
db.insert(b"k2", b"dogs").unwrap();
db.insert(b"id", &0_u64.to_le_bytes()).unwrap();

let mut threads = vec![];

Expand All @@ -570,6 +572,9 @@ fn run_tx() {
let v1 = db.remove(b"k1").unwrap().unwrap();
let v2 = db.remove(b"k2").unwrap().unwrap();

db.insert(b"id", &db.generate_id().unwrap().to_le_bytes())
.unwrap();

db.insert(b"k1", v2).unwrap();
db.insert(b"k2", v1).unwrap();
Ok(())
Expand All @@ -585,19 +590,32 @@ fn run_tx() {
let barrier = barrier.clone();
let thread = std::thread::spawn(move || {
barrier.wait();
let mut last_id = 0;
loop {
db.transaction::<_, _, ()>(|db| {
let v1 = db.get(b"k1").unwrap().unwrap();
let v2 = db.get(b"k2").unwrap().unwrap();

let mut results = vec![v1, v2];
results.sort();

assert_eq!([&results[0], &results[1]], [b"cats", b"dogs"]);

Ok(())
})
.unwrap();
let read_id = db
.transaction::<_, _, ()>(|db| {
let v1 = db.get(b"k1").unwrap().unwrap();
let v2 = db.get(b"k2").unwrap().unwrap();
let id = u64::from_le_bytes(
TryFrom::try_from(
&*db.get(b"id").unwrap().unwrap(),
)
.unwrap(),
);

let mut results = vec![v1, v2];
results.sort();

assert_eq!(
[&results[0], &results[1]],
[b"cats", b"dogs"]
);

Ok(id)
})
.unwrap();
assert!(read_id >= last_id);
last_id = read_id;
}
});
threads.push(thread);
Expand Down

0 comments on commit e048de8

Please sign in to comment.