Expand description
Alignment padding records.
O_DIRECT requires every write to be a multiple of the device block size, so the tail of a flush batch is padded out to the next boundary and the file offset advances by the padded length. The bytes in that gap are not part of any record.
Leaving the gap unframed breaks replay. A reader walks records back to back, so it lands on the padding and tries to parse it as a record header — the bytes are stale content from a previous batch (the write buffer is reused without being re-zeroed), and even all-zero padding fails the magic check. The reader treats that as the end of the committed prefix, so a segment holding more than one flush batch replays only its first batch.
Padding is therefore framed as a record: the gap is filled with a Noop
whose payload is zeroes, keeping the record chain continuous across batch
boundaries so every reader walks the whole segment. Padding records carry
LSN 0, are never mirrored into the double-write buffer, and are skipped by
all readers rather than surfaced to replay.
Constants§
- MIN_
PADDING_ RECORD_ SIZE - Smallest on-disk footprint a padding record can occupy: a bare header with an empty payload. A gap narrower than this cannot be framed at all.
Functions§
- padding_
record - Build a padding record occupying exactly
total_sizebytes on disk. - padding_
span - On-disk size of the padding record needed to bring
lenup to analignmentboundary, orNonewhenlenis already aligned.