aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2020-09-23 19:24:16 -0700
committerGitHub <noreply@github.com>2020-09-23 19:24:16 -0700
commitb80a2b3cc9d3613a0095c74474bcac9092a300b6 (patch)
treea3be86a222d5369312447cb3b0c6054cdbf8aa9f
parentf7a0ccb595edb51498aeb61aa0e09ac93228b007 (diff)
parenteecd6b5d35f01823b546adc0a44b28dd60184e30 (diff)
downloadseaweedfs-b80a2b3cc9d3613a0095c74474bcac9092a300b6.tar.xz
seaweedfs-b80a2b3cc9d3613a0095c74474bcac9092a300b6.zip
Merge pull request #1486 from LIBA-S/fix_race_condition
Fix a race condition when handle VolumeLocationList
-rw-r--r--weed/topology/topology_vacuum.go2
-rw-r--r--weed/topology/volume_location_list.go8
2 files changed, 9 insertions, 1 deletions
diff --git a/weed/topology/topology_vacuum.go b/weed/topology/topology_vacuum.go
index 789a01330..1079816fc 100644
--- a/weed/topology/topology_vacuum.go
+++ b/weed/topology/topology_vacuum.go
@@ -165,7 +165,7 @@ func vacuumOneVolumeLayout(grpcDialOption grpc.DialOption, volumeLayout *VolumeL
volumeLayout.accessLock.RLock()
tmpMap := make(map[needle.VolumeId]*VolumeLocationList)
for vid, locationList := range volumeLayout.vid2location {
- tmpMap[vid] = locationList
+ tmpMap[vid] = locationList.Copy()
}
volumeLayout.accessLock.RUnlock()
diff --git a/weed/topology/volume_location_list.go b/weed/topology/volume_location_list.go
index 8905c54b5..6acd70f2f 100644
--- a/weed/topology/volume_location_list.go
+++ b/weed/topology/volume_location_list.go
@@ -18,6 +18,14 @@ func (dnll *VolumeLocationList) String() string {
return fmt.Sprintf("%v", dnll.list)
}
+func (dnll *VolumeLocationList) Copy() *VolumeLocationList {
+ list := make([]*DataNode, len(dnll.list))
+ copy(list, dnll.list)
+ return &VolumeLocationList{
+ list: list,
+ }
+}
+
func (dnll *VolumeLocationList) Head() *DataNode {
//mark first node as master volume
return dnll.list[0]