Browse Source

create new volumes on less occupied disk locations

pull/7349/head
chrislu 23 hours ago
parent
commit
5401605a9f
  1. 13
      weed/storage/disk_location.go
  2. 12
      weed/storage/store.go

13
weed/storage/disk_location.go

@ -386,6 +386,19 @@ func (l *DiskLocation) VolumesLen() int {
return len(l.volumes)
}
func (l *DiskLocation) LocalVolumesLen() int {
l.volumesLock.RLock()
defer l.volumesLock.RUnlock()
count := 0
for _, v := range l.volumes {
if !v.HasRemoteFile() {
count++
}
}
return count
}
func (l *DiskLocation) SetStopping() {
l.volumesLock.Lock()
for _, v := range l.volumes {

12
weed/storage/store.go

@ -165,14 +165,18 @@ func (s *Store) addVolume(vid needle.VolumeId, collection string, needleMapKind
return fmt.Errorf("Volume Id %d already exists!", vid)
}
// Find location and its index
// Find location with lowest local volume count (load balancing)
var location *DiskLocation
var diskId uint32
var minVolCount int = -1
for i, loc := range s.Locations {
if loc.DiskType == diskType && s.hasFreeDiskLocation(loc) {
location = loc
diskId = uint32(i)
break
volCount := loc.LocalVolumesLen()
if location == nil || volCount < minVolCount {
location = loc
diskId = uint32(i)
minVolCount = volCount
}
}
}

Loading…
Cancel
Save