[thin_restore (rust)] Apply several fixes

- Fix reading queued blocks
- Fix unnecessary block shadowing when there's no remaining values
- Prevent superblock from overwritten
- Flush queued writes before updating superblock
This commit is contained in:
Ming-Hung Tsai
2021-05-02 23:51:56 +08:00
parent e9899ac610
commit 4b4584c830
3 changed files with 24 additions and 9 deletions

View File

@ -65,6 +65,18 @@ impl WriteBatcher {
Ok(())
}
pub fn read(&mut self, blocknr: u64) -> Result<Block> {
for b in self.queue.iter().rev() {
if b.loc == blocknr {
let r = Block::new(b.loc);
r.get_data().copy_from_slice(b.get_data());
return Ok(r);
}
}
self.engine.read(blocknr).map_err(|_| anyhow!("read block error"))
}
pub fn flush_(&mut self, queue: Vec<Block>) -> Result<()> {
self.engine.write_many(&queue)?;
Ok(())