4.4 KiB
Chunk-local mutation boundary
Signatures confirmed:
func (s *WALStore) ClearChunkLocal(chunk uint64) error
func (s *WALStore) MarkChunkLocal(chunk uint64) error
func (s *WALStore) MarkChunksLocal(chunks []uint64) error
Success is immediate durable map publication, not a promise to publish at the next checkpoint. Methods take store/lifecycle locks internally; the caller must not hold stMu. Uninitialized/unrecovered coverage returns ErrChunkCoverageUnavailable. Out-of-range returns *ChunkCoverageRangeError. A publication error is not permission to drop bytes or claim durable all-local coverage.
Clear: caller establishes that the chunk equals its current HEAD reference and excludes guest writes, fills and another eviction with the existing destructive admission barrier. Caller first writes/syncs the absent record page, calls Clear, and only on success may discard bytes. Keep that barrier across the complete sequence. An older prepared map is invalidated before the local bits are cleared.
The crash window between absent record page and durable map clear retains the old bytes. The old bitmap may still say local, but those bytes have not been discarded and still equal the admitted reference. Safety does not depend on the loader overriding bitmap authority using an absent page. After the clear is durable, leftover physical bytes are harmless; their local bits are absent. A failed clear leaves bytes in place; retry/reopen is required.
Mark: caller has resolved every fill in the batch, installed every missing extent block with local writes winning, and excluded stale fill/eviction. MarkChunksLocal syncs all the batch extents before persisting their all-local bitmaps in ONE map publication, then returns after the sole descriptor publisher syncs the new tuple. Validate the entire batch before changing memory; an invalid member changes none. Empty batches do nothing and duplicate indexes are harmless. MarkChunkLocal delegates to the same batch boundary with one index. Only then may a record page durably claim whole-local. A crash before successful publication repeats a fetch conservatively; it never authorizes bitmap bits over unsynced bytes. The final short chunk uses its actual block count.
Both operations preserve the chunk's LSN, checkpoint and log tail; no acknowledged write is discarded by the store boundary itself. The caller's clean-eviction admission is mandatory. Concurrent Recover is checked with the existing generation/proof and leader rules. The new methods do not write record pages or activate the draft format.
Validation refusals before mutation, including an invalid batch or an in-progress BASE install, leave coverage unchanged. Memory changes before durable publication, so an error after mutation can leave memory and disk different. After a failed Clear, memory says absent while the caller retains the bytes, so reads can fetch remotely. After a failed Mark, memory says local over installed bytes, and any later publication syncs those extents before publishing the bits. A retryable preparation/refusal can converge through an idempotent retry or later checkpoint. A latched extent-sync or uncertain descriptor-publication fault requires reopen and recovery; the faulted open refuses further mutations, checkpoints and coverage reads. An error still grants no permission to discard bytes or claim durable coverage.
The extent-sync failure control observes map sync and descriptor publication, not the first map write. Its coverage does not independently prove the absence of earlier map writes; extent sync precedes map preparation in the production call order.
Cost limit: the current shared map preparer still copies/validates the full map per publication. Until that work is proportional to changed pages, callers batch on the record-page schedule: at most ceil(N/B) publications for N restored chunks in batches of B, then persist those record pages. Clear also publishes the whole map once per eviction. No production eviction caller is wired here; a future eviction driver may call it per chunk only after checkpoint work is proportional to changed pages, or must gain a batch boundary first. Fixed-size batching amortizes the work; its current cost is still O(S * ceil(N/B)), not a claimed linear restore. This small prerequisite exposes the correct durable boundary first; the checkpoint-by-changed-pages work owns removal of the O(S) work. No proportional-cost or stop-time claim here.