wal-truncate-rewrites-files

Status: IN

`WriteAheadLog.truncate()` reads and rewrites every segment file record-by-record rather than deleting whole segment files, making it O(total records) instead of O(segments)

Source: entries/2026/05/29/topic-log-compaction-vs-persistence.md

Example

for path in self._wal_files():
    kept = []
    with open(path, "rb") as f:
        while True:
            rec = _read_record(f)
            if rec is None: break
            if rec.seq_num > up_to_seq:
                kept.append(rec)
    if not kept: os.remove(path)
    else:
        with open(path, "wb") as f:
            for rec in kept: f.write(_encode_record(...))

JSON