mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
docs: a restored volume stays bound to its source snapshot; drop pages of the old store
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b0b0a6ebb7
commit
1feaa18b31
4 files changed
+6
-265
No files matched your search
@@ -22,7 +22,8 @@ var errNoLayoutHolder = errors.New("blockvolume: no layout holder identity for t
|
||||
// cleaning entry: a cut or a stop cancels it through the remote's state.
|
||||
// cleanerOf returns the remote Start established; its Begin refuses unless
|
||||
// HEAD is still that holder's at its epoch, so a process that lost the
|
||||
// volume removes nothing. Automatic cleaning stays default-off; retention runs either way.
|
||||
// volume removes nothing. Automatic cleaning is on by default (--chunk-maintenance-gc);
|
||||
// retention runs either way.
|
||||
// layoutCleaner is the holder's layout remote as the maintenance cleans
|
||||
// through it (chunkstore.LayoutRemote).
|
||||
type layoutCleaner interface {
|
||||
|
||||
@@ -1,263 +0,0 @@
|
||||
# Chunk garbage collection (W5)
|
||||
|
||||
`NewCollector(catalog, blobDeleter, config).Run(ctx)` traces every volume returned by the catalog, every HEAD, every snapshot (including unnamed attempt entries), and every live upload/copy intent. Use a deadline-bound context. Supply `IssuedEpoch` from the authoritative blockmaster reader, not lease expiry or a host-local projection. The CLI below binds that reader to blockmaster; there is no automatic scheduler.
|
||||
|
||||
A capture intent can expire only when its age strictly exceeds IntentTTL, the blockmaster has issued a higher epoch, and the actual remote HEAD has advanced to a higher epoch no greater than the issued one. Unknown authority retains it. Snapshot/fork copy intents never expire by epoch. `SweepCopies(ctx)` may settle an attempt past its recorded deadline only by claiming its final immutable publication target through Catalog.AbortSnapshot/AbortFork. Snapshot targets are `snaps/<name>/<attempt>`; fork targets are HEAD, never VOLUME. A confirmed permanent aborted target or a validated published target settles the intent. Unknown claim/read retains it. The deadline admits a claim but never by itself releases protection. Old copy intents without deadline metadata remain protected.
|
||||
|
||||
An immutable binding becomes a candidate only when its creation time is strictly older than Grace and no root names it. Reclamation requires another successful mark at least Grace after its first observation with the same binding bytes. A rooted candidate is forgotten; failed marks discard coverage. A bare Collector restart discards coverage; ExecuteGC restores only a completed, configuration-matching filer mark. Grace must exceed the catalog operation deadline plus the measured mark duration. Backward clock movement refuses the pass.
|
||||
|
||||
Before physical deletion the binding receives a conditional `swb.gc.deleted=1` tombstone; after every resolved replica deletion succeeds it becomes `done`. Bindings are never removed or rebound. Failed/uncertain blob deletion returns an error and retains the fid for a conservative retry after fresh marks. The SeaweedFS adapter deletes the exact fid, accepts only HTTP 200/202/204/404 (SeaweedFS returns 202 after synchronous replicated deletion), and propagates transport/other HTTP failures. Authenticated deployments must supply a BlobDeleter with their write authorization; this patch does not add an auth provisioning path.
|
||||
|
||||
Unbound needles (upload succeeded but key binding never persisted) are RETAINED. The existing interfaces cannot enumerate/count them, so `UnknownUnbound=true` reports that limitation instead of a fabricated zero. No sweep is attempted.
|
||||
|
||||
## Scope and follow-ups
|
||||
|
||||
This first Draft implements the GC core and the real Capture/intent/HEAD caller regression. Retention (newest N plus logarithmic age buckets), workspace tombstoning, automatic scheduling remain follow-up W5 slices. The CLI and blockmaster epoch binding are available below. Unnamed deleting snapshot attempts root their keys until their deleting timestamp is older than grace; normal two-mark/upload-age admission still applies afterward. The immutable attempt record is never removed, even after reclaim. Active unnamed attempts remain roots. This is not complete workspace lifecycle acceptance.
|
||||
|
||||
## Lock order
|
||||
|
||||
The new Collector mutex serializes its own passes and candidate state; it never enters WAL, publication, shard or chunk-layer locks. Remote calls execute only while holding that collector-local mutex. Producer Capture already uploads after releasing its capture/publication barrier, so GC adds no edge to the storage lock graph. The epoch-reader and BlobDeleter must not re-enter this Collector. Multiple collectors may repeat idempotent physical deletes, but each must independently satisfy the two-mark grace rule.
|
||||
|
||||
## Evidence boundary
|
||||
|
||||
The assertion RED is an initial GC candidate that already implemented HEAD/snapshot tracing and two marks but omitted intent roots; the base has no GC API to test. It is NOT claimed as a GC bug reproduced on unmodified main. The same test holds the shipping Capture before CAS after real immutable uploads, runs two GC marks, resumes CAS, and reads exact bytes through ChunkRemote. Filer/needle services are deterministic adapters; no SeaweedFS process, hardware, lab or cloud acceptance is claimed.
|
||||
|
||||
## Copy-sweep integration
|
||||
|
||||
The follow-up branch merges W2 #119 b51713e with #117 5f010ca (the #121 parent). The sole capture conflict keeps #117's pre-upload intent list and cleanup semantics, and retains #119's typed `ErrChunkRemoteUnavailable` wrapper on upload failure. No capture intent is swept through the copy protocol. Name reuse creates a new snapshot attempt; permanent old attempt tombstones continue refusing late old inserts. Volume IDs cannot be reused.
|
||||
|
||||
The first copy-sweep RED uses the prior retain-forever behavior (a no-op SweepCopies seam), not a claimed bug on an unmodified main. The same real Catalog caller turns GREEN with permanent-target claims. Tests cover a pending snapshot across name reuse, a fork with VOLUME already present and HEAD held, published unnamed/deleting attempts, unknown claim recovery, and the retained stalled-Capture case. Deterministic remote services only; no lab/cloud actions.
|
||||
|
||||
## Operational CLI
|
||||
|
||||
Use the existing `sw-block ops chunk` surface rather than a background job: the
|
||||
operator explicitly chooses the catalog namespace and when deletion is allowed.
|
||||
Before applied GC, configure durable filer writes for the namespace using the
|
||||
SeaweedFS shell, e.g. `fs.configure -locationPrefix=/swblock/ -collection=swblock -fsync -apply`,
|
||||
and retain that configuration. The catalog path must fall under the configured
|
||||
prefix. A different namespace needs its matching rule. The default is a read-only JSON preview:
|
||||
|
||||
```sh
|
||||
sw-block ops chunk gc --chunk-filer 127.0.0.1:18888 \
|
||||
--chunk-path /swblock/chunks --master 127.0.0.1:9090
|
||||
# First applied mark records candidates; it does not reclaim newly seen keys.
|
||||
sw-block ops chunk gc --chunk-filer 127.0.0.1:18888 \
|
||||
--chunk-path /swblock/chunks --master 127.0.0.1:9090 --apply
|
||||
# Repeat --apply after at least --grace (default 1h).
|
||||
```
|
||||
|
||||
`--master` is the blockmaster gRPC endpoint, not the SeaweedFS master. The
|
||||
`EvidenceService.QueryVolumeStatus` reply must identify the requested volume and
|
||||
an assigned, nonzero epoch. Unknown authority retains capture intents. Expiry
|
||||
still requires both the higher issued epoch and a higher actual remote HEAD,
|
||||
plus `--intent-ttl` (default 1h). No lease-expiry inference is used.
|
||||
|
||||
The JSON `roots` array identifies HEADs, snapshots, snapshot attempts, capture
|
||||
intents and `retained_copy_intent` roots with their keys. `would_delete` lists
|
||||
mature unrooted key/fid pairs; `would_expire_intents` names eligible capture
|
||||
intents. `Reclaimed`, `ExpiredIntents`, `settled_copy_intents` and `mark_saved`
|
||||
describe actual effects. A preview does not settle copy intents, expire capture
|
||||
intents, write marks or delete blobs. Consequently a copy that an apply can
|
||||
settle may still appear as a retained root in the preceding preview.
|
||||
|
||||
Independent apply calls persist two-mark coverage in `_GC_MARK` under the
|
||||
catalog namespace. A conditional in-progress mark invalidates old coverage
|
||||
before effects; only a completed pass saves fresh coverage. A failed scan after an acknowledged in-progress write does not save completed
|
||||
coverage. Configuration changes cannot reuse prior coverage. A mark write can
|
||||
commit and then lose its response: an error does **not** prove that remote
|
||||
coverage is absent or unchanged. Do not edit or copy this state between namespaces. All filer/master/
|
||||
blob calls share `--timeout` (default 1m). Grace must exceed the catalog operation
|
||||
deadline (5m) plus the measured mark duration. Increase timeout only if the pass
|
||||
still fits that safety margin. Permanent attempt, HEAD and key tombstones are
|
||||
never removed by this command. Pre-binding needle enumeration remains unknown.
|
||||
|
||||
The CLI adds no storage lock edge: the collector retains its local mutex and
|
||||
uses the existing remote APIs. The persisted mark uses filer conditional writes,
|
||||
not a new WAL/publication/shard lock. Concurrent apply calls can conflict and
|
||||
report an error. Callers must keep the failure status, but must not infer that
|
||||
all effects were rolled back or that no completed mark exists remotely.
|
||||
|
||||
Errors after GC execution begins return `{code,message,retryable,gc}` with the
|
||||
known partial counters/root report preserved in `gc`. `mark_saved=true` means
|
||||
the completed-write response was acknowledged, not merely attempted.
|
||||
`mark_outcome` describes this invocation: `not_attempted`, `in_progress`
|
||||
(acknowledged), `complete` (acknowledged), or `unknown` (write response lost or
|
||||
failed; remote outcome not established). `unknown_outcomes` names incomplete
|
||||
stages (`in_progress_mark_write`, `copy_intent_settlement`, `reclamation`, or
|
||||
`completed_mark_write`). A stage may have partially taken effect even though
|
||||
its acknowledged counters are lower; for example a blob delete may succeed
|
||||
then lose its reply. Do not interpret the counters as an upper bound or assume
|
||||
that retries start from a pristine store. The next invocation reads the actual
|
||||
conditional mark and authoritative roots as usual.
|
||||
|
||||
The opt-in end-to-end test invokes the actual CLI entrypoint against a real
|
||||
blockmaster runtime and real SeaweedFS master/volume/filer processes:
|
||||
|
||||
```sh
|
||||
CHUNKSTORE_WEED=/path/to/weed go test -tags chunkstore_integration \
|
||||
./cmd/sw-block -run '^TestIntegration_OpsChunkGC_RealMasterAndStore$' \
|
||||
-v -count=1 -timeout=180s
|
||||
```
|
||||
|
||||
This test requires the binary and fails rather than skips when it is absent. It configures and reads back the filer rule `fs.configure -locationPrefix=/swblock/ -collection=swblock -fsync -apply` before creating catalog data.
|
||||
It advances only the GC clock to exercise grace admission deterministically;
|
||||
network services, conditional metadata writes, authority RPC and blob deletion
|
||||
are real. It is not an elapsed-time soak or a lab qualification.
|
||||
|
||||
## Single filer
|
||||
|
||||
Every command that writes chunk metadata (`snapshot-delete`, `fork`, `retain`
|
||||
without `--dry-run`, `volume-delete`, `gc --apply`) and `verify` make the same
|
||||
start check as blockvolume before they read or write anything: it asks the
|
||||
filer for its masters and filer group, and refuses unless a master lists
|
||||
exactly one filer in that group and it is the `--chunk-filer` given. `verify`
|
||||
writes nothing, but against a split filer view it would report false
|
||||
findings. The other read-only commands and modes do not run the check. A
|
||||
filer that is not the only one of its group exits 2 with code `bad_request`;
|
||||
a check that cannot finish (a filer or master that does not answer) exits 1
|
||||
with code `remote_unavailable`, retryable. The check runs within the command's
|
||||
`--timeout`. The masters the filer reports must be reachable from where the
|
||||
command runs.
|
||||
|
||||
## Verify
|
||||
|
||||
`sw-block ops chunk verify` compares one volume's remote image with what its
|
||||
HEAD, and optionally its snapshots, say. It is read-only: it writes no intent,
|
||||
mark, tombstone or binding, and deletes nothing.
|
||||
|
||||
```sh
|
||||
sw-block ops chunk verify --volume v1 --chunk-filer 127.0.0.1:18888 \
|
||||
[--chunk-path /swblock/chunks] [--snapshot s1 | --all-snapshots] \
|
||||
[--depth meta|bindings|data] [--concurrency 2] [--bytes-per-sec 33554432] \
|
||||
[--timeout 10m]
|
||||
```
|
||||
|
||||
HEAD is always checked. `--snapshot` adds one named snapshot; `--all-snapshots`
|
||||
adds every published snapshot that is not being deleted. Each depth includes the
|
||||
one before it:
|
||||
|
||||
- `meta`: the HEAD root decodes and is self-consistent; its chunk size and chunk
|
||||
indices fit the VOLUME geometry; every segment a checked root names is
|
||||
readable, matches its SHA-256 and decodes strictly; the same for each checked
|
||||
snapshot's embedded HEAD; a snapshot's document names the volume and the
|
||||
snapshot it was found under (else `ROOT_INVALID`; the snapshot is still
|
||||
checked under the name it was found under); references to one
|
||||
chunk with different SHA-256s disagree (`CONTENT_MISMATCH`); for a fork, its
|
||||
fork record's digest matches an attempt of the parent snapshot at the
|
||||
recorded generation.
|
||||
- `bindings` (the default): also, every chunk key a checked root references has
|
||||
a binding in its owner's `keys/` (a fork's `@owner/key` resolves to the owner
|
||||
volume), of the right kind, with a fid, without filer chunks, and not
|
||||
tombstoned by GC. Each owner's `keys/` is listed once. GC's mark does not make
|
||||
this check: it never looks up the bindings of the keys it roots.
|
||||
- `data`: also, every distinct chunk (owner and key, across all checked roots)
|
||||
is read once, and its SHA-256 must equal the reference and its length the
|
||||
chunk size, the rule a guest read applies. `--depth data` requires an explicit
|
||||
`--timeout`. Reads are bounded by `--concurrency` and paced by
|
||||
`--bytes-per-sec` (0 leaves them unpaced).
|
||||
|
||||
Old capture intents below HEAD's epoch that name no key HEAD references are
|
||||
reported as `INTENT_STALE`. This is a hint only: whether GC may expire an intent
|
||||
remains GC's decision, with blockmaster authority.
|
||||
|
||||
The output is one JSON object: the HEAD generations and snapshots covered,
|
||||
segments and chunks checked, distinct chunks and bytes read, the two counters
|
||||
below, findings by class, and the findings, one per line. Each finding
|
||||
names the volume, the root (`HEAD gen N`, `snapshot name/attempt`, an intent or
|
||||
the VOLUME fork record), the chunk index or segment, the owner, key and fid, a
|
||||
class and a detail. Classes: `ROOT_INVALID`, `GEOMETRY`, `SEGMENT_UNREADABLE`,
|
||||
`BINDING_MISSING`, `BINDING_TOMBSTONED`, `NEEDLE_MISSING`, `CONTENT_MISMATCH`,
|
||||
`SIZE_MISMATCH`, `FORK_RECORD_MISMATCH`, `INTENT_STALE`, `READ_ERROR`.
|
||||
|
||||
`NEEDLE_MISSING` means the blob store answered that the needle does not exist
|
||||
(for SeaweedFS: HTTP 404 from every location of a fresh volume lookup; when the
|
||||
cached locations all answer 404, the volume is looked up again, since it may
|
||||
have moved). Any other read failure, such as a
|
||||
timeout, a refused or reset connection, or another HTTP status, is retried twice
|
||||
with a short backoff. If it still fails, the chunk or segment is reported as
|
||||
`READ_ERROR`, with the error in the detail. `READ_ERROR` is not evidence of
|
||||
damage: it means that object was **not verified**. Re-run verify, after fixing
|
||||
the store's reachability if needed. The summary counts these objects separately
|
||||
in `chunksNotRead`, and `readRetries` counts the retried reads. The rule below
|
||||
applies to `READ_ERROR` as to any other bad outcome.
|
||||
|
||||
### Running beside a live owner and beside GC
|
||||
|
||||
Segments and chunks are immutable and written before the root that names them,
|
||||
so a root read once and the segments it names are a consistent view. But nothing
|
||||
registers a reader with GC: a chunk that leaves a root can be collected once
|
||||
GC's grace has passed, and a long pass can outlive that. So verify checks each
|
||||
chunk once, records its outcome, and computes the findings only at the end, from
|
||||
those outcomes and the roots at its final read:
|
||||
|
||||
- HEAD is read again at least every 2 minutes during a long pass (a newer
|
||||
generation replaces the view; only segments whose key changed are read again;
|
||||
chunks it names that the pass has not seen are added and checked).
|
||||
- When every chunk is checked, verify reads HEAD and each checked snapshot's state
|
||||
once more. If that read names a chunk not seen, verify checks it and reads
|
||||
again, at most 3 times; the read that names nothing new is the final read, and
|
||||
no read follows it. Only a HEAD that decodes can be part of it: if that read
|
||||
finds no HEAD, or one that does not decode, the final view has no HEAD root and
|
||||
the pass is incomplete.
|
||||
- Chunks and segments alike are read once per key, whatever reference names them,
|
||||
and keep that one outcome: the content (a segment keeps its bytes), or binding
|
||||
missing or tombstoned, needle missing, or a read error.
|
||||
- At the end, each reference is judged against that one outcome, the same way
|
||||
whatever the order the pass met them in: a bad outcome stays that outcome; a
|
||||
reference with another hash is a `CONTENT_MISMATCH`; a chunk that matches its
|
||||
reference but is not a chunk long is a `SIZE_MISMATCH`; a segment that does not
|
||||
decode under that reference's own fields is `SEGMENT_UNREADABLE`; else it is
|
||||
sound (and a sound segment reference gives that root its chunks).
|
||||
- For each object and class a reference of the final read has, there is one
|
||||
finding, under the first root having such a reference (HEAD, then the snapshots
|
||||
still active, in order), at its first such index.
|
||||
- A chunk or segment that had a problem under any reference the pass saw (or a bad
|
||||
outcome) but has no finding, because no reference of the final read has one, is
|
||||
counted once: in `rootDeletedDuringVerify` when a checked snapshot that was
|
||||
deleted during the pass carried a problem reference, otherwise in
|
||||
`supersededDuringVerify`. This includes an object still named, but only by sound
|
||||
references. Deleted snapshots are listed in `snapshotsDeletedDuringVerify` as not
|
||||
fully covered. The counters do not make a pass unclean.
|
||||
- A key that an earlier HEAD read named, a later one did not, and the final HEAD
|
||||
names again is a `ROOT_INVALID` finding ("HEAD names a key it had dropped"),
|
||||
whatever its chunk's state: a key that left every root may have been collected,
|
||||
and must not come back.
|
||||
|
||||
A finding describes each chunk as it was when checked, for the roots at the final
|
||||
read; a chunk damaged after its check is the next pass's finding.
|
||||
|
||||
A pass that cannot finish is **incomplete**, never clean: `complete` is false and
|
||||
`incomplete` gives the reason: `deadline`, `cancelled`, `error` (a filer or blob
|
||||
store failure, a refused request, or a final read that returned an older HEAD),
|
||||
`closing_rounds_exhausted` (each of the 3 final reads named new chunks: the volume
|
||||
is too busy; re-run), `head_absent` (the final read found no HEAD) or
|
||||
`head_invalid` (the final read's HEAD does not decode; also a `ROOT_INVALID`
|
||||
finding). Its findings are those computed from the chunks it did check, for the
|
||||
roots of its last view (none for HEAD in the last two cases).
|
||||
|
||||
### What verify cannot check
|
||||
|
||||
- Orphan needles: a needle uploaded whose binding was never written cannot be
|
||||
enumerated.
|
||||
- Which block inside a chunk is bad: there is one SHA-256 per chunk.
|
||||
- A data chunk's size without reading it: bindings and references store no size.
|
||||
- The HEAD root against an independent value: no checksum of the root is stored.
|
||||
- Whether the image equals the volume's content at its remote LSN: only the
|
||||
holder's local volume could say.
|
||||
- Past HEAD generations, forced-move lost ranges (kept outside the filer), and
|
||||
any verification history (nothing records it).
|
||||
- Each replica of a needle: a read stops at the first replica that answers.
|
||||
|
||||
### Exit codes
|
||||
|
||||
- `0`: the pass completed with no finding.
|
||||
- `3`: the pass completed with findings. This includes `READ_ERROR`: the pass
|
||||
did not verify everything.
|
||||
- `1`: the pass could not complete (the deadline passed, the filer failed, HEAD
|
||||
kept naming new chunks, HEAD was gone or did not decode at the final read, or
|
||||
the volume or snapshot does not exist). The error body
|
||||
`{code,message,retryable}` is printed with the partial result, and its
|
||||
`incomplete` reason, under `verify`. A single-filer start check that cannot
|
||||
finish also exits 1 (`remote_unavailable`), before the pass, with no result.
|
||||
- `2`: usage error, or the filer is not the only one of its group (`bad_request`,
|
||||
before the pass, with no result).
|
||||
@@ -871,7 +871,7 @@ Notes:
|
||||
|
||||
Notes:
|
||||
|
||||
- `INV-WS-SINGLE-FILER-001`: the same census runs in every `sw-block ops chunk` command that writes chunk metadata (snapshot-delete, fork, retain, volume-delete, gc --apply), and in verify, which writes nothing but would report false findings against a split filer view, before it reads or writes; other read-only commands and modes do not run it.
|
||||
- `INV-WS-SINGLE-FILER-001`: the same census runs in every `sw-block ops chunk` command that writes chunk metadata (snapshot-delete, retain, volume-delete), and in verify, which writes nothing but would report false findings against a split filer view, before it reads or writes; other read-only commands and modes do not run it.
|
||||
- `INV-WS-HEAD-CAS-001`: The integration test needs build tag `chunkstore_integration` and a pinned `weed` binary.
|
||||
- `INV-WS-CAS-UNKNOWN-001`: An unknown-outcome CAS is not in the TLA+ models (`docs/spec/README.md`, Limits).
|
||||
- `INV-WS-HEAD-KEY-PROVENANCE-001`: No test asserts it yet in this change. The legacy verifier that observed a key HEAD named, dropped and named again is removed; on the content-named layout a name is its content, so the case does not arise there.
|
||||
|
||||
@@ -924,6 +924,9 @@ A restore makes a new volume from a snapshot. The new volume reads every chunk i
|
||||
|
||||
#### Lifetime of a restore target
|
||||
|
||||
- **v2 never becomes independent of the source snapshot**, not even after its whole device has been read: the
|
||||
snapshot stays pinned while v2 exists and counts toward the source's limit of 10 snapshots, and the source volume
|
||||
cannot be deleted before v2. Making a restored volume independent is planned for v1.1.0.
|
||||
- **The source snapshot cannot be deleted** while v2 exists: `ops chunk snapshot-delete` is refused with `snapshot_has_dependents`. Delete v2 first (see [Delete a volume](volume-lifecycle.md#delete-a-volume)); the snapshot can be deleted after that.
|
||||
- **A snapshot of v2 cannot be restored:** it names the source's chunks. The restore exits 1 with `"code":"restore_source_not_own"` (from the master's typed reason, not its text) and a message ending in `snapshot names another volume's chunks: "<snapshot>"`. The refused restore changes nothing: the target name stays free, and a restore from the source's own snapshot may use it.
|
||||
- **v2's own writes stay in v2:** the source's snapshot never changes.
|
||||
|
||||
Reference in new issue
Block a user