aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_volume_balance.go
diff options
context:
space:
mode:
authorthemarkchen <132556106+themarkchen@users.noreply.github.com>2023-05-04 22:35:37 +0800
committerGitHub <noreply@github.com>2023-05-04 07:35:37 -0700
commit7592d013fe83c67d1f9071d513fbfbd2cd17270b (patch)
tree493742cb68c1c2dd57256e8ab607543cee3f399d /weed/shell/command_volume_balance.go
parent6fdff0bb1857da8ce18668518e4ab19e5540b347 (diff)
downloadseaweedfs-7592d013fe83c67d1f9071d513fbfbd2cd17270b.tar.xz
seaweedfs-7592d013fe83c67d1f9071d513fbfbd2cd17270b.zip
fix shell volume.balance bug (#4447)
Diffstat (limited to 'weed/shell/command_volume_balance.go')
-rw-r--r--weed/shell/command_volume_balance.go38
1 files changed, 15 insertions, 23 deletions
diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go
index 1c599b8a0..b2b65d5d2 100644
--- a/weed/shell/command_volume_balance.go
+++ b/weed/shell/command_volume_balance.go
@@ -3,14 +3,15 @@ package shell
import (
"flag"
"fmt"
+ "io"
+ "os"
+ "time"
+
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
"github.com/seaweedfs/seaweedfs/weed/storage/super_block"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
"golang.org/x/exp/slices"
- "io"
- "os"
- "time"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
@@ -371,33 +372,24 @@ func isGoodMove(placement *super_block.ReplicaPlacement, existingReplicas []*Vol
return false
}
}
- dcs, racks := make(map[string]bool), make(map[string]int)
+
+ // existing replicas except the one on sourceNode
+ existingReplicasExceptSourceNode := make([]*VolumeReplica, 0)
for _, replica := range existingReplicas {
if replica.location.dataNode.Id != sourceNode.info.Id {
- dcs[replica.location.DataCenter()] = true
- racks[replica.location.Rack()]++
+ existingReplicasExceptSourceNode = append(existingReplicasExceptSourceNode, replica)
}
}
- dcs[targetNode.dc] = true
- racks[fmt.Sprintf("%s %s", targetNode.dc, targetNode.rack)]++
-
- if len(dcs) != placement.DiffDataCenterCount+1 {
- return false
- }
-
- if len(racks) != placement.DiffRackCount+placement.DiffDataCenterCount+1 {
- return false
+ // target location
+ targetLocation := location{
+ dc: targetNode.dc,
+ rack: targetNode.rack,
+ dataNode: targetNode.info,
}
- for _, sameRackCount := range racks {
- if sameRackCount != placement.SameRackCount+1 {
- return false
- }
- }
-
- return true
-
+ // check if this satisfies replication requirements
+ return satisfyReplicaPlacement(placement, existingReplicasExceptSourceNode, targetLocation)
}
func adjustAfterMove(v *master_pb.VolumeInformationMessage, volumeReplicas map[uint32][]*VolumeReplica, fullNode *Node, emptyNode *Node) {