Browse Source

Merge pull request #1486 from LIBA-S/fix_race_condition

Fix a race condition when handle VolumeLocationList
pull/1502/head
Chris Lu 4 years ago
committed by GitHub
parent
commit
b80a2b3cc9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      weed/topology/topology_vacuum.go
  2. 8
      weed/topology/volume_location_list.go

2
weed/topology/topology_vacuum.go

@ -165,7 +165,7 @@ func vacuumOneVolumeLayout(grpcDialOption grpc.DialOption, volumeLayout *VolumeL
volumeLayout.accessLock.RLock() volumeLayout.accessLock.RLock()
tmpMap := make(map[needle.VolumeId]*VolumeLocationList) tmpMap := make(map[needle.VolumeId]*VolumeLocationList)
for vid, locationList := range volumeLayout.vid2location { for vid, locationList := range volumeLayout.vid2location {
tmpMap[vid] = locationList
tmpMap[vid] = locationList.Copy()
} }
volumeLayout.accessLock.RUnlock() volumeLayout.accessLock.RUnlock()

8
weed/topology/volume_location_list.go

@ -18,6 +18,14 @@ func (dnll *VolumeLocationList) String() string {
return fmt.Sprintf("%v", dnll.list) 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 { func (dnll *VolumeLocationList) Head() *DataNode {
//mark first node as master volume //mark first node as master volume
return dnll.list[0] return dnll.list[0]

Loading…
Cancel
Save