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): + } } }