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.
This commit is contained in:
Chris Lu committed 2026-11-30 22:36:21 -08:00
1 parent d8ab2ba06a
commit c4a8f6effe
1 file changed
+27 -3
+27 -3
View File
@@ -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):
}
}
}