diff --git a/seaweed-block/core/host/master/retirement_worker_test.go b/seaweed-block/core/host/master/retirement_worker_test.go index 8527c88dde..1898c3964f 100644 --- a/seaweed-block/core/host/master/retirement_worker_test.go +++ b/seaweed-block/core/host/master/retirement_worker_test.go @@ -166,3 +166,40 @@ func TestRetirementWorkerServingWithOneHundredSlowHeads(t *testing.T) { }) } } + +func TestRetirementPassReportsOnlyPendingRecords(t *testing.T) { + original, _ := retirementScanHost(t, "kept") + cfg := original.cfg + closeTestMaster(t, original) + logs := &syncBuffer{} + cfg.Logger = log.New(logs, "", 0) + h, err := New(cfg) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { closeTestMaster(t, h) }) + if _, err := h.Lifecycle().Volumes.CreateVolume(lifecycle.VolumeSpec{VolumeID: "live", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { + t.Fatal(err) + } + if err := h.PruneUnusedSpecPlacements(t.Context(), []string{"kept", "live"}); err != nil { + t.Fatal(err) + } + h.Start() // no reader yet, so no worker: this test drives the passes + h.cfg.LayoutReadHead = func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) { + return layout.Head{State: layout.StateDeleted}, nil + } + pass := func() int { + if err := h.reconcileDeletedSpecVolumes(t.Context(), true, time.Now()); err != nil { + t.Fatal(err) + } + return strings.Count(logs.String(), "deletion retirement pass") + } + if got := pass(); got != 2 || !strings.Contains(logs.String(), "eligible=1 reads=1") { + t.Fatalf("pending pass lines=%d, want start and end with counters:\n%s", got, logs.String()) + } + for i := 0; i < 3; i++ { + if got := pass(); got != 2 { + t.Fatalf("idle pass %d logged; pass lines=%d:\n%s", i, got, logs.String()) + } + } +} diff --git a/seaweed-block/core/host/master/spec_retirement.go b/seaweed-block/core/host/master/spec_retirement.go index addd3939e8..8e8afbaa58 100644 --- a/seaweed-block/core/host/master/spec_retirement.go +++ b/seaweed-block/core/host/master/spec_retirement.go @@ -83,14 +83,6 @@ func (h *Host) reconcileDeletedSpecVolumes(ctx context.Context, paced bool, now h.log.Printf("blockmaster: deletion retirement skipped volume=%q reason=%s error=%v", id, reason, err) } } - if h.log != nil { - h.log.Printf("blockmaster: deletion retirement pass start=%s", started.UTC().Format(time.RFC3339Nano)) - } - defer func() { - if h.log != nil { - h.log.Printf("blockmaster: deletion retirement pass start=%s end=%s eligible=%d reads=%d timeouts=%d retired=%d skips=%v", started.UTC().Format(time.RFC3339Nano), time.Now().UTC().Format(time.RFC3339Nano), eligible, reads, timeouts, retired, reasons) - } - }() records := stores.Volumes.ListVolumes() if h.retirementNext == nil { h.retirementNext = map[string]time.Time{} @@ -119,6 +111,13 @@ func (h *Host) reconcileDeletedSpecVolumes(ctx context.Context, paced bool, now eligible++ } } + // An idle inventory stays silent; a pass with pending records reports. + if h.log != nil && eligible > 0 { + h.log.Printf("blockmaster: deletion retirement pass start=%s", started.UTC().Format(time.RFC3339Nano)) + defer func() { + h.log.Printf("blockmaster: deletion retirement pass start=%s end=%s eligible=%d reads=%d timeouts=%d retired=%d skips=%v", started.UTC().Format(time.RFC3339Nano), time.Now().UTC().Format(time.RFC3339Nano), eligible, reads, timeouts, retired, reasons) + }() + } // Volume records are sorted; the cursor is constant-size and wraps. start := sort.Search(len(records), func(i int) bool { return records[i].Spec.VolumeID > h.retirementAfter }) for i := 0; i < len(records); i++ { diff --git a/seaweed-block/core/lifecycle/layout_identity_guard_test.go b/seaweed-block/core/lifecycle/layout_identity_guard_test.go index ccdd7cffdb..1a4884159a 100644 --- a/seaweed-block/core/lifecycle/layout_identity_guard_test.go +++ b/seaweed-block/core/lifecycle/layout_identity_guard_test.go @@ -32,11 +32,6 @@ func TestLayoutIdentityWriterAndReaders(t *testing.T) { "core/host/master/services.go CreateVolume": true, "core/host/master/services.go createLifecycleVolume": true, "core/host/master/workspace_layout_head.go WorkspaceLayoutVolume": true, - // Logs the existing record's immutable LayoutID only when a fresh - // post-lease HEAD read fails; never mints or changes the identity. - // TestSpecRetirementBackgroundBoundsReadsAndCachesTerminalProof - // covers the deferred read, and the fresh-Host witness pins its record. - "core/host/master/spec_retirement.go reconcileDeletedSpecVolumes": true, "core/launcher/k8s_renderer.go blockVolumeArgs": true, "core/launcher/k8s_renderer.go durableRoot": true, "cmd/blockvolume/main.go runVolume": true, diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index d43c936ff4..bb96c24acc 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -146,7 +146,7 @@ flowchart LR | Bound | Deleting | a deletion reservation; the id is never created again | `core/host/master/services.go` `MarkVolumeDeleting` | `INV-VOL-ID-NO-REUSE-001` | | any authority line | DeleteReserved (permanent) | the existing lifecycle reservation is committed durably; then `mu -> leaseMu` publishes the exclusion. Publication, move issue, first grant, expired re-grant and renewal check it under their writer lock. Restart reloads every committed exclusion before serving. Deleting HEAD requires the granted or restart deadline plus skew to have ended, including unclaimed grants; the check returns a refusal rather than waiting | `core/authority/workspace_delete_reservation.go` `ReserveWorkspaceDeletion`, `NoLiveWorkspaceLease`; `core/host/master/volume_delete_authority.go`; `host.go` `New` | `INV-SNAPK-DELETE-GATE-001` | | any authority line, stores still awaited (stage 1) | DeleteReserved without the holder's acknowledgement | the master's record is marked first, durably and in the lock that ends the store wait; the mark freezes the record in stage 1 (the wait never ends after it, so the primary, whose assignment keeps awaiting the stores, never serves); the reservation then skips the live-lease refusal. Deleting HEAD waits out the lease as above. Past stage 1, also while the end of creation is unrecorded (the volume may be serving), the live-lease refusal stays | `core/host/master/volume_delete_authority.go` `Reserve`; `core/host/master/store_attestation.go` `markDeleteWithoutAck`, `awaited`; `core/authority/workspace_delete_reservation.go` `ReserveNeverCreatedWorkspaceDeletion` | `INV-WS-DELETE-WITHOUT-ACK-001` | -| DeleteReserved, removed from the desired spec | Retired metadata (reservation permanent) | no live lease, then a fresh bounded HEAD read proves deleted or absent; unread/live/deleting keeps the records. Remove authority durably, then placement and bindings, then the volume record; a crash retries the remaining removals. One host-owned paced worker retries after lease barriers and read failures, also without the product loop; serving and product ticks perform none of this scan's remote reads. Each pass reports start/end, eligible records, reads, timeouts, retirements and skip reasons. The store and its resweep inputs are untouched | `core/host/master/spec_retirement.go` `reconcileDeletedSpecVolumes`, `startRetirementWorker`; `core/authority/workspace_retirement.go` `RetireDeletedWorkspace` | `INV-SPEC-DELETE-RETIRE-001`, `INV-SPEC-DELETE-RETRY-001` | +| DeleteReserved, removed from the desired spec | Retired metadata (reservation permanent) | no live lease, then a fresh bounded HEAD read proves deleted or absent; unread/live/deleting keeps the records. Remove authority durably, then placement and bindings, then the volume record; a crash retries the remaining removals. One host-owned paced worker retries after lease barriers and read failures, also without the product loop; serving and product ticks perform none of this scan's remote reads. A pass with pending eligible records reports start/end, eligible records, reads, timeouts, retirements and skip reasons; an idle pass logs nothing. One inventory snapshot per pass, a fair cursor and a freshness-window delay W between passes bound the next eligible visit by two passes plus W (at most 2 E x 5 s + W of remote reads and timers for E pending records, plus local processing). The store and its resweep inputs are untouched | `core/host/master/spec_retirement.go` `reconcileDeletedSpecVolumes`, `startRetirementWorker`; `core/authority/workspace_retirement.go` `RetireDeletedWorkspace` | `INV-SPEC-DELETE-RETIRE-001`, `INV-SPEC-DELETE-RETRY-001` | **Volume creation phase, in blockmaster's store record** (`core/host/master/store_attestation.go`, decided by `inCreationPhase` in `core/host/master/product_loop.go`). Every replacement entry (both promotion gates, the operator's failover and planned move, the rebalance) acts only on Established. @@ -1209,7 +1209,7 @@ Notes: | `INV-CUT-TIMER-SLOT-WAIT-001` | A periodic cut refused for held host slots, pending urgent work or an earlier ticket is a wait, not a failure: no backoff or minimum spacing; it retries at the next poll in ticket order, and status reports the wait until any later cut succeeds. Other errors keep the backoff. | M5 periodic trigger (before Admit) | `core/frontend/durable/provider_chunk.go` `cutPolicy.after`, `chunkLoop`; `core/hostlimit/limiter.go` `ErrSlotsHeld` | `TestCutPolicy_HostSlotBusyIsAWaitNotAFailure`, `TestCutPolicy_SuccessDuringSlotWaitEndsTheWait`, `TestCutWaitSlot_StatusEndsTheWaitAfterALaterCut`, `TestCutPolicy_TicketOrderWaitBound` (`core/frontend/durable/cut_policy_test.go`); `TestTimerCutRunsSoonAfterHostSlotFrees`, `TestSlotWaitEndsWithASuccessfulDetachSeal` (`core/frontend/durable/host_slot_wait_test.go`); `TestAdmitClosedDuringPoolAcquisitionIsRevoked` (`core/hostlimit/limiter_test.go`) | — | ACTIVE | | `INV-SNAPSHOT-ANSWER-COUNT-001` | Newly produced snapshot creation and listing answers omit the uncomputed chunk count; no manifest scan is added to answer a snapshot. | M9 snapshot answer projection (no transition change) | `core/frontend/chunkstore/control_types.go`, `api.go`; `core/host/volume/chunk_control.go` | `TestSnapshotAfter200MiBWritesOmitsUncomputedChunkCount` (`core/host/volume/snapshot_chunk_count_test.go`) | NONE (pure projection of the published snapshot; no authority or persisted format change) | STUB | | `INV-SPEC-DELETE-RETIRE-001` | Retire spec-removed metadata only under a permanent reservation after no-live-lease and a subsequent HEAD read proves deleted or absent. Read errors, live HEAD and deleting HEAD keep the records. Retirement never removes the reservation or store data. | M4 delete retirement | `core/host/master/spec_retirement.go`; `core/authority/workspace_retirement.go`, `authority_store_file.go` | `TestSpecRetirementReadsHeadOnlyAfterLeaseAndKeepsTombstone`, `TestSpecRetirementRequiresDeletedOrAbsentAndReadableHead`, `TestSpecRetirementDoesNotUseAbsentHeadWithoutReservation`, `TestRetirementKeepsReservationAndWaitsForLiveLease`, `TestFileAuthorityRetirementSurvivesReloadAndKeepsOtherRecords`, `TestSpecRetirementBackgroundBoundsReadsAndCachesTerminalProof`, `TestSpecRetirementLocalFailureDoesNotStopOtherVolumesOrProductTick` | DeleteRetire.ReadOK; DeleteRetire.Retire; DeleteRetire.HostRetire | STUB | -| `INV-SPEC-DELETE-RETRY-001` | One host-owned paced retirement worker runs independently of the product loop and retries lease skips, failed reads and local removals without a restart. One inventory snapshot per pass, a fair cursor and a freshness-window delay between passes give a next eligible visit within two passes plus that delay (remote-read and timer contribution at most 2 E x 5 s + W for E pending eligible records, plus local processing). Each pass rechecks every lease and HEAD guard and reports start/end, E, reads, timeouts, retirements and skip reasons. Close cancels and joins it before stores close. | M4 delete retirement scheduling | `core/host/master/host.go` `Start`, `Close`; `spec_retirement.go` `startRetirementWorker` | `TestStandaloneRestartRetriesSpecRetirementAfterLeaseFloor`, `TestRetirementWorkerRetriesTimeoutWithoutProductLoopOrRestart`, `TestRetirementWorkerTimerJoinsOnCancellation`, `TestRetirementWorkerServingWithOneHundredSlowHeads` | DeleteRetire r5 (`RetireOnlyWhenUp = TRUE`): ReadOK; RetireLine; RetirePlace; RetireProgress | STUB | +| `INV-SPEC-DELETE-RETRY-001` | One host-owned paced worker, independent of the product loop, retries lease skips, failed reads and local removals without a restart. Every pass rechecks each lease and HEAD guard; Close cancels and joins the worker before stores close. | M4 delete retirement scheduling | `core/host/master/host.go` `Start`, `Close`; `spec_retirement.go` `startRetirementWorker` | `TestStandaloneRestartRetriesSpecRetirementAfterLeaseFloor`, `TestRetirementWorkerRetriesTimeoutWithoutProductLoopOrRestart`, `TestRetirementWorkerTimerJoinsOnCancellation`, `TestRetirementWorkerServingWithOneHundredSlowHeads`, `TestRetirementPassReportsOnlyPendingRecords` | DeleteRetire r5 (`RetireOnlyWhenUp = TRUE`): ReadOK; RetireLine; RetirePlace; RetireProgress | STUB | | `INV-SPEC-UNUSED-PLACEMENT-001` | A spec startup prunes an undesired placement only before serving and with no volume record, authority line, binding or deletion reservation, and no skipped authority recovery. The desired spec and seed are one keep set. | M4 registration input | `cmd/blockmaster/main.go`; `core/host/master/spec_retirement.go` | `TestClusterSpecImportRemovesUnusedPlacementMissingFromSpec`, `TestClusterSpecCleanupKeepsRecordsBindingsAuthorityAndSeed` | NONE (registration-only cleanup before controller activity) | STUB | | `INV-CHECK-DELETING-001` | A post-lease reserved volume with HEAD deleting, deleted or absent holds no serving work. Its status is informational and checks issue no lease or holder requests for it. Another volume's failures remain visible. | M9 delete observation | `core/host/master/observation_snapshot.go`, `journal_isolation.go`; `cmd/sw-block/shell_check.go` | `TestSpecRetirementRequiresDeletedOrAbsentAndReadableHead`, `TestSpecRetirementReadsHeadOnlyAfterLeaseAndKeepsTombstone`, `TestClusterCheckDoesNotProbeDeletingOrDeletedVolumes` | DeleteRetire.HostRetire | STUB | | `INV-CLI-DELETE-RETRY-001` | Only the final lease barrier after a committed volume-delete reservation permits retryable true/exit 75 at its horizon. A live-holder Reserve refusal requires stopping the volume first (not_admitted, non-retryable, exit 1). No lease guard is bypassed. | M9 delete admission result projection | `cmd/sw-block/chunk_volume_delete.go` `authorityErr`; `cmd/sw-block/chunk.go` `chunkResult` | `TestVolumeDeleteAdmissionRetryAnswer`; `TestOpsChunkVolumeDeleteRefusalSaysNothingWasPersisted` | MoveAdmission.DelRead; MoveAdmission.DelMark (unchanged guards) | STUB |