aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_volume_fix_replication.go
diff options
context:
space:
mode:
authorMax Denushev <mdenushev@ya.ru>2024-09-26 18:34:13 +0300
committerGitHub <noreply@github.com>2024-09-26 08:34:13 -0700
commitf1e700ce2f37a702eb33c2294cb08e638a74c4ea (patch)
treeb2d5b6a0855a005e7048d9659e5b763bb747c41e /weed/shell/command_volume_fix_replication.go
parentae8c6d95a61b6ada7f7676188aab1d81d4308df7 (diff)
downloadseaweedfs-f1e700ce2f37a702eb33c2294cb08e638a74c4ea.tar.xz
seaweedfs-f1e700ce2f37a702eb33c2294cb08e638a74c4ea.zip
Fix/copy before delete replication (#6064)
* fix(shell): volume.fix.replication misplaced volumes unsatisfying replication factor * fix(shell): simplify replication check * fix(shell): add test for satisfyReplicaCurrentLocation
Diffstat (limited to 'weed/shell/command_volume_fix_replication.go')
-rw-r--r--weed/shell/command_volume_fix_replication.go23
1 files changed, 22 insertions, 1 deletions
diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.go
index 074931f40..97b06adb5 100644
--- a/weed/shell/command_volume_fix_replication.go
+++ b/weed/shell/command_volume_fix_replication.go
@@ -99,7 +99,7 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv,
replica := replicas[0]
replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(replica.info.ReplicaPlacement))
switch {
- case replicaPlacement.GetCopyCount() > len(replicas):
+ case replicaPlacement.GetCopyCount() > len(replicas) || !satisfyReplicaCurrentLocation(replicaPlacement, replicas):
underReplicatedVolumeIds = append(underReplicatedVolumeIds, vid)
case isMisplaced(replicas, replicaPlacement):
misplacedVolumeIds = append(misplacedVolumeIds, vid)
@@ -377,6 +377,27 @@ func keepDataNodesSorted(dataNodes []location, diskType types.DiskType) {
})
}
+func satisfyReplicaCurrentLocation(replicaPlacement *super_block.ReplicaPlacement, replicas []*VolumeReplica) bool {
+ existingDataCenters, existingRacks, _ := countReplicas(replicas)
+
+ if replicaPlacement.DiffDataCenterCount+1 > len(existingDataCenters) {
+ return false
+ }
+ if replicaPlacement.DiffRackCount+1 > len(existingRacks) {
+ return false
+ }
+ if replicaPlacement.SameRackCount > 0 {
+ foundSatisfyRack := false
+ for _, rackCount := range existingRacks {
+ if rackCount >= replicaPlacement.SameRackCount+1 {
+ foundSatisfyRack = true
+ }
+ }
+ return foundSatisfyRack
+ }
+ return true
+}
+
/*
if on an existing data node {
return false