Skip to content

Commit

Permalink
Only load sequences when DB is fresh
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaum committed Jan 15, 2025
1 parent 288698b commit 4015322
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions crates/db/src/worldstate_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,23 @@ impl WorldStateDB {

let sequences = [(); 16].map(|_| Arc::new(AtomicI64::new(-1)));

// Fill sequences from the sequences partition.
for (i, seq) in sequences.iter().enumerate() {
let seq_value = sequences_partition
.get(i.to_le_bytes())
.unwrap()
.map(|b| i64::from_le_bytes(b[0..8].try_into().unwrap()))
.unwrap_or(-1);
seq.store(seq_value, std::sync::atomic::Ordering::SeqCst);
}

let mut fresh = false;
if !keyspace.partition_exists("object_location") {
fresh = true;
}

if !fresh {
// Fill sequences from the sequences partition.
for (i, seq) in sequences.iter().enumerate() {
let seq_value = sequences_partition
.get(i.to_le_bytes())
.unwrap()
.map(|b| i64::from_le_bytes(b[0..8].try_into().unwrap()))
.unwrap_or(-1);
seq.store(seq_value, std::sync::atomic::Ordering::SeqCst);
}
}

// 16th sequence is the monotonic transaction number.
let start_tx_num = sequences_partition
.get(15_u64.to_le_bytes())
Expand Down

0 comments on commit 4015322

Please sign in to comment.