fix: exclude deleted work from checks and host retirement (#1033)

Merge note (batch b13; pull_request_target spec-trace workflow has a startup_failure, so its checks run locally):
- One Test run (47268279447) succeeded (go test (linux), process-level tests (real binaries)) on the integration tree 78104cee = main 40c56035 + #1033 #1034 #1036 #1038 #1035  in this order; these squash merges reproduce that tree, verified after the last one.
- spec-trace-check.sh and public-text-check.sh, run with main's scripts against this head and body: both exit 0.
This commit is contained in:
pingqiu-cpu authored and GitHub committed 2026-12-03 21:14:56 -08:00
1 parent 99fcb4bc96
commit 5437732181
7 files changed
+247 -6

No files matched your search

+7 -1
View File
@@ -443,7 +443,13 @@ func (o *inspectionObservation) known() checkFinding {
if len(o.volumes) == 0 {
return checkElsewhere("no volumes registered")
}
return checkOK(fmt.Sprintf("%d volume records", len(o.volumes)))
count := 0
for _, v := range o.volumes {
if v.evidence.Status != ops.ObservationStatusDeleting && v.evidence.Status != ops.ObservationStatusDeleted {
count++
}
}
return checkOK(fmt.Sprintf("%d volume records", count))
}
func (o *inspectionObservation) assigned() checkFinding {
return o.each(false, func(v inspectedVolume) checkFinding {
@@ -114,3 +114,20 @@ func TestClusterCheckCollectionSkipsDeletedRPCsAndKeepsLiveFailures(t *testing.T
t.Fatalf("live collection missing: lease=%v HTTP=%v", backend.leases, requests)
}
}
func TestClusterCheckKnownExcludesDeletingRecords(t *testing.T) {
for _, state := range []string{ops.ObservationStatusDeleting, ops.ObservationStatusDeleted} {
for _, requested := range []string{"", "gone"} {
o := &inspectionObservation{requested: requested, volumes: []inspectedVolume{{evidence: ops.VolumeEvidence{VolumeID: "gone", Status: state}}}}
if f := o.known(); f.Status == "FAIL" || f.Finding != "0 volume records" {
t.Fatalf("%s requested=%s: %+v", state, requested, f)
}
if requested == "" {
o.volumes = append(o.volumes, inspectedVolume{evidence: ops.VolumeEvidence{VolumeID: "live", Status: ops.ObservationStatusStopped}})
if f := o.known(); f.Finding != "1 volume records" {
t.Fatalf("stopped live record lost: %+v", f)
}
}
}
}
}
+16 -2
View File
@@ -10,6 +10,7 @@ import (
"sync/atomic"
"time"
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
"github.com/seaweedfs/seaweed-block/core/lifecycle"
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
"github.com/seaweedfs/seaweed-block/core/rpc/lifecycleclient"
@@ -518,8 +519,16 @@ func (h *Host) RetireHost(server, confirm string) error {
if _, ok := h.lifecycle.Nodes.GetNode(server); !ok {
return fmt.Errorf("retire refused: host %q is not registered", server)
}
if vols := h.volumesServedBy(server); len(vols) > 0 {
return errHostHoldsWork{server: server, volumes: vols}
var work []string
for _, id := range h.candidateVolumesServedBy(server) {
proof, ok := h.noWork.Load(id)
if ok && (proof == layout.StateDeleting || proof == layout.StateDeleted) && h.lifecycle.Deletions.CommittedSnapshot(id) && h.Publisher().NoLiveWorkspaceLease(context.Background(), id) == nil {
continue
}
work = append(work, id)
}
if len(work) > 0 {
return errHostHoldsWork{server: server, volumes: work}
}
if err := h.lifecycle.Nodes.RemoveNode(server); err != nil {
return errRetireStorage{err}
@@ -568,6 +577,11 @@ func (s *services) RetireHost(ctx context.Context, req *control.RetireHostReques
if err := ctx.Err(); err != nil {
return nil, err
}
if req.GetServerId() != "" && req.GetConfirm() == req.GetServerId() {
if err := s.host.refreshHostDeletionProofs(ctx, req.GetServerId()); err != nil {
return nil, workspaceError(err)
}
}
s.host.workspaceMu.Lock()
defer s.host.workspaceMu.Unlock()
err := s.host.RetireHost(req.GetServerId(), req.GetConfirm())
@@ -81,6 +81,19 @@ func (h *Host) nodeServesVolumes(server string) bool { return len(h.volumesServe
// line it sources), a live line a move issued to it, a static topology volume whose line a move minted on
// it, or a static topology home slot whose line no move minted.
func (h *Host) volumesServedBy(server string) []string {
candidates := h.candidateVolumesServedBy(server)
out := candidates[:0]
for _, v := range candidates {
if _, noWork := h.noWork.Load(v); !noWork {
out = append(out, v)
}
}
return out
}
// Keep the raw membership separate so the retire guard can recheck cached
// proof premises without adding publisher locks to heartbeat census reads.
func (h *Host) candidateVolumesServedBy(server string) []string {
seen := map[string]bool{}
lines := h.Publisher().PublishedAuthorityLines()
if h.lifecycle != nil {
@@ -125,9 +138,6 @@ func (h *Host) volumesServedBy(server string) []string {
}
out := make([]string, 0, len(seen))
for v := range seen {
if _, noWork := h.noWork.Load(v); noWork {
continue
}
out = append(out, v)
}
sort.Strings(out)
@@ -169,3 +169,45 @@ func (h *Host) reconcileDeletedSpecVolumes(ctx context.Context, limited bool, no
}
return nil
}
// refreshHostDeletionProofs rebuilds only the requested host's missing NoWork
// proofs. The permanent reservation makes a post-lease deleting/deleted/absent
// HEAD monotone. A read failure retains work; this never retires volume data
// or metadata. Run before taking workspaceMu, then use the normal retire guard.
func (h *Host) refreshHostDeletionProofs(ctx context.Context, server string) error {
if h.lifecycle == nil || h.cfg.LayoutReadHead == nil {
return nil
}
for _, id := range h.volumesServedBy(server) {
if err := ctx.Err(); err != nil {
return err
}
if !h.lifecycle.Deletions.CommittedSnapshot(id) {
continue
}
if err := h.Publisher().NoLiveWorkspaceLease(ctx, id); err != nil {
continue
}
rec, ok := h.lifecycle.Volumes.GetVolumeSnapshot(id)
if !ok {
continue
}
readCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
head, err := h.cfg.LayoutReadHead(readCtx, rec.Spec)
ended := readCtx.Err()
cancel()
if ended != nil {
continue
}
state := head.State
if errors.Is(err, layout.ErrHeadAbsent) {
state = layout.StateDeleted
} else if err != nil {
continue
}
if state == layout.StateDeleting || state == layout.StateDeleted {
h.noWork.Store(id, state)
}
}
return ctx.Err()
}
@@ -8,6 +8,7 @@ import (
"reflect"
"runtime"
"slices"
"strings"
"sync/atomic"
"testing"
"time"
@@ -486,3 +487,153 @@ func TestSpecRetirementLocalFailureDoesNotStopOtherVolumesOrProductTick(t *testi
t.Fatalf("retirement retry must take a new post-lease HEAD proof: %v", reads)
}
}
// Retiring a host must refresh a missing disposable proof on demand, without
// waiting for a product tick or retiring unrelated volume metadata.
func TestRetireHostRefreshesDeletedWorkProof(t *testing.T) {
for _, state := range []string{"deleting", "deleted", "absent", "live", "unread", "timeout", "partial"} {
t.Run(state, func(t *testing.T) {
h, _ := retirementScanHost(t, "gone", "other")
if _, err := h.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-a", Addr: "127.0.0.1:9200"}); err != nil {
t.Fatal(err)
}
if _, err := h.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: "gone", DesiredRF: 1, Candidates: []lifecycle.PlacementCandidate{{VolumeID: "gone", ServerID: "node-a", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil {
t.Fatal(err)
}
var reads atomic.Int32
h.cfg.LayoutReadHead = func(readCtx context.Context, spec lifecycle.VolumeSpec) (layout.Head, error) {
if spec.VolumeID != "gone" {
t.Errorf("read unrelated volume %s", spec.VolumeID)
}
reads.Add(1)
if !h.workspaceMu.TryLock() {
t.Error("HEAD read held workspaceMu")
} else {
h.workspaceMu.Unlock()
}
switch state {
case "absent":
return layout.Head{}, layout.ErrHeadAbsent
case "unread":
return layout.Head{}, errors.New("unavailable")
case "timeout":
<-readCtx.Done()
return layout.Head{State: layout.StateDeleted}, nil
}
return layout.Head{State: state}, nil
}
if state == "partial" {
cfg := h.cfg
closeTestMaster(t, h)
if err := os.WriteFile(filepath.Join(cfg.AuthorityStoreDir, "broken.v3auth.json"), []byte("not JSON"), 0600); err != nil {
t.Fatal(err)
}
fresh, err := New(cfg)
if err != nil {
t.Fatal(err)
}
h = fresh
h.Start()
t.Cleanup(func() { closeTestMaster(t, fresh) })
if len(h.Publisher().LoadErrors()) == 0 {
t.Fatal("partial-load fixture skipped no record")
}
}
conn, err := grpc.NewClient(h.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}
defer conn.Close()
_, err = control.NewLifecycleServiceClient(conn).RetireHost(t.Context(), &control.RetireHostRequest{ServerId: "node-a", Confirm: "node-a"})
wantRetired := state == "deleting" || state == "deleted" || state == "absent"
if (err == nil) != wantRetired {
t.Fatalf("retire state %s: %v", state, err)
}
wantReads := int32(1)
if state == "partial" {
wantReads = 0
}
if reads.Load() != wantReads {
t.Fatalf("HEAD reads=%d want%d", reads.Load(), wantReads)
}
if _, ok := h.Lifecycle().Volumes.GetVolume("gone"); !ok {
t.Fatal("retire-host removed volume metadata")
}
if _, ok := h.Lifecycle().Volumes.GetVolume("other"); !ok {
t.Fatal("retire-host removed unrelated work")
}
if !h.Lifecycle().Deletions.CommittedSnapshot("gone") {
t.Fatal("retire-host removed tombstone")
}
})
}
}
func TestRetireHostDoesNotReadHeadBeforeCreatingLeaseEnds(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Linux lifecycle directory fsync")
}
h, lc, _, _, now := neverCreatedVolume(t, false)
if err := h.VolumeDeleteAuthority("v", "retire-live").Reserve(t.Context()); err != nil {
t.Fatal(err)
}
var reads atomic.Int32
h.cfg.LayoutReadHead = func(context.Context, lifecycle.VolumeSpec) (layout.Head, error) {
reads.Add(1)
return layout.Head{State: layout.StateDeleted}, nil
}
req := &control.RetireHostRequest{ServerId: "node-a", Confirm: "node-a"}
// A cached entry alone cannot override the locked live-lease guard.
h.noWork.Store("v", layout.StateDeleted)
if _, err := lc.RetireHost(t.Context(), req); status.Code(err) != codes.FailedPrecondition {
t.Fatalf("retire with live creating lease: %v", err)
}
if reads.Load() != 0 {
t.Fatal("read HEAD before no-live-lease proof")
}
h.noWork.Delete("v")
now.Add(int64(2 * time.Minute))
if _, err := lc.RetireHost(t.Context(), req); err != nil {
t.Fatalf("retire after lease and deleted proof: %v", err)
}
if reads.Load() != 1 {
t.Fatalf("HEAD reads=%d want1", reads.Load())
}
}
func TestRetireHostDeletionProofKeepsSecondLiveVolume(t *testing.T) {
h, _ := retirementScanHost(t, "gone")
if _, err := h.Lifecycle().Volumes.CreateVolume(lifecycle.VolumeSpec{VolumeID: "live", SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil {
t.Fatal(err)
}
if _, err := h.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-a", Addr: "127.0.0.1:9200"}); err != nil {
t.Fatal(err)
}
for _, id := range []string{"gone", "live"} {
if _, err := h.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: id, DesiredRF: 1, Candidates: []lifecycle.PlacementCandidate{{VolumeID: id, ServerID: "node-a", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil {
t.Fatal(err)
}
}
h.cfg.LayoutReadHead = func(_ context.Context, spec lifecycle.VolumeSpec) (layout.Head, error) {
if spec.VolumeID != "gone" {
t.Errorf("read unreserved volume %s", spec.VolumeID)
}
return layout.Head{State: layout.StateDeleted}, nil
}
conn, err := grpc.NewClient(h.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}
defer conn.Close()
_, err = control.NewLifecycleServiceClient(conn).RetireHost(t.Context(), &control.RetireHostRequest{ServerId: "node-a", Confirm: "node-a"})
if status.Code(err) != codes.FailedPrecondition || !strings.Contains(err.Error(), "volumes live;") || strings.Contains(err.Error(), "gone") {
t.Fatalf("retire with second live volume: %v", err)
}
// Even a stale/invalid cache entry cannot hide an unreserved volume.
h.noWork.Store("live", layout.StateDeleted)
_, err = control.NewLifecycleServiceClient(conn).RetireHost(t.Context(), &control.RetireHostRequest{ServerId: "node-a", Confirm: "node-a"})
if status.Code(err) != codes.FailedPrecondition || !strings.Contains(err.Error(), "volumes live;") {
t.Fatalf("cache bypassed reservation recheck: %v", err)
}
}
+1
View File
@@ -204,6 +204,7 @@ core/host/master/host.go New http.Server.IdleTimeout 1 per-call NONE: no model r
core/host/master/probe_round.go roundEvidenceProvider.round time.NewTimer 1 per-call FencingRound.Deliver; FencingRound.Open one probe round's evidence wait
core/host/master/services.go services.deleteHolderEvidence context.WithTimeout 1 per-call FormatGate.Report one RPC or request
core/host/master/spec_retirement.go Host.reconcileDeletedSpecVolumes context.WithTimeout 1 per-call DeleteRetire.ReadOK one fresh HEAD read after the no-live-lease barrier
core/host/master/spec_retirement.go Host.refreshHostDeletionProofs context.WithTimeout 1 per-call DeleteRetire.ReadOK one post-lease HEAD read for a requested host candidate; error retains work
core/host/master/workspace_service.go services.AckWorkspaceRevoked context.WithTimeout 1 per-call FormatGate.Place; MoveAdmission.ReadForMove; StopAndRestart.ReadClean one RPC or request
core/host/master/workspace_service.go services.MoveWorkspace context.WithTimeout 1 per-call FormatGate.Place; MoveAdmission.ReadForMove; StopAndRestart.ReadClean one RPC or request
core/host/master/workspace_service.go services.PreviewWorkspaceMove context.WithTimeout 1 per-call FormatGate.Place; MoveAdmission.ReadForMove; StopAndRestart.ReadClean one RPC or request
Can't render this file because it contains an unexpected character in line 49 and column 123.