Browse Source

add locking to volume layout vacuum

pull/753/head
Chris Lu 6 years ago
parent
commit
201c24c110
  1. 4
      weed/topology/topology_event_handling.go
  2. 20
      weed/topology/topology_vacuum.go

4
weed/topology/topology_event_handling.go

@ -40,6 +40,10 @@ func (t *Topology) SetVolumeCapacityFull(volumeInfo storage.VolumeInfo) bool {
if !vl.SetVolumeCapacityFull(volumeInfo.Id) {
return false
}
vl.accessLock.RLock()
defer vl.accessLock.RUnlock()
for _, dn := range vl.vid2location[volumeInfo.Id].list {
if !volumeInfo.ReadOnly {
dn.UpAdjustActiveVolumeCountDelta(-1)

20
weed/topology/topology_vacuum.go

@ -122,7 +122,23 @@ func (t *Topology) Vacuum(garbageThreshold float64, preallocate int64) int {
for _, vl := range c.storageType2VolumeLayout.Items() {
if vl != nil {
volumeLayout := vl.(*VolumeLayout)
vacuumOneVolumeLayout(volumeLayout, c, garbageThreshold, preallocate)
}
}
}
return 0
}
func vacuumOneVolumeLayout(volumeLayout *VolumeLayout, c *Collection, garbageThreshold float64, preallocate int64) {
volumeLayout.accessLock.RLock()
tmpMap := make(map[storage.VolumeId]*VolumeLocationList)
for vid, locationlist := range volumeLayout.vid2location {
tmpMap[vid] = locationlist
}
volumeLayout.accessLock.RUnlock()
for vid, locationlist := range tmpMap {
volumeLayout.accessLock.RLock()
isReadOnly, hasValue := volumeLayout.readonlyVolumes[vid]
@ -140,10 +156,6 @@ func (t *Topology) Vacuum(garbageThreshold float64, preallocate int64) int {
}
}
}
}
}
return 0
}
type VacuumVolumeResult struct {
Result bool

Loading…
Cancel
Save