fix: isolate permanent GC DELETE refusals without losing coverage

This commit is contained in:
pingqiu committed 2026-11-20 20:35:19 -08:00
1 parent a3a3bc0a23
commit b9c11477b7
10 files changed
+91 -11

No files matched your search

@@ -208,7 +208,7 @@ func TestIntegration_OpsChunkGC_RealMasterAndStore(t *testing.T) {
if !first.MarkSaved || first.Reclaimed != 0 {
t.Fatalf("first mark: %+v", first)
}
now = now.Add(time.Hour + time.Second)
now = now.Add(time.Hour + chunkstore.DefaultGCClockSkew + time.Second)
preview = call(false)
if preview.Reclaimed != 0 || len(preview.WouldDelete) != 1 || preview.WouldDelete[0].Key != "orphan" {
t.Fatalf("mature preview: %+v", preview)
@@ -278,7 +278,7 @@ func TestIntegration_OpsChunkGC_RealMasterAndStore(t *testing.T) {
if expired.ExpiredIntents != 1 || expired.Reclaimed != 0 {
t.Fatalf("fenced intent admission: %+v", expired)
}
now = now.Add(time.Hour + time.Second)
now = now.Add(time.Hour + chunkstore.DefaultGCClockSkew + time.Second)
reclaimed := call(true)
if reclaimed.Reclaimed != 1 || len(reclaimed.WouldDelete) != 1 || reclaimed.WouldDelete[0].Key != "held" {
t.Fatalf("expired capture: %+v", reclaimed)
@@ -1,6 +1,7 @@
package main
import (
"bytes"
"context"
"encoding/json"
"errors"
@@ -264,3 +265,20 @@ func TestOpsChunkGC_FailedMarkLookupPreservesUnknownUnbound(t *testing.T) {
})
}
}
func TestOpsChunkGC_PermanentDeleteReportsFailureWithSavedCoverage(t *testing.T) {
var stdout, stderr bytes.Buffer
out := chunkstore.GCExecution{MarkOutcome: "complete", MarkSaved: true, GCResult: chunkstore.GCResult{
Reclaimed: 1, FailedDeletes: []chunkstore.GCDeleteFailure{{GCObject: chunkstore.GCObject{Volume: "v1", Key: "bad", FID: "3,bad"}, Error: "http 400"}},
}}
rc := chunkGCResult(out, chunkstore.ErrBlobDeleteRejected, &stdout, &stderr)
var body struct {
GC chunkstore.GCExecution `json:"gc"`
}
if err := json.Unmarshal(stdout.Bytes(), &body); err != nil {
t.Fatal(err)
}
if rc != 1 || !body.GC.MarkSaved || body.GC.MarkOutcome != "complete" || body.GC.Reclaimed != 1 || len(body.GC.FailedDeletes) != 1 || body.GC.FailedDeletes[0].FID != "3,bad" {
t.Fatalf("partial failure lost saved coverage or object identity: rc=%d body=%s", rc, stdout.String())
}
}
+28 -4
View File
@@ -19,6 +19,10 @@ import (
const extGCDeleted = "swb.gc.deleted"
// ErrBlobDeleteRejected identifies a definite per-object refusal (HTTP400).
// It never proves the needle absent; GC retains its tombstone and reports it.
var ErrBlobDeleteRejected = errors.New("chunkstore: blob DELETE rejected")
// DefaultGCClockSkew is the allowed pairwise difference between timestamp
// writers and collectors. Deployments with a larger bound must raise ClockSkew;
// no finite time-based grace can be safe with unbounded clock differences.
@@ -55,10 +59,16 @@ type GCObject struct {
Key string `json:"key"`
FID string `json:"fid"`
}
type GCDeleteFailure struct {
GCObject
Error string `json:"error"`
}
type GCResult struct {
Roots []GCRoot `json:"roots"`
WouldDelete []GCObject `json:"would_delete"`
WouldExpireIntents []string `json:"would_expire_intents"`
FailedDeletes []GCDeleteFailure `json:"failed_deletes"`
Roots []GCRoot `json:"roots"`
WouldDelete []GCObject `json:"would_delete"`
WouldExpireIntents []string `json:"would_expire_intents"`
Volumes, Intents, ExpiredIntents, Candidates, Reclaimed int
// Pre-binding needles cannot be enumerated by this API. They are retained;
// UnknownUnbound is true rather than inventing a report-only count.
@@ -127,6 +137,7 @@ func (g *Collector) run(ctx context.Context, apply bool) (result GCResult, err e
result.Roots = []GCRoot{}
result.WouldDelete = []GCObject{}
result.WouldExpireIntents = []string{}
result.FailedDeletes = []GCDeleteFailure{}
defer func() {
if err != nil && apply {
g.candidates = map[string]gcCandidate{}
@@ -371,7 +382,20 @@ func (g *Collector) run(ctx context.Context, apply bool) (result GCResult, err e
}
}
if err = g.blobs.DeleteBlob(ctx, string(b.entry.Extended[extFid])); err != nil {
return result, err
if ctx.Err() != nil {
return result, ctx.Err()
}
if !errors.Is(err, ErrBlobDeleteRejected) {
return result, err
}
// INV-GC-DELETE-PROGRESS-001: a confirmed object rejection
// must not starve later candidates or invalidate a complete mark.
// Keep the fid/tombstone and retry; never record this object done.
result.FailedDeletes = append(result.FailedDeletes, GCDeleteFailure{
GCObject: GCObject{Volume: b.volume, Key: mustUnescapeGCKey(b.entry.Name), FID: string(b.entry.Extended[extFid])}, Error: err.Error(),
})
nextCandidates[p] = candidate
continue
}
e := proto.Clone(b.entry).(*filerpb.Entry)
e.Extended[extGCDeleted] = []byte("done")
@@ -2,6 +2,7 @@ package chunkstore
import (
"context"
"errors"
"net/http"
"net/http/httptest"
"path"
@@ -56,7 +57,10 @@ func TestGCPermanentDeleteDoesNotStarveLaterBindings(t *testing.T) {
if out.Reclaimed != 1 {
t.Fatalf("permanent DELETE starved later binding: %+v err=%v", out, err)
}
if err != nil || !out.MarkSaved {
if len(out.FailedDeletes) != 1 || out.FailedDeletes[0].FID != badFID || out.FailedDeletes[0].Key != "a_bad" || out.FailedDeletes[0].Volume != "v1" || !strings.Contains(out.FailedDeletes[0].Error, "http 400") {
t.Fatalf("object refusal missing from result: %+v", out)
}
if !errors.Is(err, ErrBlobDeleteRejected) || !out.MarkSaved {
t.Fatalf("partial deletion must retain complete mark coverage: %+v %v", out, err)
}
badEntry, err := f.LookupEntry(ctx, path.Join(catBase, "v1", keysDir), "a_bad")
@@ -74,7 +78,7 @@ func TestGCPermanentDeleteDoesNotStarveLaterBindings(t *testing.T) {
for i := 0; i < 2; i++ {
*now = now.Add(2 * time.Hour)
out, err = c.ExecuteVolumeGC(ctx, "v1", deleter, g.cfg, true)
if err != nil || !out.MarkSaved {
if (err != nil && !errors.Is(err, ErrBlobDeleteRejected)) || !out.MarkSaved || ((len(out.FailedDeletes) > 0) != errors.Is(err, ErrBlobDeleteRejected)) {
t.Fatalf("repeated rejection stalled coverage: %+v %v", out, err)
}
if i == 1 && out.Reclaimed != 1 {
@@ -121,6 +121,12 @@ func (c *Catalog) executeGC(ctx context.Context, blobs BlobDeleter, cfg GCConfig
}
out.MarkOutcome = "complete"
out.MarkSaved = true
if len(out.FailedDeletes) != 0 {
// The mark completed and is reusable even though these tombstoned
// objects remain. Report partial failure after persisting coverage,
// so CLI/maintenance callers cannot mistake it for full reclamation.
return out, fmt.Errorf("%w: %d objects retained; complete GC mark saved", ErrBlobDeleteRejected, len(out.FailedDeletes))
}
return out, nil
}
@@ -339,7 +339,7 @@ func TestGC_CopyIntentSurvivesTakeover(t *testing.T) {
}
func TestSWFS_DeleteBlobStatusesAndExactPath(t *testing.T) {
for _, status := range []int{200, 202, 204, 404, 401, 500} {
for _, status := range []int{200, 202, 204, 404, 400, 401, 500} {
t.Run(http.StatusText(status), func(t *testing.T) {
calls := 0
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -355,6 +355,9 @@ func TestSWFS_DeleteBlobStatusesAndExactPath(t *testing.T) {
if (e == nil) != (status == 200 || status == 202 || status == 204 || status == 404) {
t.Fatalf("status %d: %v", status, e)
}
if errors.Is(e, ErrBlobDeleteRejected) != (status == 400) {
t.Fatalf("wrong per-object refusal classification: status=%d err=%v", status, e)
}
if calls != 1 {
t.Fatalf("calls %d", calls)
}
@@ -317,6 +317,9 @@ func (c *SWFS) DeleteBlob(ctx context.Context, fid string) error {
return err
}
resp.Body.Close()
if resp.StatusCode == http.StatusBadRequest {
return fmt.Errorf("%w: delete %s: http %d", ErrBlobDeleteRejected, fid, resp.StatusCode)
}
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusNotFound {
return fmt.Errorf("chunkstore: delete %s: http %d", fid, resp.StatusCode)
}
+5 -1
View File
@@ -300,6 +300,7 @@ HEAD states, snapshots, forks, intents, key bindings, GC and volume delete in th
| intent live | expired | conservative elapsed age exceeds the TTL after pairwise clock skew, blockmaster has issued a higher epoch, and remote HEAD has a higher epoch | `core/frontend/chunkstore/gc.go` `Collector.run` | `INV-GC-INTENT-EXPIRY-001`, `INV-GC-CLOCK-SKEW-001` |
| — | bound | exclusive create of the key; a key that exists or once existed is refused | `core/frontend/chunkstore/chunk_remote.go` `putObject` | `INV-CHUNK-WRITE-ONCE-001` |
| bound | tombstoned, needle deleted | unrooted in two complete marks separated by more than grace plus clock skew, binding age exceeds grace plus skew plus one-second timestamp precision, binding unchanged; an unreadable segment aborts the pass; the collector requires grace greater than the operation deadline | `core/frontend/chunkstore/gc.go` `Collector.run`, `NewCollector` | `INV-GC-REACHABLE-001`, `INV-GC-UNREADABLE-SEGMENT-001`, `INV-GC-GRACE-DEADLINE-001`, `INV-GC-CLOCK-SKEW-001` |
| tombstoned, DELETE rejected | tombstoned, retry later; continue other bindings | definite HTTP400 is reported per object; no success recorded for the rejected fid; complete mark coverage is saved before returning partial failure; cancellation, unknown/other DELETE errors and metadata errors still stop the pass | `core/frontend/chunkstore/gc.go` `Collector.run`; `gc_execution.go` `executeGC`; `swfs.go` `DeleteBlob` | `INV-GC-DELETE-PROGRESS-001` |
| tombstoned | (never rebound) | bindings are never removed | `core/frontend/chunkstore/chunk_remote.go` `putObject` | `INV-CHUNK-WRITE-ONCE-001` |
GC clock admission (`INV-GC-CLOCK-SKEW-001`):
@@ -310,6 +311,8 @@ flowchart LR
age --> young[Not past grace: retain root or candidate]
age --> old[Past grace: existing authority and complete-mark guards]
future[Future or backward mark clock] --> reset[Discard elapsed coverage and start a fresh mark]
old --> reject[HTTP400: retain tombstone and report failure]
reject --> later[Continue later bindings and save complete mark]
```
@@ -373,7 +376,7 @@ with a separate scope/config-bound mark. Incomplete marks carry no coverage.
## Part B. Invariant ledger
125 rows: 106 ACTIVE, 17 STUB, 2 ARCHIVED; 15 kept from the internal ledger, 110 new.
126 rows: 107 ACTIVE, 17 STUB, 2 ARCHIVED; 15 kept from the internal ledger, 111 new.
The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger.
@@ -551,6 +554,7 @@ Notes:
| `INV-GC-REACHABLE-001` | GC never deletes a chunk reachable from a HEAD, a snapshot, an attempt or a live intent, and deletes a binding only after two marks at least one grace period apart. | M6 key: Bound → Tombstoned | `core/frontend/chunkstore/gc.go` `Collector.run` | `TestGC_UnreachableRequiresTwoMarksAndUploadAge`, `TestGC_StalledCutRemainsReadableAfterTwoMarks`, `TestGC_SnapshotAndQualifiedForkAreRoots` (`core/frontend/chunkstore/gc_test.go`) | `ChunkLifecycleFixed` `GCSafe`; `RetentionGCTiming` `NoLiveDelete` | ACTIVE |
| `INV-GC-INTENT-EXPIRY-001` | A capture intent expires only when it is older than the TTL, blockmaster has issued a higher epoch, and remote HEAD has moved to a higher epoch. | M6 intent: Live → Expired | `core/frontend/chunkstore/gc.go` `Collector.run` | `TestGC_IntentExpiryNeedsTTLAuthorityAndRemoteFence` (`core/frontend/chunkstore/gc_test.go`) | `WorkspaceTakeover` `NoLiveIntentExpired`, `GCSafe` | ACTIVE |
| `INV-GC-UNREADABLE-SEGMENT-001` | An unreadable published segment aborts the whole GC pass before any deletion. | M6 GC mark | `core/frontend/chunkstore/gc.go` `Collector.run` | `TestManifest_UnreadablePublishedSegmentRefusesWholeGC` (`core/frontend/chunkstore/manifest_test.go`) | — | ACTIVE |
| `INV-GC-DELETE-PROGRESS-001` | A definite HTTP400 DELETE refusal cannot starve later eligible bindings or erase younger candidates' completed-mark coverage. The rejected fid stays in its immutable tombstone, is retried later and is never counted reclaimed. FailedDeletes reports the object; ExecuteGC saves the complete mark before returning partial failure. Other/unknown errors and cancellation remain pass failures. | M6 bound/tombstoned → physical reclamation | `core/frontend/chunkstore/gc.go` `run`; `gc_execution.go` `executeGC`; `swfs.go` `DeleteBlob` | `TestGCPermanentDeleteDoesNotStarveLaterBindings`, `TestSWFS_DeleteBlobStatusesAndExactPath` | `GCDeleteProgress` `NoFalseSuccess`, `FailureVisible`, `LaterProgress` | ACTIVE |
| `INV-GC-CLOCK-SKEW-001` | Time-based GC eligibility subtracts configured pairwise clock skew (default one minute), plus one second for binding timestamps. Future valid intent/deletion stamps retain roots without blocking unrelated work. Future/backward or differently configured marks supply no elapsed coverage; malformed marks still refuse. This assumes clocks stay within the configured pairwise bound. | M6 intent expiry, deleting snapshot roots, bound → tombstoned | `core/frontend/chunkstore/gc.go` `oldEnough`, `run`; `gc_copy.go` `SweepCopies`, `snapshotAttemptHeads`; `gc_execution.go` `readMark`, `executeGC` | `TestGCSkewSnapshotDeleteGraceBothDirections`, `TestGCSkewIntentExpiryUsesConservativeAge`, `TestGCSkewFutureIntentKeepsRootsWithoutBlockingProgress`, `TestGCSkewPersistedCoverageAcrossHosts`, `TestGCSkewBindingAgeIncludesSecondResolution`, `TestGCSkewConfigAndMarkCoverage`, `TestGCSkewBackwardStepDiscardsCoverageAndPreviewDoesNotMutate`, `TestGCSkewFutureCopyDoesNotBlockOtherSettlement` (`core/frontend/chunkstore/gc_clock_skew_test.go`) | `GCClockSkew` `NoEarlyExpiry`, `FutureProtects`, `IndependentProgress`, `EventuallyEligibleAtBound` | ACTIVE |
| `INV-GC-GRACE-DEADLINE-001` | A GC collector cannot be built unless its grace period exceeds the catalog operation deadline. | M6 GC configuration | `core/frontend/chunkstore/gc.go` `NewCollector` | `TestGC_GraceConstructorRejectsCopyDeadline` | `RetentionGCTiming` `NoLiveDelete` | ACTIVE |
| `INV-SNAP-EXPLICIT-DELETE-001` | A published snapshot is removed only by `DeleteSnapshot` or retention for its own attempt, and never while a fork claim on it is live. | M6 snapshot: Published → Deleting | `core/frontend/chunkstore/catalog.go` `DeleteSnapshot`; `core/frontend/chunkstore/retention.go` `markDeleting` | `TestCatalog_DeleteMarksThenIdempotent` (`core/frontend/chunkstore/catalog_test.go`); `TestCatalog_ClaimBetweenCheckAndMarkWins` (`core/frontend/chunkstore/retention_review_test.go`) | `ChunkLifecycleFixed` `SnapOnlyExplicitDelete` | ACTIVE |
+1 -1
View File
@@ -16,7 +16,7 @@ Step == /\ next \in Keys
/\ deleted' = deleted \cup {next}
/\ rejected' = rejected
/\ next' = next+1
/\ complete' = next = 3
/\ complete' = (next = 3)
Spec == Init /\ [][Step]_vars
NoFalseSuccess == Bad \notin deleted
FailureVisible == complete => Bad \in rejected
+18
View File
@@ -475,3 +475,21 @@ queue empty, depth16. `GCClockSkew_no_skew.cfg` exited12 at `NoEarlyExpiry`
(44/44, depth8); `GCClockSkew_abort_future.cfg` exited12 at
`IndependentProgress` (11/11, depth2). Source tests independently cover
persisted-mark compatibility, future-clock resets and authority-preserving expiry.
## Per-object GC DELETE progress
`GCDeleteProgress.tla` models the narrow sweep transition after a complete,
authorised mark: three ordered candidates, first DELETE definitively rejected,
later deletes accepted. It checks that the rejected fid is never reported
successful, the failure is visible, and later candidates progress. Root/epoch
admission, elapsed coverage and persistence are outside this small abstraction;
source tests retain those guards and reopen independent collectors between passes.
Local TLC2.19 / Java21, same jar SHA256 as GCClockSkew above, 2026-11-21:
`java -Xmx512m -cp <jar> tlc2.TLC -config GCDeleteProgress_safe.cfg GCDeleteProgress`
from `docs/spec`, separate metadirs. Positive exhausted exit0, 4 generated /4
distinct states, depth4. `GCDeleteProgress_stop.cfg` exits12 at `LaterProgress`
(2 generated /2 distinct, depth2). The HTTP source red uses an actual400 and
checks later reclamation, retained failed tombstones, younger-object progress
across separate collectors and permanent no-rebind behavior.