From 361d19adaad82e1c366e3b16e2bda0f8f7e32881 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 22 Jun 2021 18:39:40 +0800 Subject: [PATCH] [space_map (rust)] Fix cache hit with async-io --- src/pdata/space_map_metadata.rs | 2 +- src/write_batcher.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pdata/space_map_metadata.rs b/src/pdata/space_map_metadata.rs index be55fc3..9002ca0 100644 --- a/src/pdata/space_map_metadata.rs +++ b/src/pdata/space_map_metadata.rs @@ -77,7 +77,7 @@ fn adjust_counts( let nr_free = ie.nr_free - (end - begin) as u32; // 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())?; // Update all the entries diff --git a/src/write_batcher.rs b/src/write_batcher.rs index b6e7a34..2300c87 100644 --- a/src/write_batcher.rs +++ b/src/write_batcher.rs @@ -109,6 +109,14 @@ impl WriteBatcher { pub fn write(&mut self, b: Block, kind: checksum::BT) -> Result<()> { 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 { let mut tmp = Vec::new(); std::mem::swap(&mut tmp, &mut self.queue);