Browse Source

add sortEcNodesByFreeslotsDecending and sortEcNodesByFreeslotsAscending

addressing https://github.com/chrislusf/seaweedfs/issues/1111
pull/1125/head
Chris Lu 5 years ago
parent
commit
40514c5362
  1. 4
      weed/shell/command_ec_balance.go
  2. 10
      weed/shell/command_ec_common.go
  3. 2
      weed/shell/command_ec_rebuild.go

4
weed/shell/command_ec_balance.go

@ -207,7 +207,7 @@ func doDeduplicateEcShards(ctx context.Context, commandEnv *CommandEnv, collecti
if len(ecNodes) <= 1 { if len(ecNodes) <= 1 {
continue continue
} }
sortEcNodes(ecNodes)
sortEcNodesByFreeslotsAscending(ecNodes)
fmt.Printf("ec shard %d.%d has %d copies, keeping %v\n", vid, shardId, len(ecNodes), ecNodes[0].info.Id) fmt.Printf("ec shard %d.%d has %d copies, keeping %v\n", vid, shardId, len(ecNodes), ecNodes[0].info.Id)
if !applyBalancing { if !applyBalancing {
continue continue
@ -442,7 +442,7 @@ func doBalanceEcRack(ctx context.Context, commandEnv *CommandEnv, ecRack *EcRack
func pickOneEcNodeAndMoveOneShard(ctx context.Context, commandEnv *CommandEnv, expectedTotalEcShards int, existingLocation *EcNode, collection string, vid needle.VolumeId, shardId erasure_coding.ShardId, possibleDestinationEcNodes []*EcNode, applyBalancing bool) error { func pickOneEcNodeAndMoveOneShard(ctx context.Context, commandEnv *CommandEnv, expectedTotalEcShards int, existingLocation *EcNode, collection string, vid needle.VolumeId, shardId erasure_coding.ShardId, possibleDestinationEcNodes []*EcNode, applyBalancing bool) error {
sortEcNodes(possibleDestinationEcNodes)
sortEcNodesByFreeslotsDecending(possibleDestinationEcNodes)
averageShardsPerEcNode := ceilDivide(expectedTotalEcShards, len(possibleDestinationEcNodes)) averageShardsPerEcNode := ceilDivide(expectedTotalEcShards, len(possibleDestinationEcNodes))
for _, destEcNode := range possibleDestinationEcNodes { for _, destEcNode := range possibleDestinationEcNodes {

10
weed/shell/command_ec_common.go

@ -112,12 +112,18 @@ func eachDataNode(topo *master_pb.TopologyInfo, fn func(dc string, rack RackId,
} }
} }
func sortEcNodes(ecNodes []*EcNode) {
func sortEcNodesByFreeslotsDecending(ecNodes []*EcNode) {
sort.Slice(ecNodes, func(i, j int) bool { sort.Slice(ecNodes, func(i, j int) bool {
return ecNodes[i].freeEcSlot > ecNodes[j].freeEcSlot return ecNodes[i].freeEcSlot > ecNodes[j].freeEcSlot
}) })
} }
func sortEcNodesByFreeslotsAscending(ecNodes []*EcNode) {
sort.Slice(ecNodes, func(i, j int) bool {
return ecNodes[i].freeEcSlot < ecNodes[j].freeEcSlot
})
}
type CandidateEcNode struct { type CandidateEcNode struct {
ecNode *EcNode ecNode *EcNode
shardCount int shardCount int
@ -202,7 +208,7 @@ func collectEcNodes(ctx context.Context, commandEnv *CommandEnv, selectedDataCen
totalFreeEcSlots += freeEcSlots totalFreeEcSlots += freeEcSlots
}) })
sortEcNodes(ecNodes)
sortEcNodesByFreeslotsDecending(ecNodes)
return return
} }

2
weed/shell/command_ec_rebuild.go

@ -111,7 +111,7 @@ func rebuildEcVolumes(commandEnv *CommandEnv, allEcNodes []*EcNode, collection s
return fmt.Errorf("ec volume %d is unrepairable with %d shards\n", vid, shardCount) return fmt.Errorf("ec volume %d is unrepairable with %d shards\n", vid, shardCount)
} }
sortEcNodes(allEcNodes)
sortEcNodesByFreeslotsDecending(allEcNodes)
if allEcNodes[0].freeEcSlot < erasure_coding.TotalShardsCount { if allEcNodes[0].freeEcSlot < erasure_coding.TotalShardsCount {
return fmt.Errorf("disk space is not enough") return fmt.Errorf("disk space is not enough")

Loading…
Cancel
Save