From 803ca3c9589ce11d1799ded47bce25c58f179d85 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Thu, 1 Sep 2022 21:01:47 +0500 Subject: [PATCH] avoid data race on doSubscribeToOneFiler/ma.filer.UniqueFilerEpoch (#3566) https://github.com/seaweedfs/seaweedfs/issues/3565 --- weed/filer/meta_aggregator.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/weed/filer/meta_aggregator.go b/weed/filer/meta_aggregator.go index d384c2c38..fbc163442 100644 --- a/weed/filer/meta_aggregator.go +++ b/weed/filer/meta_aggregator.go @@ -9,6 +9,7 @@ import ( "io" "strings" "sync" + "sync/atomic" "time" "google.golang.org/grpc" @@ -194,13 +195,13 @@ func (ma *MetaAggregator) doSubscribeToOneFiler(f *Filer, self pb.ServerAddress, err = pb.WithFilerClient(true, peer, ma.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - ma.filer.UniqueFilerEpoch++ + atomic.AddInt32(&ma.filer.UniqueFilerEpoch, 1) stream, err := client.SubscribeLocalMetadata(ctx, &filer_pb.SubscribeMetadataRequest{ ClientName: "filer:" + string(self), PathPrefix: "/", SinceNs: lastTsNs, ClientId: ma.filer.UniqueFilerId, - ClientEpoch: ma.filer.UniqueFilerEpoch, + ClientEpoch: atomic.LoadInt32(&ma.filer.UniqueFilerEpoch), }) if err != nil { return fmt.Errorf("subscribe: %v", err)