[space_map (rust)] Fix cache hit with async-io

This commit is contained in:
Ming-Hung Tsai 2021-06-22 18:39:40 +08:00
parent 5dd2e81bf0
commit 361d19adaa
2 changed files with 9 additions and 1 deletions

View File

@ -77,7 +77,7 @@ fn adjust_counts(
let nr_free = ie.nr_free - (end - begin) as u32; let nr_free = ie.nr_free - (end - begin) as u32;
// Read the bitmap // Read the bitmap
let bitmap_block = w.engine.read(ie.blocknr)?; let bitmap_block = w.read(ie.blocknr)?;
let (_, mut bitmap) = Bitmap::unpack(bitmap_block.get_data())?; let (_, mut bitmap) = Bitmap::unpack(bitmap_block.get_data())?;
// Update all the entries // Update all the entries

View File

@ -109,6 +109,14 @@ impl WriteBatcher {
pub fn write(&mut self, b: Block, kind: checksum::BT) -> Result<()> { pub fn write(&mut self, b: Block, kind: checksum::BT) -> Result<()> {
checksum::write_checksum(&mut b.get_data(), kind)?; checksum::write_checksum(&mut b.get_data(), kind)?;
for blk in self.queue.iter().rev() {
if blk.loc == b.loc {
// write hit
blk.get_data().copy_from_slice(b.get_data());
return Ok(());
}
}
if self.queue.len() == self.batch_size { if self.queue.len() == self.batch_size {
let mut tmp = Vec::new(); let mut tmp = Vec::new();
std::mem::swap(&mut tmp, &mut self.queue); std::mem::swap(&mut tmp, &mut self.queue);