Skip to content

Commit 12afe92

Browse files
committed
set SEALED flag on seal
1 parent 1b6c0ab commit 12afe92

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

libsql-wal/src/segment/current.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,24 @@ impl<F> CurrentSegment<F> {
307307
let mut writer = BufWriter::new(&mut cursor);
308308
self.index.merge_all(&mut writer)?;
309309
writer.into_inner().map_err(|e| e.into_parts().0)?;
310+
// we perform a first sync to ensure that all the segment has been flushed to disk. We then
311+
// write the header and flush again. We want to guarantee that if we find a segement marked
312+
// as "SEALED", then there was no partial flush.
313+
//
314+
// If a segment is found that doesn't have the SEALED flag, then we enter crash recovery,
315+
// and we need to check the segment.
316+
self.file.sync_all()?;
317+
310318
header.index_offset = index_byte_offset.into();
311319
header.index_size = cursor.count().into();
312320
header.recompute_checksum();
321+
let flags = header.flags();
322+
header.set_flags(flags | SegmentFlags::SEALED);
313323
self.file.write_all_at(header.as_bytes(), 0)?;
324+
325+
// flush the header.
326+
self.file.sync_all()?;
327+
314328
let sealed = SealedSegment::open(
315329
self.file.clone(),
316330
self.path.clone(),

0 commit comments

Comments
 (0)