From 695e3a909c43be623228a4b5a9c9c7cd371f6752 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Wed, 7 Sep 2022 21:51:15 +0500 Subject: [PATCH] avoid data race on currentDiskUsage.maxVolumeCount (#3592) https://github.com/seaweedfs/seaweedfs/issues/3590 --- weed/topology/data_node.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/weed/topology/data_node.go b/weed/topology/data_node.go index 760f14ded..0ce6fdbee 100644 --- a/weed/topology/data_node.go +++ b/weed/topology/data_node.go @@ -9,6 +9,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/storage/needle" "github.com/seaweedfs/seaweedfs/weed/storage/types" "github.com/seaweedfs/seaweedfs/weed/util" + "sync/atomic" ) type DataNode struct { @@ -141,12 +142,13 @@ func (dn *DataNode) AdjustMaxVolumeCounts(maxVolumeCounts map[string]uint32) { } dt := types.ToDiskType(diskType) currentDiskUsage := dn.diskUsages.getOrCreateDisk(dt) - if currentDiskUsage.maxVolumeCount == int64(maxVolumeCount) { + currentDiskUsageMaxVolumeCount := atomic.LoadInt64(¤tDiskUsage.maxVolumeCount) + if currentDiskUsageMaxVolumeCount == int64(maxVolumeCount) { continue } disk := dn.getOrCreateDisk(dt.String()) deltaDiskUsage := deltaDiskUsages.getOrCreateDisk(dt) - deltaDiskUsage.maxVolumeCount = int64(maxVolumeCount) - currentDiskUsage.maxVolumeCount + deltaDiskUsage.maxVolumeCount = int64(maxVolumeCount) - currentDiskUsageMaxVolumeCount disk.UpAdjustDiskUsageDelta(deltaDiskUsages) } }