[space_map (rust)] Fix space map building
- Fix out-of-bounds index - Automatically flush queued writes before function return - Track allocated blocks in write_batcher (might be space consuming)
This commit is contained in:
parent
13d6c72ad9
commit
c142cd0d48
@ -209,7 +209,7 @@ pub fn write_common(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result<(Vec<Inde
|
||||
let mut nr_free: u32 = 0;
|
||||
for i in 0..ENTRIES_PER_BITMAP {
|
||||
let b: u64 = ((bm * ENTRIES_PER_BITMAP) as u64) + i as u64;
|
||||
if b > sm.get_nr_blocks()? {
|
||||
if b >= sm.get_nr_blocks()? {
|
||||
break;
|
||||
}
|
||||
let rc = sm.get(b)?;
|
||||
|
@ -16,6 +16,7 @@ pub fn write_disk_sm(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result<SMRoot>
|
||||
}
|
||||
|
||||
let bitmap_root = index_builder.complete(w)?;
|
||||
w.flush()?;
|
||||
|
||||
Ok(SMRoot {
|
||||
nr_blocks: sm.get_nr_blocks()?,
|
||||
|
@ -126,6 +126,7 @@ pub fn write_metadata_sm(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result<SMRo
|
||||
metadata_index.pack(&mut cur)?;
|
||||
let loc = bitmap_root.loc;
|
||||
w.write(bitmap_root, checksum::BT::INDEX)?;
|
||||
w.flush()?;
|
||||
|
||||
Ok(SMRoot {
|
||||
nr_blocks: sm.get_nr_blocks()?,
|
||||
|
@ -43,6 +43,7 @@ impl WriteBatcher {
|
||||
return Err(anyhow!("out of metadata space"));
|
||||
}
|
||||
|
||||
self.allocations.insert(b.unwrap());
|
||||
Ok(Block::new(b.unwrap()))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user