test: a lost primary's and the fencing round's ack profile (red)

The survivors' answers cannot show the profile the lost primary
acknowledged under. Adds AssignmentFact.ack_profile (blockmaster's
profile) with tests: an assignment names the master's profile; a primary
of a replicated line in another profile (or under a master that names
none) does not serve and says why, while its own profile or an RF1 line
serves; and a fencing round answered in another profile publishes
nothing, on both gates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-26 13:03:28 -08:00
1 parent 8b0da9cd67
commit af2b7e4d22
6 files changed
+773 -621

No files matched your search

@@ -5,7 +5,9 @@ import (
"testing"
"time"
"github.com/seaweedfs/seaweed-block/core/adapter"
"github.com/seaweedfs/seaweed-block/core/authority"
"github.com/seaweedfs/seaweed-block/core/host/bootstrap"
"github.com/seaweedfs/seaweed-block/core/ops"
"github.com/seaweedfs/seaweed-block/core/rpc/control"
)
@@ -114,3 +116,57 @@ func TestProbeRound_ReportsAnAckProfileMismatch(t *testing.T) {
})
}
}
// The fencing round's answers are the evidence the decision counts, so their
// profiles are checked too: with the plain round in agreement and a survivor
// answering the fence in another profile, neither gate publishes a primary;
// the line stays and the volume shows ack_profile_mismatch.
func TestTheFencingRoundsAckProfileIsCheckedToo(t *testing.T) {
for _, g := range []struct {
name string
tick func(t *testing.T, h *Host)
}{
{"unsupported gate", func(t *testing.T, h *Host) {
ineligible := restarting
ineligible.eligible = false
unsupportedTick(t, h, ineligible)
}},
{"supported gate", func(t *testing.T, h *Host) {
supportedCreatingTick(t, h, rf3Slot{incarnation: "r1-a", reachable: true, eligible: false})
}},
} {
t.Run(g.name, func(t *testing.T) {
h := newBootGraceMaster(t, Config{ControllerConfig: authority.TopologyControllerConfig{PrimaryBootGrace: 200 * time.Millisecond}})
defer closeTestMaster(t, h)
p := probeOf(t, h)
p.mu.Lock()
p.fenceMismatch = "master sync_quorum, answers r2=best_effort"
p.mu.Unlock()
time.Sleep(250 * time.Millisecond) // past the boot grace
g.tick(t, h)
p.mu.Lock()
fences := p.fenceCalls
p.mu.Unlock()
if fences == 0 {
t.Fatal("no fencing round ran: the plain round agreed, so the fence must be asked")
}
expectLineStaysR1(t, h, "a fencing round answered in another profile")
if !blockedFor(h, "vol-rf3", ops.ReasonAckProfileMismatch) {
t.Fatalf("the volume does not show %s", ops.ReasonAckProfileMismatch)
}
})
}
}
// Every assignment names the master's ack profile in canonical form, so a
// primary can refuse to serve a replicated line under another one.
func TestAssignmentNamesTheMastersAckProfile(t *testing.T) {
for flag, want := range map[string]string{"sync-quorum": "sync_quorum", "best-effort": "best_effort", "sync-all": "sync_all"} {
h := &Host{boot: &bootstrap.DurableAuthorityBootstrap{Publisher: authority.NewPublisher(authority.NewStaticDirective(nil))}, topo: authority.AcceptedTopology{Volumes: []authority.VolumeExpected{{VolumeID: "v", Slots: []authority.ExpectedSlot{{ReplicaID: "r1", ServerID: "s1"}}}}}}
h.promotionProber = &roundEvidenceProvider{ackProfile: flag}
fact := (&services{host: h}).assignmentFact(adapter.AssignmentInfo{VolumeID: "v", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1})
if fact.GetAckProfile() != want {
t.Fatalf("--launcher-replication-ack=%s: assignment names %q; want %q", flag, fact.GetAckProfile(), want)
}
}
}
@@ -24,13 +24,15 @@ func (s staticPromotionProbe) FencePromotionCandidates(_ string, current authori
func (p *switchProbe) FencePromotionCandidates(_ string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
p.mu.Lock()
silent := p.fenceSilent
silent, mismatch := p.fenceSilent, p.fenceMismatch
p.fenceCalls++
p.mu.Unlock()
if silent {
return PromotionProbeResult{FencedEpoch: current.Epoch + 1}, nil
}
return fenceObeyed(current, survivors)
r, err := fenceObeyed(current, survivors)
r.ProfileMismatch = mismatch
return r, err
}
func (p *swapPromotionProbe) FencePromotionCandidates(_ string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
@@ -82,6 +82,9 @@ type switchProbe struct {
profile string
// mismatch is the round's ProfileMismatch ("" = every answer agrees).
mismatch string
// fenceMismatch is the fencing round's ProfileMismatch: the plain round
// agrees, a survivor answers the fence in another profile.
fenceMismatch string
// When hold is set, a probe signals entered and then blocks until
// release is closed.
hold bool
@@ -0,0 +1,70 @@
package volume
import (
"context"
"strings"
"testing"
"github.com/seaweedfs/seaweed-block/core/engine"
"github.com/seaweedfs/seaweed-block/core/frontend"
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
"github.com/seaweedfs/seaweed-block/core/storage/memorywal"
)
// A primary of a replicated line serves only under the ack profile its
// assignment names (the master's): a volume started with the default
// best-effort and assigned primary of a sync-quorum line is not Healthy,
// refuses writes through the real backend, and says why, naming both
// profiles. The same line under its own profile serves; a line without
// peers (RF1) is not held by the profile.
func TestPrimaryOfAReplicatedLineServesOnlyUnderTheMastersAckProfile(t *testing.T) {
peer := []*control.ReplicaDescriptor{{ReplicaId: "rC", Epoch: 2, EndpointVersion: 1, DataAddr: "127.0.0.1:3", CtrlAddr: "127.0.0.1:4"}}
for _, c := range []struct {
name string
master string
peers []*control.ReplicaDescriptor
serves bool
}{
{"replicated line under another profile", "sync_quorum", peer, false},
{"replicated line from a master that names none", "", peer, false},
{"replicated line under its own profile", "best_effort", peer, true},
{"RF1 line under another profile", "sync_quorum", nil, true},
} {
t.Run(c.name, func(t *testing.T) {
h, _, _ := newStubbedHost(t, "vol1", "rB", &orderingRecorder{})
h.cfg.AckProfile = "best_effort" // blockvolume's default --replication-ack
proj := &mutableProjector{p: engine.ReplicaProjection{Mode: engine.ModeHealthy, Epoch: 2, EndpointVersion: 1}}
h.view = NewAdapterProjectionView(proj, "vol1", "rB", h)
if err := h.SetSelfFence(&switchFencer{}); err != nil {
t.Fatal(err)
}
store := memorywal.NewStore(8, 4096)
t.Cleanup(func() { _ = store.Close() })
backend := durable.NewStorageBackend(store, h.view, frontend.Identity{VolumeID: "vol1", ReplicaID: "rB", Epoch: 2, EndpointVersion: 1})
backend.SetOperational(true, "ack profile")
fact := selfFact(2)
fact.Peers, fact.AckProfile = c.peers, c.master
h.applyFixtureFact(fact)
_, werr := backend.Write(context.Background(), 0, []byte("w"))
s := NewStatusServer(h.view).statusProjection()
if c.serves {
if !h.view.Projection().Healthy || werr != nil {
t.Fatalf("does not serve: healthy=%t write=%v reason=%q", h.view.Projection().Healthy, werr, s.NotReadyReason)
}
return
}
if h.view.Projection().Healthy {
t.Fatal("a primary in another ack profile than its line's is Healthy")
}
if werr == nil {
t.Fatal("a write was acknowledged by a primary in another ack profile than its line's")
}
if s.FrontendPrimaryReady || !strings.Contains(s.NotReadyReason, "ack profile mismatch") || !strings.Contains(s.NotReadyReason, "best_effort") {
t.Fatalf("status: ready=%t reason=%q; want the mismatch naming both profiles", s.FrontendPrimaryReady, s.NotReadyReason)
}
})
}
}
File diff suppressed because it is too large. Load diff
@@ -323,6 +323,12 @@ message AssignmentFact {
// another one is a restarted process: it opens no replica session on
// this line, whose sessions belong to the dead process.
string line_incarnation = 17;
// The master's replication ACK profile (blockmaster's
// --launcher-replication-ack, canonical: best_effort, sync_quorum,
// sync_all). A primary of a replicated line whose own --replication-ack
// is another one does not serve: a later failover reads its
// acknowledged writes by this profile's rules.
string ack_profile = 18;
}
// PrimaryKind is how a line made its primary the primary.