{"id":"wal-truncate-rewrites-files","text":"`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)","truth_value":"IN","source":"entries/2026/05/29/topic-log-compaction-vs-persistence.md","source_url":"","source_hash":"","justifications":[],"dependents":[],"metadata":{"example":"for path in self._wal_files():\n    kept = []\n    with open(path, \"rb\") as f:\n        while True:\n            rec = _read_record(f)\n            if rec is None: break\n            if rec.seq_num > up_to_seq:\n                kept.append(rec)\n    if not kept: os.remove(path)\n    else:\n        with open(path, \"wb\") as f:\n            for rec in kept: f.write(_encode_record(...))"},"explanation":{"steps":[{"node":"wal-truncate-rewrites-files","truth_value":"IN","reason":"premise"}]}}