mq broker: keep one request id across filers for a topic.conf save (#13237)

A save that applied but lost its answer was retried on the next filer under
a new request id, refused as changed by its own write, and redone from the
saved topic.conf: a balance move then found the target already leading and
failed after saving. The same id lets the owner replay the recorded outcome.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-12-01 14:19:51 -08:00
1 parent 5213f4c1b0
commit 42a39099e0
3 files changed
+22 -4

No files matched your search

+4 -1
View File
@@ -9,6 +9,7 @@ import (
"sync/atomic"
"time"
"github.com/google/uuid"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
"github.com/seaweedfs/seaweedfs/weed/pb"
@@ -179,9 +180,11 @@ func (fca *FilerClientAccessor) SaveTopicConfToFiler(ctx context.Context, t topi
glog.V(0).Infof("save conf for topic %v to filer", t)
// one id across filers, so a failover replays a save whose answer was lost
requestId := uuid.NewString()
var saveErr error
if err := fca.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
saveErr = t.WriteConfFile(ctx, client, conf, previous)
saveErr = t.WriteConfFile(ctx, client, conf, previous, requestId)
if errors.Is(saveErr, topic.ErrConfChanged) {
// the filer answered, and any other would refuse it too
return nil
@@ -223,3 +223,18 @@ func TestSlowRetirementKeepsTheTargetWaiting(t *testing.T) {
t.Fatalf("the target could not take the sealed fence: %v", err)
}
}
// A move whose topic.conf save applied but lost its answer is retried on the next
// filer as the same request, so it is not redone over its own save and refused.
func TestBalanceMoveKeepsASaveWhoseAnswerWasLost(t *testing.T) {
f, b, source, target := newMove(t)
b.fca.GetFilers = func() []pb.ServerAddress { return []pb.ServerAddress{b.GetFiler(), b.GetFiler()} }
f.mu.Lock()
f.dropResponses = 1
f.mu.Unlock()
if _, err := b.BalanceTopics(context.Background(), &mq_pb.BalanceTopicsRequest{}); err != nil {
t.Fatal(err)
}
movedAssignment(t, f, source, target)
}
+3 -3
View File
@@ -8,7 +8,6 @@ import (
"strings"
"time"
"github.com/google/uuid"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
@@ -98,7 +97,8 @@ func (t Topic) ReadConfFileWithMetadata(ctx context.Context, client filer_pb.Sea
// WriteConfFile saves conf only while topic.conf is still the entry previous was
// read as, or still absent when previous is nil; otherwise it fails with ErrConfChanged.
func (t Topic) WriteConfFile(ctx context.Context, client filer_pb.SeaweedFilerClient, conf *mq_pb.ConfigureTopicResponse, previous *filer_pb.Entry) error {
// A retry with the same requestId gets the outcome the filer recorded for it.
func (t Topic) WriteConfFile(ctx context.Context, client filer_pb.SeaweedFilerClient, conf *mq_pb.ConfigureTopicResponse, previous *filer_pb.Entry, requestId string) error {
var buf bytes.Buffer
filer.ProtoToText(&buf, conf)
content := buf.Bytes()
@@ -128,7 +128,7 @@ func (t Topic) WriteConfFile(ctx context.Context, client filer_pb.SeaweedFilerCl
ConditionKey: path,
Condition: &filer_pb.WriteCondition{Clauses: []*filer_pb.WriteCondition_Clause{condition}},
Mutations: []*filer_pb.ObjectMutation{{Type: filer_pb.ObjectMutation_PUT, Directory: t.Dir(), Entry: entry}},
RequestId: uuid.NewString(),
RequestId: requestId,
})
if status.Code(err) == codes.FailedPrecondition || resp.GetErrorCode() == filer_pb.FilerError_PRECONDITION_FAILED {
return fmt.Errorf("save topic %v conf: %w", t, ErrConfChanged)