use ShouldGrowVolumesByDcAndRack (#6280)

This commit is contained in:
Konstantin Lebedev
2024-11-25 22:30:37 +05:00
committed by GitHub
parent 167b50be88
commit 8836fa19b6
3 changed files with 45 additions and 32 deletions

View File

@@ -365,25 +365,10 @@ func (vl *VolumeLayout) ShouldGrowVolumes() bool {
return writable <= crowded
}
func (vl *VolumeLayout) ShouldGrowVolumesByDataNode(nodeType string, dataNode string) bool {
vl.accessLock.RLock()
writables := make([]needle.VolumeId, len(vl.writables))
copy(writables, vl.writables)
vl.accessLock.RUnlock()
dataNodeId := NodeId(dataNode)
for _, v := range writables {
for _, dn := range vl.vid2location[v].list {
dataNodeFound := false
switch nodeType {
case "DataCenter":
dataNodeFound = dn.GetDataCenter().Id() == dataNodeId
case "Rack":
dataNodeFound = dn.GetRack().Id() == dataNodeId
case "DataNode":
dataNodeFound = dn.Id() == dataNodeId
}
if dataNodeFound {
func (vl *VolumeLayout) ShouldGrowVolumesByDcAndRack(writables *[]needle.VolumeId, dcId NodeId, rackId NodeId) bool {
for _, v := range *writables {
for _, dn := range vl.Lookup(v) {
if dn.GetDataCenter().Id() == dcId && dn.GetRack().Id() == rackId {
if info, err := dn.GetVolumesById(v); err == nil && !vl.isCrowdedVolume(&info) {
return false
}
@@ -399,6 +384,14 @@ func (vl *VolumeLayout) GetWritableVolumeCount() (active, crowded int) {
return len(vl.writables), len(vl.crowded)
}
func (vl *VolumeLayout) CloneWritableVolumes() (writables []needle.VolumeId) {
vl.accessLock.RLock()
writables = make([]needle.VolumeId, len(vl.writables))
copy(writables, vl.writables)
vl.accessLock.RUnlock()
return writables
}
func (vl *VolumeLayout) removeFromWritable(vid needle.VolumeId) bool {
toDeleteIndex := -1
for k, id := range vl.writables {