Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

adjust replica placement after move

Chris Lue2c741f76f6f
diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go
index 3e36c7fd5b..9a3dbe0a61 100644
--- a/weed/shell/command_volume_balance.go
+++ b/weed/shell/command_volume_balance.go
@@ -40,12 +40,12 @@ func (c *commandVolumeBalance) Help() string {
}
func balanceWritableVolumes(){
- idealWritableVolumes = totalWritableVolumes / numVolumeServers
+ idealWritableVolumeRatio = totalWritableVolumes / totalNumberOfMaxVolumes
for hasMovedOneVolume {
- sort all volume servers ordered by the number of local writable volumes
- pick the volume server B with the highest number of writable volumes y
- for any the volume server A with the number of writable volumes x +1 <= idealWritableVolume {
- if y > idealWritableVolumes and x +1 <= idealWritableVolumes {
+ sort all volume servers ordered by the localWritableVolumeRatio = localWritableVolumes to localVolumeMax
+ pick the volume server B with the highest localWritableVolumeRatio y
+ for any the volume server A with the number of writable volumes x + 1 <= idealWritableVolumeRatio * localVolumeMax {
+ if y > localWritableVolumeRatio {
if B has a writable volume id v that A does not have, and satisfy v replication requirements {
move writable volume v from A to B
}
@@ -242,8 +242,7 @@ func attemptToMoveOneVolume(commandEnv *CommandEnv, volumeReplicas map[uint32][]
}
if _, found := emptyNode.selectedVolumes[v.Id]; !found {
if err = moveVolume(commandEnv, v, fullNode, emptyNode, applyBalancing); err == nil {
- delete(fullNode.selectedVolumes, v.Id)
- emptyNode.selectedVolumes[v.Id] = v
+ adjustAfterMove(v, volumeReplicas, fullNode, emptyNode)
hasMoved = true
break
} else {
@@ -312,3 +311,19 @@ func isGoodMove(placement *super_block.ReplicaPlacement, existingReplicas []*Vol
return true
}
+
+func adjustAfterMove(v *master_pb.VolumeInformationMessage, volumeReplicas map[uint32][]*VolumeReplica, fullNode *Node, emptyNode *Node) {
+ delete(fullNode.selectedVolumes, v.Id)
+ emptyNode.selectedVolumes[v.Id] = v
+ existingReplicas := volumeReplicas[v.Id]
+ for _, replica := range existingReplicas {
+ if replica.location.dataNode.Id == fullNode.info.Id &&
+ replica.location.rack == fullNode.rack &&
+ replica.location.dc == fullNode.dc {
+ replica.location.dc = emptyNode.dc
+ replica.location.rack = emptyNode.rack
+ replica.location.dataNode = emptyNode.info
+ return
+ }
+ }
+}