diff options
| author | Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> | 2022-09-07 21:50:17 +0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-07 09:50:17 -0700 |
| commit | cca45b02a25efd17c99cb656103d9f0140d6a248 (patch) | |
| tree | 0b7a11d882ad05f1fa728f273ff3210836d5f09e /weed/topology/node.go | |
| parent | 9678fc2106d58a80fe130fc1f59eb2d6dbf6e8dc (diff) | |
| download | seaweedfs-cca45b02a25efd17c99cb656103d9f0140d6a248.tar.xz seaweedfs-cca45b02a25efd17c99cb656103d9f0140d6a248.zip | |
avoid data race on calc freeVolumeSlotCount (#3594)
https://github.com/seaweedfs/seaweedfs/issues/3593
Diffstat (limited to 'weed/topology/node.go')
| -rw-r--r-- | weed/topology/node.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/weed/topology/node.go b/weed/topology/node.go index 807cce47c..b964a611f 100644 --- a/weed/topology/node.go +++ b/weed/topology/node.go @@ -10,6 +10,7 @@ import ( "math/rand" "strings" "sync" + "sync/atomic" ) type NodeId string @@ -139,9 +140,10 @@ func (n *NodeImpl) getOrCreateDisk(diskType types.DiskType) *DiskUsageCounts { } func (n *NodeImpl) AvailableSpaceFor(option *VolumeGrowOption) int64 { t := n.getOrCreateDisk(option.DiskType) - freeVolumeSlotCount := t.maxVolumeCount + t.remoteVolumeCount - t.volumeCount - if t.ecShardCount > 0 { - freeVolumeSlotCount = freeVolumeSlotCount - t.ecShardCount/erasure_coding.DataShardsCount - 1 + freeVolumeSlotCount := atomic.LoadInt64(&t.maxVolumeCount) + atomic.LoadInt64(&t.remoteVolumeCount) - atomic.LoadInt64(&t.volumeCount) + ecShardCount := atomic.LoadInt64(&t.ecShardCount) + if ecShardCount > 0 { + freeVolumeSlotCount = freeVolumeSlotCount - ecShardCount/erasure_coding.DataShardsCount - 1 } return freeVolumeSlotCount } |
