fix: the delete reads a never-claimed initial HEAD as epoch 0

The master's HEAD reader refused the initial HEAD (epoch 0, no holder) as
invalid, so the delete saw every never-started line as unreadable. It now
returns that HEAD with ErrWorkspaceHeadUnclaimed: every caller that needs
an identity still gets an error; the delete evidence reads it as epoch 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-24 07:12:27 -08:00
1 parent bd10769811
commit 0273c9d8aa
5 files changed
+58 -4

No files matched your search

@@ -19,6 +19,13 @@ type WorkspaceHead struct {
FilerMtimeNS int64
}
// ErrWorkspaceHeadUnclaimed is a HEAD reader's answer for a volume's initial
// HEAD that no holder ever claimed (epoch 0, no holder, active): the head
// returned with it carries its generation and epoch 0. It names no identity,
// so a caller that needs one treats it as any read error; the delete
// admission reads it as never started (TERM-LIVE-HOLDER-001).
var ErrWorkspaceHeadUnclaimed = errors.New("HEAD never claimed: epoch 0, no holder")
// ErrWorkspaceOutcomeUncertain marks a move whose outcome is unknown: its
// issuing write failed after it may have reached the store, or the volume's
// workspace persistence is already uncertain. Memory shows it unissued, but
@@ -999,6 +999,9 @@ func (s *services) deleteHolderEvidence(ctx context.Context, vol string) (*autho
readCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
head, err := s.host.cfg.WorkspaceHeadReader(readCtx, vol)
if errors.Is(err, authority.ErrWorkspaceHeadUnclaimed) {
return &head, owner // the initial HEAD: epoch 0, never claimed
}
if err != nil {
s.host.log.Printf("blockmaster: MarkVolumeDeleting volume=%q: HEAD unreadable (%v); a line without an ACK is refused", vol, err)
return nil, owner
@@ -27,11 +27,10 @@ func TestDeleteAdmitsANeverStartedLine(t *testing.T) {
return authority.WorkspaceHead{}, errors.New("filer unreachable")
}
e := uint64(headEpoch.Load())
holder := ""
if e > 0 {
holder = "node-a/r1"
if e == 0 { // the initial HEAD, as the filer reader returns it
return authority.WorkspaceHead{Gen: 2}, authority.ErrWorkspaceHeadUnclaimed
}
return authority.WorkspaceHead{Gen: 2, Epoch: e, Holder: holder}, nil
return authority.WorkspaceHead{Gen: 2, Epoch: e, Holder: "node-a/r1"}, nil
}, nil)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
t.Cleanup(cancel)
@@ -83,6 +83,12 @@ func NewWorkspaceHEADReader(base string) (func(context.Context, string) (authori
return authority.WorkspaceHead{}, err
}
// DecodeHeadDocument above owns the supported-format checks.
// The initial HEAD of a volume no holder ever claimed: epoch 0, no
// holder, active. It names no identity, so callers that need one get
// an error as before; the delete reads it as "never started".
if doc.Gen > 0 && doc.Epoch == 0 && doc.Holder == "" && doc.LegacyDetached == nil && doc.DetachedBy == nil && (doc.State == "" || doc.State == "active") {
return authority.WorkspaceHead{Gen: doc.Gen, FilerMtimeNS: headFilerMtimeNS(res.Header)}, authority.ErrWorkspaceHeadUnclaimed
}
if doc.Gen == 0 || doc.Epoch == 0 || doc.Holder == "" || doc.LegacyDetached != nil || (doc.State != "" && doc.State != "active" && doc.State != "detached") {
return authority.WorkspaceHead{}, fmt.Errorf("invalid HEAD identity/state")
}
@@ -2,9 +2,12 @@ package master
import (
"context"
"errors"
"net/http"
"net/http/httptest"
"testing"
"github.com/seaweedfs/seaweed-block/core/authority"
)
// These are decoder controls, not the W2 Detach/filer integration proof.
@@ -43,3 +46,39 @@ func TestWorkspaceHEADCanonicalState(t *testing.T) {
})
}
}
// The initial HEAD of a volume no holder ever claimed (epoch 0, no holder,
// active) reads as ErrWorkspaceHeadUnclaimed with its generation and epoch 0:
// still an error to every caller that needs an identity, and the delete's
// evidence of "never started". A claimed or detached HEAD is unchanged, and
// an epoch-0 HEAD with a holder or a detach proof stays invalid.
func TestWorkspaceHEADUnclaimed(t *testing.T) {
for _, tc := range []struct {
name, doc string
unclaimed bool
}{
{"initial", `{"format":1,"gen":1,"epoch":0,"holder":"","remote_lsn":0}`, true},
{"initial active", `{"format":1,"gen":1,"epoch":0,"holder":"","remote_lsn":0,"state":"active"}`, true},
{"epoch 0 with a holder", `{"format":1,"gen":1,"epoch":0,"holder":"x/r1","remote_lsn":0}`, false},
{"epoch 0 detached", `{"format":1,"gen":1,"epoch":0,"holder":"","remote_lsn":0,"state":"detached","detachedBy":{"holder":"","epoch":0,"gen":1}}`, false},
} {
t.Run(tc.name, func(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(tc.doc)) }))
defer s.Close()
read, err := NewWorkspaceHEADReader(s.URL)
if err != nil {
t.Fatal(err)
}
h, err := read(context.Background(), "v")
if got := errors.Is(err, authority.ErrWorkspaceHeadUnclaimed); got != tc.unclaimed {
t.Fatalf("unclaimed=%v (err %v); want %v", got, err, tc.unclaimed)
}
if tc.unclaimed && (h.Gen != 1 || h.Epoch != 0) {
t.Fatalf("unclaimed HEAD %+v; want its generation and epoch 0", h)
}
if !tc.unclaimed && err == nil {
t.Fatalf("HEAD %+v accepted; want an error", h)
}
})
}
}