Compare commits

..
Author SHA1 Message Date
pingqiuandClaude Opus 5.5 6dce14b5bf seaweed-block: a queued rebalance carries the line it was decided against
The controller's rebalance ask now names the current line it was decided
against (ExpectCurrent), as an endpoint refresh already does. A line
published directly since, such as an operator's failover, makes the
publisher refuse the queued rebalance (ErrExpectedLineMoved) instead of
minting it over that line at the next epoch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 03:37:17 -08:00
pingqiuandClaude Opus 5.5 b773ffbe98 seaweed-block: red: a queued rebalance is minted over a line the operator published since
The controller decides a rebalance against the line it read and queues it.
An operator's failover published directly in that window is overridden
when the publisher takes the queued ask: today it mints the rebalance at
the next epoch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-05 03:36:30 -08:00
6 changed files with 93 additions and 179 deletions

No files matched your search

@@ -510,6 +510,10 @@ func (c *TopologyController) decideVolume(
Intent: IntentReassign,
Evidence: plannedEvidence(target.PromotionEvidence),
Incarnation: target.Incarnation,
// Decided against the line read for this intake: a line
// published directly since (an operator's failover) refuses
// it, so a queued rebalance never overrides that line.
ExpectCurrent: &ExpectedLine{ReplicaID: currentLine.ReplicaID, Epoch: currentLine.Epoch, DataAddr: currentLine.DataAddr, CtrlAddr: currentLine.CtrlAddr},
}, "rebalance", true
}
return AssignmentAsk{}, "", false
@@ -0,0 +1,89 @@
package authority
import (
"context"
"errors"
"testing"
"time"
)
// A rebalance is decided against the line the controller read and waits in
// the queue until the publisher takes it. A line published directly in that
// window (an operator's failover) must not be overridden by the queued
// rebalance: the publisher refuses it because the line moved, and the line
// the operator published stays.
func TestAQueuedRebalanceIsNotMintedOverALineMovedSinceItWasDecided(t *testing.T) {
holder := &basisReaderHolder{}
ctrl := NewTopologyController(TopologyControllerConfig{RebalanceSkew: 1}, holder)
pub := NewPublisher(ctrl)
holder.set(pub)
for _, seed := range []AssignmentAsk{
{VolumeID: "v1", ReplicaID: "v1r1", DataAddr: "d11", CtrlAddr: "c11", Intent: IntentBind},
{VolumeID: "v2", ReplicaID: "v2r1", DataAddr: "d21", CtrlAddr: "c21", Intent: IntentBind},
{VolumeID: "v3", ReplicaID: "v3r2", DataAddr: "d32", CtrlAddr: "c32", Intent: IntentBind},
} {
if err := pub.apply(seed); err != nil {
t.Fatalf("seed %s: %v", seed.VolumeID, err)
}
}
// s1 carries two primaries, s3 none: the controller decides v1's
// rebalance to v1r3 against v1r1@1 and queues it (the publisher is not
// draining yet).
snap := ClusterSnapshot{
CollectedRevision: 1,
Servers: []ServerObservation{
{ServerID: "s1", Reachable: true, Eligible: true},
{ServerID: "s2", Reachable: true, Eligible: true},
{ServerID: "s3", Reachable: true, Eligible: true},
},
Volumes: []VolumeTopologySnapshot{
clusterVolume("v1", observedAuthorityFrom(pub, "v1"),
candidate("v1r1", "s1", "d11", "c11", 10),
candidate("v1r2", "s2", "d12", "c12", 10),
candidate("v1r3", "s3", "d13", "c13", 30),
),
clusterVolume("v2", observedAuthorityFrom(pub, "v2"),
candidate("v2r1", "s1", "d21", "c21", 10),
candidate("v2r2", "s2", "d22", "c22", 10),
candidate("v2r3", "s3", "d23", "c23", 10),
),
clusterVolume("v3", observedAuthorityFrom(pub, "v3"),
candidate("v3r1", "s1", "d31", "c31", 10),
candidate("v3r2", "s2", "d32", "c32", 10),
candidate("v3r3", "s3", "d33", "c33", 10),
),
},
}
if err := ctrl.SubmitClusterSnapshot(snap); err != nil {
t.Fatal(err)
}
if d, ok := ctrl.DesiredFor("v1"); !ok || d.Ask.ReplicaID != "v1r3" || d.Reason != "rebalance" {
t.Fatalf("fixture: v1's desired %+v (ok=%v), want the rebalance to v1r3 queued", d, ok)
}
// The operator's failover publishes v1r2 directly, at the next epoch.
operator := candidate("v1r2", "s2", "d12", "c12", 10).PromotionEvidence
if err := pub.apply(AssignmentAsk{VolumeID: "v1", ReplicaID: "v1r2", DataAddr: "d12", CtrlAddr: "c12", Intent: IntentReassign, Evidence: operator}); err != nil {
t.Fatalf("the operator's failover: %v", err)
}
moved, _ := pub.VolumeAuthorityLine("v1")
if moved.ReplicaID != "v1r2" || moved.Epoch != 2 {
t.Fatalf("fixture: line after the failover %+v, want v1r2@2", moved)
}
// The publisher now takes the queued rebalance.
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
ask, err := ctrl.Next(ctx)
if err != nil || ask.VolumeID != "v1" || ask.ReplicaID != "v1r3" {
t.Fatalf("fixture: took %+v %v, want the queued rebalance of v1 to v1r3", ask, err)
}
applyErr := pub.apply(ask)
line, _ := pub.VolumeAuthorityLine("v1")
if line.ReplicaID != "v1r2" || line.Epoch != 2 {
t.Fatalf("the queued rebalance overrode the operator's failover: line %+v (apply: %v), want v1r2@2 kept", line, applyErr)
}
if !errors.Is(applyErr, ErrExpectedLineMoved) {
t.Fatalf("the stale rebalance was refused with %v, want ErrExpectedLineMoved", applyErr)
}
}
@@ -1,69 +0,0 @@
package layout
import (
"context"
"errors"
"testing"
)
// pausedAfterWindow is the store as a paused adopter sees it: its first HEAD
// read returns the HEAD of that moment, and then, before the adopter acts on
// it, the rest of the cluster moves on (pause).
type pausedAfterWindow struct {
*chainStore
reads int
pause func()
}
func (s *pausedAfterWindow) ReadHead(ctx context.Context) (Head, bool, error) {
h, found, err := s.chainStore.ReadHead(ctx)
s.reads++
if s.reads == 1 && s.pause != nil {
s.pause()
}
return h, found, err
}
// An adopter that passed its delete-intent window and then paused must not
// re-tag the page once the window has moved on. During its pause a cleaner
// pass moved the HEAD generation, the unlinked page was deleted, and another
// executor of the same operation staged it again at the new base. Acting on
// its stale window, the adopter would take over that new executor's page
// under the old base's writer tag; it must refuse instead and leave the page
// as the new executor staged it.
func TestAPausedAdopterDoesNotRetagAPageStagedAgainAfterItsWindow(t *testing.T) {
s, c, p := deleteIntentFixture(t)
ctx := context.Background()
base := s.h.Gen
if _, err := StageSnapshotDeletePage(ctx, s, base, p); err != nil {
t.Fatal(err)
}
rel, err := c.Ref.Path()
if err != nil {
t.Fatal(err)
}
paused := &pausedAfterWindow{chainStore: s, pause: func() {
// A cleaner pass (two HEAD generations) removes the unlinked page,
// then another executor stages it again at the new base.
s.h.Gen = base + 2
delete(s.objs, s.full(rel))
if _, err := StageSnapshotDeletePage(ctx, s, base+2, p); err != nil {
t.Errorf("the second executor's staging: %v", err)
}
}}
adoptErr := adoptDeleteIntentPage(ctx, paused, s.volume, base, c.Ref)
meta, found, err := s.Stat(ctx, rel)
if err != nil || !found {
t.Fatalf("stat the page: %v %v", found, err)
}
if meta.Session != p.Producer || meta.Mark != "" {
t.Fatalf("the paused adopter re-tagged the page staged at the new base: tags %+v (adopt: %v), want the second executor's %q", meta, adoptErr, p.Producer)
}
if adoptErr == nil {
t.Fatal("the paused adopter acted on a window that had moved on: want a refusal")
}
if !errors.Is(adoptErr, ErrPrecondition) && !errors.Is(adoptErr, ErrBusy) {
t.Fatalf("the paused adopter was refused with %v, want ErrPrecondition or ErrBusy", adoptErr)
}
}
@@ -1,99 +0,0 @@
package chunkstore
import (
"bytes"
"context"
"errors"
"sync"
"testing"
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/filerpb"
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
)
// betweenLookupAndUpdate runs before, once, ahead of the first UpdateEntry:
// what other writers do while a stale one is between its lookup and its
// conditional update.
type betweenLookupAndUpdate struct {
Filer
once sync.Once
before func()
}
func (f *betweenLookupAndUpdate) UpdateEntry(ctx context.Context, dir string, e *filerpb.Entry, expected map[string][]byte) error {
f.once.Do(f.before)
return f.Filer.UpdateEntry(ctx, dir, e, expected)
}
// A stale metadata change (a delete-intent page's adoption by an executor
// that paused between its lookup and its update) must not write the entry it
// looked up over an object that was deleted and created again with the same
// tags in between: the update would put the deleted object's chunk list on
// the new entry, and the filer frees the new entry's chunks.
func TestAStaleMetadataChangeDoesNotOverwriteARecreatedObject(t *testing.T) {
ctx := context.Background()
f, b := newFakeFiler(), newFakeBlobs()
var id layout.VolumeID
for i := range id {
id[i] = 0x30 + byte(i)
}
others, err := NewLayoutStore(f, b, "/vol", id)
if err != nil {
t.Fatal(err)
}
hooked := &betweenLookupAndUpdate{Filer: f}
stale, err := NewLayoutStore(hooked, b, "/vol", id)
if err != nil {
t.Fatal(err)
}
data := bytes.Repeat([]byte{0x5a}, 4096)
rel := layout.NameChunk(1, data).Path()
dir, name, err := others.object(rel)
if err != nil {
t.Fatal(err)
}
fidOf := func() string {
t.Helper()
e, err := f.LookupEntry(ctx, dir, name)
if err != nil || len(e.Chunks) != 1 {
t.Fatalf("lookup %s: %+v %v", rel, e, err)
}
return e.Chunks[0].FileId
}
if err := others.Create(ctx, rel, data, "producer-1"); err != nil {
t.Fatal(err)
}
first := fidOf()
meta, found, err := others.Stat(ctx, rel)
if err != nil || !found {
t.Fatalf("stat: %v %v", found, err)
}
var second string
hooked.before = func() {
// While the stale writer is between lookup and update: a cleaner
// marks and deletes the object, and another executor of the same
// operation creates it again with the same producer tag.
if err := others.Mark(ctx, rel, meta, "clean-1"); err != nil {
t.Errorf("mark: %v", err)
}
if err := others.DeleteMarked(ctx, rel, "clean-1"); err != nil {
t.Errorf("delete: %v", err)
}
if err := others.Create(ctx, rel, data, "producer-1"); err != nil {
t.Errorf("re-create: %v", err)
}
second = fidOf()
}
reuseErr := stale.Reuse(ctx, rel, meta, "writer-1")
if second == "" || second == first {
t.Fatalf("fixture: the object was not re-created with a new chunk (first %s, second %s)", first, second)
}
if got := fidOf(); got != second {
t.Fatalf("the stale update wrote the deleted object's chunk %s over the re-created object's %s (Reuse: %v)", got, second, reuseErr)
}
if !errors.Is(reuseErr, layout.ErrPrecondition) {
t.Fatalf("the stale update over a re-created object answered %v, want ErrPrecondition", reuseErr)
}
}
@@ -27,10 +27,6 @@ writing guest:
5. **Under `best-effort`, a replica can fall behind while it shows `healthy`.** A `best-effort` write waits for no
replica, so a replica whose connection dropped can keep showing `healthy` while it misses writes. Use `sync-quorum`
when the replicas must hold the data.
6. **An operator failover can be undone by an automatic rebalance.** With `sync-all`, or `sync-quorum` and two
replicas, a rebalance blockmaster decided just before `sw-block ops failover` can still be applied after it and move
the primary again. No acknowledged write is lost. After a failover, read the line with
`sw-block ops volumes --master-api <addr> -o json` and, if the primary moved, repeat the failover against it.
**Planned for a later release.** Supported replicated volumes are planned for a later release; v1.1.x keeps every replicated
configuration a preview. Replicated volumes are a preview: a primary cut off from the block master is not stopped
-7
View File
@@ -46,13 +46,6 @@ v1.1.1 is a fix release of the v1.1 line. None of its changes alters a stored fo
- At startup blockmaster checks volumes that are reserved for deletion and hold no workspace lease, one at a time, before it serves. Each check reads the filer, so a slow filer delays the start: in our test, 100 such volumes with a 100 ms filer delay added about 20 s. Volumes in normal use are skipped without a read.
- No data is lost. A fix is planned for v1.1.2.
## Known issue: replicated volumes (preview): a queued rebalance can undo an operator failover
- Affects replicated volumes (preview) whose acknowledgement profile allows a planned move: `sync-all`, or `sync-quorum` with two replicas.
- blockmaster may decide an automatic rebalance, which moves the primary to a less loaded server, just before an operator's `sw-block ops failover`. If that rebalance is applied after the failover, it moves the primary again, away from the replica the operator chose.
- No acknowledged write is lost: under these profiles every replica holds every acknowledged write.
- What to do: after `sw-block ops failover`, read the volume's line with `sw-block ops volumes --master-api <addr> -o json`; if `primary_replica` moved again, repeat the failover with `--expect-current <primary_replica>@<epoch>`. A fix is planned for a later v1.1.x release.
## Upgrade notes
- **Order: the CLI first, then blockmaster, then each holder**, as in