diff --git a/seaweed-block/core/host/volume/replica_stores_wait_test.go b/seaweed-block/core/host/volume/replica_stores_wait_test.go index 7f566d148a..e45c3c4796 100644 --- a/seaweed-block/core/host/volume/replica_stores_wait_test.go +++ b/seaweed-block/core/host/volume/replica_stores_wait_test.go @@ -16,8 +16,17 @@ import ( // projection is not Healthy, writes through the real backend refuse, and // status says "creating: waiting for replica attestations (n of N)". The // same-generation re-send with nothing awaited opens it. +// requiringReplication is a replication slot that counts peers only with +// recorded stores (as replication.ReplicationVolume does on a volume host). +type requiringReplication struct{ *stubReplication } + +func (requiringReplication) RequireAttestedStores() {} + func TestNewVolumePrimaryServesNothingBeforeReplicaAttestations(t *testing.T) { - h, _, _ := newStubbedHost(t, "vol1", "rB", &orderingRecorder{}) + h, _, rep := newStubbedHost(t, "vol1", "rB", &orderingRecorder{}) + h.replicationMu.Lock() + h.setReplicationLocked(requiringReplication{rep}) + h.replicationMu.Unlock() 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 { @@ -52,3 +61,16 @@ func TestNewVolumePrimaryServesNothingBeforeReplicaAttestations(t *testing.T) { t.Fatalf("write once nothing is awaited: %v", err) } } + +// A host whose replication slot does not require recorded stores counts no +// peer ack by store, so the wait does not apply to it: the fact's count +// does not close its frontend. +func TestReplicaStoresWaitOnlyWhereStoresAreRequired(t *testing.T) { + h, _, _ := newStubbedHost(t, "vol1", "rB", &orderingRecorder{}) + fact := selfFact(2) + fact.ReplicaStoresAwaited, fact.ReplicaStoresInitial = 2, 2 + h.noteReplicaStores(fact) + if reason := h.ReplicaStoresAwaited(); reason != "" { + t.Fatalf("a host without a store-requiring slot waits: %q", reason) + } +} diff --git a/seaweed-block/core/host/volume/workspace_startup.go b/seaweed-block/core/host/volume/workspace_startup.go index 09d0f14ca6..404a0434e1 100644 --- a/seaweed-block/core/host/volume/workspace_startup.go +++ b/seaweed-block/core/host/volume/workspace_startup.go @@ -14,8 +14,12 @@ func (h *Host) noteReplicaStores(f *control.AssignmentFact) { // ReplicaStoresAwaited is the reason a new volume's primary serves nothing // yet: "" once every initial replica's store is recorded (or the volume -// never waited). +// never waited). It applies where the replication slot counts peers only +// with recorded stores; a host without one counts no peer ack at all. func (h *Host) ReplicaStoresAwaited() string { + if _, ok := h.getReplication().(storeRequirer); !ok { + return "" + } v := h.storesAwaited.Load() waiting, initial := v>>32, v&0xffffffff if waiting == 0 {