[space_map (rust)] Fix uninitialized bytes in index block

This commit is contained in:
Ming-Hung Tsai
2021-06-03 16:43:14 +08:00
parent 01aac6c1c1
commit 60b65ebe7a
3 changed files with 20 additions and 9 deletions

View File

@@ -47,6 +47,18 @@ impl WriteBatcher {
Ok(Block::new(b.unwrap()))
}
pub fn alloc_zeroed(&mut self) -> Result<Block> {
let mut sm = self.sm.lock().unwrap();
let b = sm.alloc()?;
if b.is_none() {
return Err(anyhow!("out of metadata space"));
}
self.allocations.insert(b.unwrap());
Ok(Block::zeroed(b.unwrap()))
}
pub fn clear_allocations(&mut self) -> BTreeSet<u64> {
let mut tmp = BTreeSet::new();
std::mem::swap(&mut tmp, &mut self.allocations);