From be5302d9ccbde706df0c7a828308b049cf7dd43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Thu, 19 Oct 2023 13:23:33 +0200 Subject: [PATCH] segment-verify: synchronize refreshing of the nodeAliasMap This part can be called from multiple goroutines, therefore we should bw prepared for concurrent run. Change-Id: I7acf1a29bdb51427d3d03f501b58b190dcf08412 --- cmd/tools/segment-verify/process.go | 4 ++++ cmd/tools/segment-verify/service.go | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/tools/segment-verify/process.go b/cmd/tools/segment-verify/process.go index 149f9f1c9..f9fde00c5 100644 --- a/cmd/tools/segment-verify/process.go +++ b/cmd/tools/segment-verify/process.go @@ -140,8 +140,12 @@ func (service *Service) VerifyBatches(ctx context.Context, batches []*Batch) err // convertAliasToNodeURL converts a node alias to node url, using a cache if needed. func (service *Service) convertAliasToNodeURL(ctx context.Context, alias metabase.NodeAlias) (_ storj.NodeURL, err error) { + service.mu.RLock() nodeURL, ok := service.aliasToNodeURL[alias] + service.mu.RUnlock() if !ok { + service.mu.Lock() + defer service.mu.Unlock() nodeID, ok := service.aliasMap.Node(alias) if !ok { latest, err := service.metabase.LatestNodesAliasMap(ctx) diff --git a/cmd/tools/segment-verify/service.go b/cmd/tools/segment-verify/service.go index e15628c95..04c070a20 100644 --- a/cmd/tools/segment-verify/service.go +++ b/cmd/tools/segment-verify/service.go @@ -10,6 +10,7 @@ import ( "io" "os" "strings" + "sync" "sync/atomic" "time" @@ -94,8 +95,9 @@ type Service struct { verifier Verifier overlay Overlay - aliasMap *metabase.NodeAliasMap + mu sync.RWMutex aliasToNodeURL map[metabase.NodeAlias]storj.NodeURL + aliasMap *metabase.NodeAliasMap priorityNodes NodeAliasSet ignoreNodes NodeAliasSet offlineNodes *nodeAliasExpiringSet