From 42a39099e09d98f65e1d51aa46dffa2091170c4e Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 1 Dec 2026 14:19:51 -0800 Subject: [PATCH] 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 --- weed/filer_client/filer_client_accessor.go | 5 ++++- weed/mq/broker/broker_grpc_balance_test.go | 15 +++++++++++++++ weed/mq/topic/topic.go | 6 +++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/weed/filer_client/filer_client_accessor.go b/weed/filer_client/filer_client_accessor.go index dc7acce839..9ba0fc531e 100644 --- a/weed/filer_client/filer_client_accessor.go +++ b/weed/filer_client/filer_client_accessor.go @@ -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 diff --git a/weed/mq/broker/broker_grpc_balance_test.go b/weed/mq/broker/broker_grpc_balance_test.go index cdbef844b6..94812af19d 100644 --- a/weed/mq/broker/broker_grpc_balance_test.go +++ b/weed/mq/broker/broker_grpc_balance_test.go @@ -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) +} diff --git a/weed/mq/topic/topic.go b/weed/mq/topic/topic.go index 62e5a3fb7f..43f6f0744b 100644 --- a/weed/mq/topic/topic.go +++ b/weed/mq/topic/topic.go @@ -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)