From c4a8f6effe7c30be24dfd21f609429c6bc21de6b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 30 Nov 2026 19:37:04 -0800 Subject: [PATCH] mq broker: report an ended generation until a settled balancer takes it A broker reported a broken pair once. When the lost broker was also the balancer, the report failed and the partition stayed at a sealed epoch nobody would serve. The report is now retried with backoff until a balancer takes it, and a balancer takes reports only after its settle window, so the new pair is picked from every live broker rather than the few that reconnected first. --- weed/mq/broker/broker_grpc_generation.go | 30 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/weed/mq/broker/broker_grpc_generation.go b/weed/mq/broker/broker_grpc_generation.go index 34297c89a0..9aa2fc0583 100644 --- a/weed/mq/broker/broker_grpc_generation.go +++ b/weed/mq/broker/broker_grpc_generation.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "time" "github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/mq/pub_balancer" @@ -25,6 +26,10 @@ func (b *MessageQueueBroker) EndPartitionGeneration(ctx context.Context, req *mq return resp, err } + if !b.balancerSettled() { + // a new pair is picked from the brokers it has heard from, so wait until all have reconnected + return nil, status.Error(codes.Unavailable, "broker balancer is still settling") + } b.generationLock.Lock() defer b.generationLock.Unlock() t := topic.FromPbTopic(req.Topic) @@ -81,13 +86,32 @@ func (b *MessageQueueBroker) sealAndReportGeneration(ctx context.Context, t topi glog.Warningf("seal topic %s partition %v epoch %d: %v", t, p, epoch, err) } } - _, err := b.EndPartitionGeneration(ctx, &mq_pb.EndPartitionGenerationRequest{ + go b.reportGenerationEnded(t, p, epoch) +} + +// reportGenerationEnded retries until a balancer takes the report: the lost broker +// may have been the balancer, and the partition stays unserved until one does. +func (b *MessageQueueBroker) reportGenerationEnded(t topic.Topic, p topic.Partition, epoch int64) { + req := &mq_pb.EndPartitionGenerationRequest{ Topic: t.ToPbTopic(), Partition: p.ToPbPartition(), Epoch: epoch, Broker: string(b.option.BrokerAddress()), - }) - if err != nil { + } + stop := context.Background().Done() + if b.ctx != nil { + stop = b.ctx.Done() + } + for wait := time.Second; ; wait = min(2*wait, 10*time.Second) { + _, err := b.EndPartitionGeneration(context.Background(), req) + if err == nil { + return + } glog.Warningf("report topic %s partition %v epoch %d ended: %v", t, p, epoch, err) + select { + case <-stop: + return + case <-time.After(wait): + } } }