1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-23 14:50:45 +01:00

Persist last indexed block marker

This commit is contained in:
Roman Zeyde 2018-07-11 21:16:34 +03:00
parent 6609d6e008
commit dd70a1cc8a
No known key found for this signature in database
GPG key ID: 87CAE5FA46917CBB
2 changed files with 13 additions and 1 deletions

View file

@ -87,7 +87,9 @@ fn run(config: Config) -> Result<()> {
.expect("indexer panicked")
.expect("indexing failed")
});
store.compact();
store.write(vec![parser.last_indexed_row()]);
store.flush();
store.compact(); // will take a while.
}).join()
.expect("writer panicked");
Ok(())

View file

@ -51,6 +51,16 @@ impl Parser {
})
}
pub fn last_indexed_row(&self) -> Row {
let indexed_blockhashes = self.indexed_blockhashes.lock().unwrap();
let last_header = self.current_headers
.iter()
.take_while(|h| indexed_blockhashes.contains(h.hash()))
.last()
.expect("no indexed header found");
last_indexed_block(last_header.hash())
}
pub fn read_blkfile(&self, path: &Path) -> Result<Vec<u8>> {
let timer = self.duration.with_label_values(&["read"]).start_timer();
let blob = fs::read(&path).chain_err(|| format!("failed to read {:?}", path))?;