B:BD[
10.1912] → [
10.1912:2076]
B:BD[
10.2076] → [
11.2467:2539]
∅:D[
11.2539] → [
10.2152:2283]
B:BD[
10.2152] → [
10.2152:2283]
B:BD[
10.2283] → [
11.2540:2589]
∅:D[
11.2589] → [
10.2336:2381]
B:BD[
10.2336] → [
10.2336:2381]
B:BD[
10.2381] → [
7.27376:27436]
∅:D[
7.27436] → [
10.2444:2536]
B:BD[
10.2444] → [
10.2444:2536]
B:BD[
10.2536] → [
11.2590:2639]
∅:D[
11.2639] → [
10.2589:2688]
B:BD[
10.2589] → [
10.2589:2688]
let env = Env::new("/tmp/sanakirja0", 4096 * 20, 2).unwrap();
let mut txn = Env::mut_txn_begin(&env).unwrap();
debug!("txn.root = {:?}", txn.env.root);
let db = create_db::<MutTxn<&Env, ()>, u64, ()>(&mut txn).unwrap();
debug!("db = {:?}", db.db.offset);
txn.set_root(0, db.db.offset);
txn.commit().unwrap();
debug!("1. commit done");
let txn = Env::mut_txn_begin(&env).unwrap();
debug!("txn.root = {:?}", txn.env.root);
let db: Db<u64, ()> = txn.root_db(0).unwrap().unwrap();
debug!("txn.root = {:?}", db);
txn.commit().unwrap();
debug!("2. commit done");
let txn = Env::mut_txn_begin(&env).unwrap();
debug!("txn.root = {:?}", txn.env.root);
txn.commit().unwrap();
debug!("commit done");
env_logger::try_init().unwrap_or(());
let mut child = unsafe { libc::fork() };
if child == 0 {
// child
let env = Env::new("/tmp/sanakirja0", 4096 * 20, 2).unwrap();
// Mutable txn
let mut txn = Env::mut_txn_begin(&env).unwrap();
info!("started child mutable txn {:?}", txn.env.root.lock());
let db = create_db::<MutTxn<&Env, ()>, u64, ()>(&mut txn).unwrap();
debug!("db = {:?}", db.db.offset);
txn.set_root(0, db.db.offset);
std::thread::sleep(std::time::Duration::from_secs(2));
txn.commit().unwrap();
info!("committed");
let t = std::time::SystemTime::now();
let mut txn = Env::mut_txn_begin(&env).unwrap();
// Since the parent has an immutable transaction started, we
// need to wait for at least some time (1s - 100ms of
// synchronisation margin).
assert!(t.elapsed().unwrap() >= std::time::Duration::from_millis(900));
info!("started child mutable txn {:?}", txn.env.root.lock());
let db = create_db::<MutTxn<&Env, ()>, u64, ()>(&mut txn).unwrap();
debug!("db = {:?}", db.db.offset);
txn.set_root(0, db.db.offset);
std::thread::sleep(std::time::Duration::from_secs(1));
txn.commit().unwrap();
unsafe { libc::exit(0) }
} else {
// parent
std::thread::sleep(std::time::Duration::from_secs(1));
let env = Env::new("/tmp/sanakirja0", 4096 * 20, 2).unwrap();
// Immutable
info!("starting parent txn {:?}", env.root);
let txn = Env::txn_begin(&env).unwrap();
info!("started parent txn");
std::thread::sleep(std::time::Duration::from_secs(3));
std::mem::drop(txn);
unsafe { libc::wait(&mut child) };
}