Skip to content

Commit

Permalink
Abort update if another has run concurrently (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Nov 22, 2022
1 parent c8f3336 commit f03b798
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,7 @@ impl Updater {
Some(progress_bar)
};

let rx = Self::fetch_blocks_from(
index,
wtx
.open_table(super::HEIGHT_TO_BLOCK_HASH)?
.range(0..)?
.rev()
.next()
.map(|(height, _hash)| height + 1)
.unwrap_or(0),
)?;
let rx = Self::fetch_blocks_from(index, self.height)?;

let mut uncomitted = 0;
for i in 0.. {
Expand All @@ -91,8 +82,20 @@ impl Updater {

if i % 5000 == 0 {
self.commit(wtx)?;
wtx = index.begin_write()?;
uncomitted = 0;
wtx = index.begin_write()?;
let height = wtx
.open_table(HEIGHT_TO_BLOCK_HASH)?
.range(0..)?
.rev()
.next()
.map(|(height, _hash)| height + 1)
.unwrap_or(0);
if height != self.height {
// another update has run between committing and beginning the new
// write transaction
break;
}
}

if INTERRUPTS.load(atomic::Ordering::Relaxed) > 0 {
Expand Down

0 comments on commit f03b798

Please sign in to comment.