From b7e895fce6c034cd390024eabbb0f8fc8bf84c56 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sat, 22 Aug 2020 13:35:21 +0200 Subject: [PATCH 1/2] Cut 0.34.3 --- CHANGELOG.md | 6 ++++++ Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b00e44b1..9125450d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.34.3 + +## New Features + +* #1146 added TransactionalTree::generate_id + # 0.34.2 ## Improvements diff --git a/Cargo.toml b/Cargo.toml index 67470f1f8..36b589134 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sled" -version = "0.34.2" +version = "0.34.3" authors = ["Tyler Neely "] description = "a modern embedded database" license = "MIT/Apache-2.0" From 741014fbf412e2d83fcd28b7941e9665cd8c9f24 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Sat, 22 Aug 2020 13:59:20 +0200 Subject: [PATCH 2/2] Add crash test for TransactionalTree::generate_id --- tests/test_crash_recovery.rs | 42 +++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/tests/test_crash_recovery.rs b/tests/test_crash_recovery.rs index 7b86e3cbb..c67ce4ae2 100644 --- a/tests/test_crash_recovery.rs +++ b/tests/test_crash_recovery.rs @@ -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}; @@ -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![]; @@ -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(()) @@ -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);