avoid data race on currentDiskUsage.maxVolumeCount (#3592)

https://github.com/seaweedfs/seaweedfs/issues/3590
This commit is contained in:
Konstantin Lebedev 2022-09-07 21:51:15 +05:00 committed by GitHub
parent cca45b02a2
commit 695e3a909c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,6 +9,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/storage/needle" "github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/seaweedfs/seaweedfs/weed/storage/types" "github.com/seaweedfs/seaweedfs/weed/storage/types"
"github.com/seaweedfs/seaweedfs/weed/util" "github.com/seaweedfs/seaweedfs/weed/util"
"sync/atomic"
) )
type DataNode struct { type DataNode struct {
@ -141,12 +142,13 @@ func (dn *DataNode) AdjustMaxVolumeCounts(maxVolumeCounts map[string]uint32) {
} }
dt := types.ToDiskType(diskType) dt := types.ToDiskType(diskType)
currentDiskUsage := dn.diskUsages.getOrCreateDisk(dt) currentDiskUsage := dn.diskUsages.getOrCreateDisk(dt)
if currentDiskUsage.maxVolumeCount == int64(maxVolumeCount) { currentDiskUsageMaxVolumeCount := atomic.LoadInt64(&currentDiskUsage.maxVolumeCount)
if currentDiskUsageMaxVolumeCount == int64(maxVolumeCount) {
continue continue
} }
disk := dn.getOrCreateDisk(dt.String()) disk := dn.getOrCreateDisk(dt.String())
deltaDiskUsage := deltaDiskUsages.getOrCreateDisk(dt) deltaDiskUsage := deltaDiskUsages.getOrCreateDisk(dt)
deltaDiskUsage.maxVolumeCount = int64(maxVolumeCount) - currentDiskUsage.maxVolumeCount deltaDiskUsage.maxVolumeCount = int64(maxVolumeCount) - currentDiskUsageMaxVolumeCount
disk.UpAdjustDiskUsageDelta(deltaDiskUsages) disk.UpAdjustDiskUsageDelta(deltaDiskUsages)
} }
} }