Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

MaybeShutdownLocalPartition refactor

chrisluf249f831b149
diff --git a/weed/mq/topic/local_partition.go b/weed/mq/topic/local_partition.go
index 53324d846d..9bedc5a156 100644
--- a/weed/mq/topic/local_partition.go
+++ b/weed/mq/topic/local_partition.go
@@ -179,28 +179,28 @@ func (p *LocalPartition) MaybeConnectToFollowers(initMessage *mq_pb.PublishMessa
}
func (p *LocalPartition) MaybeShutdownLocalPartition() (hasShutdown bool) {
- if p.canShutdownLocalPartition() {
- if p.FollowerStream != nil {
- // send close to the follower
- if followErr := p.FollowerStream.Send(&mq_pb.PublishFollowMeRequest{
- Message: &mq_pb.PublishFollowMeRequest_Close{
- Close: &mq_pb.PublishFollowMeRequest_CloseMessage{},
- },
- }); followErr != nil {
- glog.Errorf("Error closing follower stream: %v", followErr)
- }
- println("closing grpcConnection to follower")
- p.FollowerGrpcConnection.Close()
- }
+ if !p.Publishers.IsEmpty() {
+ return
}
- return
-}
+ if !p.Subscribers.IsEmpty() {
+ return
+ }
+ p.LogBuffer.ShutdownLogBuffer()
-func (p *LocalPartition) canShutdownLocalPartition() (hasShutdown bool) {
- if p.Publishers.IsEmpty() && p.Subscribers.IsEmpty() {
- p.LogBuffer.ShutdownLogBuffer()
- hasShutdown = true
+ if p.FollowerStream != nil {
+ // send close to the follower
+ if followErr := p.FollowerStream.Send(&mq_pb.PublishFollowMeRequest{
+ Message: &mq_pb.PublishFollowMeRequest_Close{
+ Close: &mq_pb.PublishFollowMeRequest_CloseMessage{},
+ },
+ }); followErr != nil {
+ glog.Errorf("Error closing follower stream: %v", followErr)
+ }
+ glog.V(4).Infof("closing grpcConnection to follower")
+ p.FollowerGrpcConnection.Close()
+ p.FollowerStream = nil
}
+
return
}