avoid data race on calc freeVolumeSlotCount (#3594)

https://github.com/seaweedfs/seaweedfs/issues/3593
This commit is contained in:
Konstantin Lebedev
2022-09-07 21:50:17 +05:00
committed by GitHub
parent 9678fc2106
commit cca45b02a2

View File

@@ -10,6 +10,7 @@ import (
"math/rand" "math/rand"
"strings" "strings"
"sync" "sync"
"sync/atomic"
) )
type NodeId string type NodeId string
@@ -139,9 +140,10 @@ func (n *NodeImpl) getOrCreateDisk(diskType types.DiskType) *DiskUsageCounts {
} }
func (n *NodeImpl) AvailableSpaceFor(option *VolumeGrowOption) int64 { func (n *NodeImpl) AvailableSpaceFor(option *VolumeGrowOption) int64 {
t := n.getOrCreateDisk(option.DiskType) t := n.getOrCreateDisk(option.DiskType)
freeVolumeSlotCount := t.maxVolumeCount + t.remoteVolumeCount - t.volumeCount freeVolumeSlotCount := atomic.LoadInt64(&t.maxVolumeCount) + atomic.LoadInt64(&t.remoteVolumeCount) - atomic.LoadInt64(&t.volumeCount)
if t.ecShardCount > 0 { ecShardCount := atomic.LoadInt64(&t.ecShardCount)
freeVolumeSlotCount = freeVolumeSlotCount - t.ecShardCount/erasure_coding.DataShardsCount - 1 if ecShardCount > 0 {
freeVolumeSlotCount = freeVolumeSlotCount - ecShardCount/erasure_coding.DataShardsCount - 1
} }
return freeVolumeSlotCount return freeVolumeSlotCount
} }