mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
110 lines
6.7 KiB
Markdown
110 lines
6.7 KiB
Markdown
# Durable chunk coverage (draft)
|
|
|
|
This draft specifies the storage-only target contract below. Its component tests do not establish daemon activation; the ledger remains STUB until that integration is qualified.
|
|
|
|
The store exposes `Coverage(chunk uint64) (LocalCoverage, uint64, error)`.
|
|
The coverage and position are one observation under the store lock. Coverage
|
|
is `CoverageNone`, `CoverageSome`, or `CoverageAll`; it describes local blocks,
|
|
not equality with a remote reference. An uninitialized or unrecovered store
|
|
returns `ErrChunkCoverageUnavailable`. Failed recovery invalidates the answer. A persisted chunk position above the retained WAL frontier refuses recovery with a WAL-integrity error; later LSN reuse cannot authorize those bits.
|
|
|
|
## Upgrade boundary
|
|
|
|
`InitializeChunkCoverage(ctx, epoch, seed, preparePages)` runs after recovery
|
|
and Sync, before chunk attachment, with extent draining held. The seed provides
|
|
local block offsets or `All` per chunk. The store persists the bitmap candidate,
|
|
then calls `preparePages(ChunkCoverageReader)` with its immutable prepared view.
|
|
That callback must persist the corresponding checked chunk-record pages. Only
|
|
then does the store publish the bitmap root and epoch together and complete the
|
|
two-slot fence, including sync and exact readback of both slots. The caller may
|
|
write the completion header and remove legacy presence only after success.
|
|
A same-epoch retry reuses the recovered bitmap and calls preparePages again.
|
|
An active BASE install or descriptor reset refuses before calling either
|
|
callback or publishing any candidate.
|
|
|
|
Presence is evidence only before the marker. Once marked at this epoch, the
|
|
initializer never calls seed: it rebuilds pages from the recovered bitmap. A
|
|
marked store without a readable initialized bitmap refuses as unavailable.
|
|
A marker at another epoch returns `ChunkCoverageEpochMismatchError` before
|
|
calling either callback or writing storage. Attach-after-move owns Drop and
|
|
the new epoch; neither this initialization API nor the legacy fence can relabel an initialized coverage map.
|
|
Failed or uncertain descriptor publication retains the existing
|
|
fault latch and requires reopening.
|
|
|
|
## Map format 2
|
|
|
|
All integer fields are little endian. The descriptor's MapFormatID is 2 and
|
|
requires the chunk-state format marker and a nonzero local-work epoch. The map
|
|
file uses immutable 4096-byte pages and the existing root publication mechanism.
|
|
The root is 4096 bytes; its hash and locator are named by the descriptor.
|
|
|
|
The logical entry stream contains, per chunk, LSN (8 bytes), Unknown (1 byte),
|
|
seven zero bytes, and ceil(chunkBlocks/8) bitmap bytes, least-significant bit
|
|
first. Entries may cross leaf boundaries. Bits beyond the last short chunk and
|
|
unused bits in the final byte are zero. Each leaf has the CLM3 header (version 2),
|
|
4000 payload bytes, and the existing 32-byte page hash. Header identity includes
|
|
UUID, map lineage, generation, page index and payload length.
|
|
|
|
The CLR3 root uses version 2, a level at offset 6, the existing identity and
|
|
shape fields through offset 87, and a default position at offsets 88..95.
|
|
References start at offset 96. Each reference is an 8-byte locator and 32-byte
|
|
hash. At most 96 references appear in a page. CLI3 index pages use version 2,
|
|
level, UUID, lineage, generation, first leaf index (offset 48), child count
|
|
(offset 56), zero padding through offset 63, and references from offset 64.
|
|
Their final 32 bytes hash the preceding 4064 bytes with domain
|
|
`swblock:chunk-map:index:v2\0`. Root and leaf hashes retain their existing
|
|
domains. A zero locator AND zero hash is a virtual subtree: the reader supplies the root-defined default byte at each entry-relative offset covered by that subtree. Bytes supplied by other leaves remain unchanged. A physical page
|
|
at locator zero has a nonzero hash. Virtual references pin no file extent.
|
|
|
|
Unchanged leaves and index branches are shared across roots. New leaves are
|
|
synced first; index pages and the root share the final sync before descriptor publication.
|
|
A captured bitmap's data file is synced before preparing its metadata pages.
|
|
|
|
## Qualification boundary
|
|
|
|
The ledger remains STUB until the daemon caller and runtime fill/BASE paths
|
|
are integrated and qualified. This draft implements recovery, initialization,
|
|
WAL write/replay, and checkpoint observations. Fill/BASE bitmap updates and
|
|
metadata-only persistence still need integration. The disk tree allows bounded
|
|
fanout, but the current runtime retains full entry/reference arrays and scans
|
|
them during preparation. No proportional runtime cost or scale claim is made. Before allocation, eager
|
|
runtime admission limits the combined logical bitmap and entry/reference tables
|
|
to a 1-GiB shape estimate. This is a runtime guard, not an on-disk format limit
|
|
or a total resident-memory promise; larger geometry refuses with ErrMapInvalid
|
|
until a paged implementation is qualified.
|
|
|
|
## Half-fence recovery
|
|
|
|
```mermaid
|
|
flowchart TD
|
|
A[Selected slot map] --> B{Intact?}
|
|
B -->|yes| C[Open selected slot]
|
|
B -->|no| D{Integrity-only failure; selected marked; same incarnation; other valid, unmarked and intact?}
|
|
D -->|yes| E[Open legacy slot; restart recovery and upgrade]
|
|
D -->|no| F[Refuse open]
|
|
```
|
|
|
|
A marked map can be overwritten by an old writer before that writer publishes
|
|
its next descriptor. The opener can then select the other slot only when it is
|
|
valid, unmarked, and has an intact map, with the same identity, geometry, nonce
|
|
and map lineage. Every leaf of a wrapped or joined cause tree must be an integrity error;
|
|
a short-read joined with a failed close does not authorize fallback. If the
|
|
fallback map also fails, both causes are returned. Operational I/O errors do
|
|
not authorize fallback. The discarded
|
|
marked slot is excluded from map binding; Recover replaces it through the sole
|
|
publisher. Both-marked map damage refuses, even when the older marked map is
|
|
intact, because falling back there could lose acknowledged marked writes.
|
|
|
|
`WALStoreOptions.RecoveryEvent` observes a typed `RecoveryHalfFenceFallback`
|
|
event after successful open, carrying discarded and selected slot generations.
|
|
The observer performs no I/O or storage calls. `ChunkMapStatsV3.HalfFenceFallbacks`
|
|
counts these opens in this process (zero on an ordinary reopen). Neither means
|
|
replay, upgrade or readiness is complete. Legacy presence remains the evidence
|
|
for restarting the unmarked upgrade; stale record pages must not be trusted.
|
|
|
|
The component control uses the unchanged format-1 allocator with only the
|
|
legacy root visible, prepares pages without a descriptor publication, confirms
|
|
marked-root damage and intact legacy dependencies, then checks byte-exact ACKed
|
|
replay, re-upgrade and another reopen. This is not the separately owed actual
|
|
released-binary downgrade/crash qualification. Ledger and trace remain STUB.
|