diff --git a/seaweed-block/cmd/blockmaster/layout_create.go b/seaweed-block/cmd/blockmaster/layout_create.go index c3131e2b32..6e9d735425 100644 --- a/seaweed-block/cmd/blockmaster/layout_create.go +++ b/seaweed-block/cmd/blockmaster/layout_create.go @@ -71,3 +71,19 @@ func layoutTargetCreator(cat *chunkstore.BCatalog) func(context.Context, lifecyc return err } } + +// newRetirementHeadReader opens only a read transport. The serving catalog has +// already validated the endpoint; retirement must not repeat its write probes +// or start another probe-cleanup worker. +func newRetirementHeadReader(cfg chunkstore.SWFSConfig) (func(context.Context, lifecycle.VolumeSpec) (layout.Head, error), *chunkstore.SWFS, error) { + client, err := chunkstore.DialSWFS(cfg) + if err != nil { + return nil, nil, err + } + cat, err := chunkstore.NewBCatalog(client, client, cfg.AssignPath) + if err != nil { + _ = client.Close() + return nil, nil, err + } + return layoutHeadReader(cat), client, nil +} diff --git a/seaweed-block/cmd/blockmaster/main.go b/seaweed-block/cmd/blockmaster/main.go index 6e659d75db..1c0c3be253 100644 --- a/seaweed-block/cmd/blockmaster/main.go +++ b/seaweed-block/cmd/blockmaster/main.go @@ -296,8 +296,8 @@ func run(f flags) int { return 1 } cfg.Auth, cfg.ServerOptions = authn, serverOpts - // The layout catalog is the master's one HEAD source (create, restore and - // the workspace reader all read through it). + // Foreground catalog operations share their serving connection. Retirement + // owns a separate connection so outage reads do not alter its backoff. var layoutCat *chunkstore.BCatalog if f.workspaceRPC { cat, client, err := chunkstore.DialBCatalog(context.Background(), chunkstore.SWFSConfig{ @@ -312,6 +312,17 @@ func run(f flags) int { cfg.LayoutCreateVolume = layoutVolumeCreator(cat) cfg.LayoutReadVolume = layoutVolumeReader(cat) cfg.LayoutReadHead = layoutHeadReader(cat) + retirementRead, retirementClient, err := newRetirementHeadReader(chunkstore.SWFSConfig{ + FilerGRPC: f.chunkFiler, Collection: f.chunkCollection, + Replication: f.chunkReplication, AssignPath: f.chunkPath, + }) + if err != nil { + fmt.Fprintln(os.Stderr, "blockmaster: retirement filer:", err) + return 1 + } + // Host.Close cancels and joins retirement before these clients close. + defer retirementClient.Close() + cfg.LayoutRetirementReadHead = retirementRead cfg.LayoutCreateTarget = layoutTargetCreator(cat) layoutCat = cat } diff --git a/seaweed-block/cmd/blockmaster/retirement_transport_test.go b/seaweed-block/cmd/blockmaster/retirement_transport_test.go new file mode 100644 index 0000000000..b99b52d4bc --- /dev/null +++ b/seaweed-block/cmd/blockmaster/retirement_transport_test.go @@ -0,0 +1,86 @@ +package main + +import ( + "context" + "errors" + "net" + "sync" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore" + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb" + "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout" + "github.com/seaweedfs/seaweed-block/core/lifecycle" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/peer" + "google.golang.org/grpc/status" +) + +type retirementTransportFiler struct { + filerpb.UnimplementedSeaweedFilerServer + mu sync.Mutex + peers []string +} + +func (f *retirementTransportFiler) LookupDirectoryEntry(ctx context.Context, _ *filerpb.LookupDirectoryEntryRequest) (*filerpb.LookupDirectoryEntryResponse, error) { + p, _ := peer.FromContext(ctx) + f.mu.Lock() + f.peers = append(f.peers, p.Addr.String()) + f.mu.Unlock() + return nil, status.Error(codes.NotFound, "absent") +} + +// Exercise actual transports: retirement opens a different HTTP/2 connection, +// performs no conditional write probe, and leaves the serving client usable +// after its own connection closes. +func TestRetirementCatalogOwnsItsConnection(t *testing.T) { + lis, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + f := &retirementTransportFiler{} + srv := grpc.NewServer() + filerpb.RegisterSeaweedFilerServer(srv, f) + go srv.Serve(lis) + defer srv.Stop() + cfg := chunkstore.SWFSConfig{FilerGRPC: lis.Addr().String(), AssignPath: "/blocks"} + serving, err := chunkstore.DialSWFS(cfg) + if err != nil { + t.Fatal(err) + } + defer serving.Close() + cat, err := chunkstore.NewBCatalog(serving, serving, cfg.AssignPath) + if err != nil { + t.Fatal(err) + } + retireRead, retireClient, err := newRetirementHeadReader(cfg) + if err != nil { + t.Fatal(err) + } + defer retireClient.Close() + id, err := layout.NewVolumeID() + if err != nil { + t.Fatal(err) + } + spec := lifecycle.VolumeSpec{VolumeID: "v", LayoutID: id.String()} + ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second) + defer cancel() + for _, read := range []func(context.Context, lifecycle.VolumeSpec) (layout.Head, error){layoutHeadReader(cat), retireRead} { + if _, err := read(ctx, spec); !errors.Is(err, layout.ErrHeadAbsent) { + t.Fatalf("read: %v", err) + } + } + if err := retireClient.Close(); err != nil { + t.Fatal(err) + } + if _, err := layoutHeadReader(cat)(ctx, spec); !errors.Is(err, layout.ErrHeadAbsent) { + t.Fatalf("serving read after retirement close: %v", err) + } + f.mu.Lock() + defer f.mu.Unlock() + if len(f.peers) != 3 || f.peers[0] == f.peers[1] || f.peers[0] != f.peers[2] { + t.Fatalf("serving, retirement, serving connections: %v", f.peers) + } +} diff --git a/seaweed-block/cmd/blockvolume/neverstarted_delete_integration_test.go b/seaweed-block/cmd/blockvolume/neverstarted_delete_integration_test.go index 69257bc599..1b92679b0d 100644 --- a/seaweed-block/cmd/blockvolume/neverstarted_delete_integration_test.go +++ b/seaweed-block/cmd/blockvolume/neverstarted_delete_integration_test.go @@ -218,35 +218,8 @@ func (env *handoffEnv) requireNeverStarted(t *testing.T, v string, e, headEpoch // and the process exits. The filer comes back. Line at 1, no lease, HEAD 0. func (env *handoffEnv) strandStoreDown(t *testing.T, v string) { t.Helper() - // A previous arm stopped the filer. Its TCP listener can be back while - // the master's shared catalog channel still backs off after an outage - // read. Resume only the typed retryable refusal, with the same request id; - // an unknown outcome or any other refusal still fails setup immediately. - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() - for { - out, errOut, code, err := runCLI(ctx, env.h, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", v, - "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath, "--request-id", "strand-restore-"+v) - if err != nil { - t.Fatalf("restore %s before stranding: %v", v, err) - } - if code == 0 { - break - } - var refusal struct { - Code string `json:"code"` - Retryable bool `json:"retryable"` - } - if code != 75 || json.Unmarshal([]byte(out), &refusal) != nil || refusal.Code != "remote_unavailable" || !refusal.Retryable { - t.Fatalf("restore %s before stranding: exit %d:\n%s\n%s", v, code, out, errOut) - } - t.Logf("restore %s waits for the master's filer channel to recover: %s", v, out) - select { - case <-ctx.Done(): - t.Fatalf("restore %s before stranding: %v", v, ctx.Err()) - case <-time.After(200 * time.Millisecond): - } - } + env.h.command(t, "ops", "chunk", "restore", "--master", env.h.masterAddr, "--source", "v1", "--snapshot", "s1", "--target", v, + "--chunk-filer", env.cluster.filerGRPC, "--chunk-path", env.chunkPath) env.cluster.stopProc(t, "filer") d := env.h.start(t, "blockvolume-"+v+"-store-down", env.h.volume, env.volArgsFor(env.hosts["n-"+v])...) err := d.wait(120 * time.Second) diff --git a/seaweed-block/core/host/master/host.go b/seaweed-block/core/host/master/host.go index 1a3b016e57..8382fab04a 100644 --- a/seaweed-block/core/host/master/host.go +++ b/seaweed-block/core/host/master/host.go @@ -99,9 +99,13 @@ type Config struct { LayoutCreateVolume func(context.Context, lifecycle.VolumeSpec) error // Restore creation reads the source VOLUME's immutable geometry before // persisting the target, then replays CreateTarget using that record. - LayoutReadVolume func(context.Context, lifecycle.VolumeSpec) (layout.Volume, error) - LayoutReadHead func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) - LayoutCreateTarget func(context.Context, lifecycle.VolumeSpec, lifecycle.VolumeSpec, string) error + LayoutReadVolume func(context.Context, lifecycle.VolumeSpec) (layout.Volume, error) + LayoutReadHead func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) + // LayoutRetirementReadHead uses a separate transport so background outage + // reads cannot change the serving catalog connection's reconnect state. + // Embedded callers may leave it nil to reuse their injected HEAD reader. + LayoutRetirementReadHead func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) + LayoutCreateTarget func(context.Context, lifecycle.VolumeSpec, lifecycle.VolumeSpec, string) error // FrontendPublicationRuntimeHTTP enables the frontend publication runtime // HTTP surface. It is disabled by default and only confirms a post-failback diff --git a/seaweed-block/core/host/master/spec_retirement.go b/seaweed-block/core/host/master/spec_retirement.go index 8e8afbaa58..beedc89a69 100644 --- a/seaweed-block/core/host/master/spec_retirement.go +++ b/seaweed-block/core/host/master/spec_retirement.go @@ -69,7 +69,11 @@ func (h *Host) ReconcileDeletedSpecVolumes(ctx context.Context) error { // configured observation freshness window. This is pacing, not a validity TTL. func (h *Host) reconcileDeletedSpecVolumes(ctx context.Context, paced bool, now time.Time) error { stores := h.Lifecycle() - if stores == nil || h.cfg.LayoutReadHead == nil { + readHead := h.cfg.LayoutRetirementReadHead + if readHead == nil { + readHead = h.cfg.LayoutReadHead + } + if stores == nil || readHead == nil { return nil } h.retirementMu.Lock() @@ -150,7 +154,7 @@ func (h *Host) reconcileDeletedSpecVolumes(ctx context.Context, paced bool, now h.retirementNext[id] = now.Add(h.cfg.Freshness.EffectiveFreshnessWindow()) readCtx, cancel := context.WithTimeout(ctx, 5*time.Second) reads++ - head, readErr := h.cfg.LayoutReadHead(readCtx, rec.Spec) + head, readErr := readHead(readCtx, rec.Spec) ended := readCtx.Err() cancel() if errors.Is(ended, context.DeadlineExceeded) || errors.Is(readErr, context.DeadlineExceeded) { @@ -217,7 +221,7 @@ func (h *Host) reconcileDeletedSpecVolumes(ctx context.Context, paced bool, now // the product loop is disabled. A pass has no total time limit: each HEAD call // has its own bound. Close cancels and joins this worker before closing stores. func (h *Host) startRetirementWorker(ctx context.Context) { - if h.cfg.LayoutReadHead == nil { + if h.cfg.LayoutRetirementReadHead == nil && h.cfg.LayoutReadHead == nil { return } h.wg.Add(1) diff --git a/seaweed-block/core/host/master/spec_retirement_test.go b/seaweed-block/core/host/master/spec_retirement_test.go index 583e94726f..12efdafa55 100644 --- a/seaweed-block/core/host/master/spec_retirement_test.go +++ b/seaweed-block/core/host/master/spec_retirement_test.go @@ -658,3 +658,27 @@ func TestRetireHostDeletionProofKeepsSecondLiveVolume(t *testing.T) { t.Fatalf("cache bypassed reservation recheck: %v", err) } } + +// A retirement pass must not use the serving catalog reader, even on failure. +func TestSpecRetirementUsesItsDedicatedReader(t *testing.T) { + h, _ := retirementScanHost(t, "gone") + h.specDesired = map[string]bool{"gone": true} + servingReads, retirementReads := 0, 0 + h.cfg.LayoutReadHead = func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) { + servingReads++ + return layout.Head{}, errors.New("serving reader must stay untouched") + } + h.cfg.LayoutRetirementReadHead = func(ctx context.Context, _ lifecycle.VolumeSpec) (layout.Head, error) { + retirementReads++ + if _, ok := ctx.Deadline(); !ok { + t.Error("retirement read has no per-call deadline") + } + return layout.Head{}, errors.New("outage on retirement connection") + } + if err := h.ReconcileDeletedSpecVolumes(t.Context()); err != nil { + t.Fatal(err) + } + if retirementReads != 1 || servingReads != 0 { + t.Fatalf("reads: retirement=%d serving=%d", retirementReads, servingReads) + } +} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index a73b24ede3..dbcd76b044 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -1263,7 +1263,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.RetireLine; DeleteRetire.RetirePlace; DeleteRetire.HostRetire | 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-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. Its reads use a dedicated connection. | M4 delete retirement scheduling | `core/host/master/host.go` `Start`, `Close`; `spec_retirement.go` `startRetirementWorker` | `TestStandaloneRestartRetriesSpecRetirementAfterLeaseFloor`, `TestRetirementWorkerRetriesTimeoutWithoutProductLoopOrRestart`, `TestRetirementWorkerTimerJoinsOnCancellation`, `TestRetirementWorkerServingWithOneHundredSlowHeads`, `TestRetirementPassReportsOnlyPendingRecords`, `TestSpecRetirementUsesItsDedicatedReader`, `TestRetirementCatalogOwnsItsConnection` | 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 |