Remove some special-casing logic
@@ -419,9 +419,11 @@ impl SegmentAccountant {
fn initialize_from_snapshot(&mut self, snapshot: Snapshot) -> Result<()> {
let io_buf_size = self.config.io_buf_size;
let file_len = self.config.file.metadata()?.len();
+ let empty_snapshot = snapshot.pt.is_empty();
let number_of_segments = usize::try_from(file_len / io_buf_size as u64)
.unwrap()
- + if file_len % u64::try_from(io_buf_size).unwrap()
+ + if empty_snapshot
+ || file_len % u64::try_from(io_buf_size).unwrap()
< u64::try_from(SEG_HEADER_LEN).unwrap()
{
0
@@ -429,6 +431,10 @@ impl SegmentAccountant {
1
};
+ if empty_snapshot {
+ assert_eq!(number_of_segments, 0);
+ }
+
// generate segments from snapshot lids
let mut segments = vec![Segment::default(); number_of_segments];
let mut segment_sizes = vec![0_usize; number_of_segments];
