2019-06-03 09:26:31 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
2022-04-18 02:35:43 +00:00
|
|
|
"golang.org/x/exp/slices"
|
2019-06-03 09:26:31 +00:00
|
|
|
"google.golang.org/grpc"
|
2022-04-18 02:35:43 +00:00
|
|
|
"math"
|
2019-06-03 09:26:31 +00:00
|
|
|
)
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
func moveMountedShardToEcNode(commandEnv *CommandEnv, existingLocation *EcNode, collection string, vid needle.VolumeId, shardId erasure_coding.ShardId, destinationEcNode *EcNode, applyBalancing bool) (err error) {
|
2019-06-03 09:26:31 +00:00
|
|
|
|
2022-08-22 21:12:23 +00:00
|
|
|
if !commandEnv.isLocked() {
|
|
|
|
return fmt.Errorf("lock is lost")
|
|
|
|
}
|
|
|
|
|
2019-06-11 04:32:56 +00:00
|
|
|
copiedShardIds := []uint32{uint32(shardId)}
|
2019-06-03 09:26:31 +00:00
|
|
|
|
2019-06-11 04:32:56 +00:00
|
|
|
if applyBalancing {
|
2019-06-03 09:26:31 +00:00
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
existingServerAddress := pb.NewServerAddressFromDataNode(existingLocation.info)
|
|
|
|
|
2019-06-11 04:32:56 +00:00
|
|
|
// ask destination node to copy shard and the ecx file from source node, and mount it
|
2021-09-13 05:47:52 +00:00
|
|
|
copiedShardIds, err = oneServerCopyAndMountEcShardsFromSource(commandEnv.option.GrpcDialOption, destinationEcNode, []uint32{uint32(shardId)}, vid, collection, existingServerAddress)
|
2019-06-11 04:32:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-03 09:26:31 +00:00
|
|
|
|
2019-06-11 04:32:56 +00:00
|
|
|
// unmount the to be deleted shards
|
2021-09-13 05:47:52 +00:00
|
|
|
err = unmountEcShards(commandEnv.option.GrpcDialOption, vid, existingServerAddress, copiedShardIds)
|
2019-06-11 04:32:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ask source node to delete the shard, and maybe the ecx file
|
2021-09-13 05:47:52 +00:00
|
|
|
err = sourceServerDeleteEcShards(commandEnv.option.GrpcDialOption, collection, vid, existingServerAddress, copiedShardIds)
|
2019-06-11 04:32:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("moved ec shard %d.%d %s => %s\n", vid, shardId, existingLocation.info.Id, destinationEcNode.info.Id)
|
2019-06-03 09:26:31 +00:00
|
|
|
|
2019-06-06 06:20:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 04:32:56 +00:00
|
|
|
destinationEcNode.addEcVolumeShards(vid, collection, copiedShardIds)
|
|
|
|
existingLocation.deleteEcVolumeShards(vid, copiedShardIds)
|
2019-06-06 06:20:26 +00:00
|
|
|
|
|
|
|
return nil
|
2019-06-03 09:26:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
func oneServerCopyAndMountEcShardsFromSource(grpcDialOption grpc.DialOption,
|
2019-12-25 00:52:21 +00:00
|
|
|
targetServer *EcNode, shardIdsToCopy []uint32,
|
2021-09-13 05:47:52 +00:00
|
|
|
volumeId needle.VolumeId, collection string, existingLocation pb.ServerAddress) (copiedShardIds []uint32, err error) {
|
2019-06-03 09:26:31 +00:00
|
|
|
|
|
|
|
fmt.Printf("allocate %d.%v %s => %s\n", volumeId, shardIdsToCopy, existingLocation, targetServer.info.Id)
|
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
targetAddress := pb.NewServerAddressFromDataNode(targetServer.info)
|
2021-12-26 08:15:03 +00:00
|
|
|
err = operation.WithVolumeServerClient(false, targetAddress, grpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
|
2019-06-03 09:26:31 +00:00
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
if targetAddress != existingLocation {
|
2019-06-03 09:26:31 +00:00
|
|
|
|
|
|
|
fmt.Printf("copy %d.%v %s => %s\n", volumeId, shardIdsToCopy, existingLocation, targetServer.info.Id)
|
2020-02-26 05:50:12 +00:00
|
|
|
_, copyErr := volumeServerClient.VolumeEcShardsCopy(context.Background(), &volume_server_pb.VolumeEcShardsCopyRequest{
|
2019-06-03 09:26:31 +00:00
|
|
|
VolumeId: uint32(volumeId),
|
|
|
|
Collection: collection,
|
|
|
|
ShardIds: shardIdsToCopy,
|
|
|
|
CopyEcxFile: true,
|
2019-12-23 20:48:20 +00:00
|
|
|
CopyEcjFile: true,
|
2019-12-28 20:44:59 +00:00
|
|
|
CopyVifFile: true,
|
2021-09-13 05:47:52 +00:00
|
|
|
SourceDataNode: string(existingLocation),
|
2019-06-03 09:26:31 +00:00
|
|
|
})
|
|
|
|
if copyErr != nil {
|
2019-06-03 17:38:21 +00:00
|
|
|
return fmt.Errorf("copy %d.%v %s => %s : %v\n", volumeId, shardIdsToCopy, existingLocation, targetServer.info.Id, copyErr)
|
2019-06-03 09:26:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("mount %d.%v on %s\n", volumeId, shardIdsToCopy, targetServer.info.Id)
|
2020-02-26 05:50:12 +00:00
|
|
|
_, mountErr := volumeServerClient.VolumeEcShardsMount(context.Background(), &volume_server_pb.VolumeEcShardsMountRequest{
|
2019-06-03 09:26:31 +00:00
|
|
|
VolumeId: uint32(volumeId),
|
|
|
|
Collection: collection,
|
|
|
|
ShardIds: shardIdsToCopy,
|
|
|
|
})
|
|
|
|
if mountErr != nil {
|
2019-06-03 17:38:21 +00:00
|
|
|
return fmt.Errorf("mount %d.%v on %s : %v\n", volumeId, shardIdsToCopy, targetServer.info.Id, mountErr)
|
2019-06-03 09:26:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
if targetAddress != existingLocation {
|
2019-06-03 09:26:31 +00:00
|
|
|
copiedShardIds = shardIdsToCopy
|
|
|
|
glog.V(0).Infof("%s ec volume %d deletes shards %+v", existingLocation, volumeId, copiedShardIds)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-11 04:32:56 +00:00
|
|
|
func eachDataNode(topo *master_pb.TopologyInfo, fn func(dc string, rack RackId, dn *master_pb.DataNodeInfo)) {
|
2019-06-03 09:26:31 +00:00
|
|
|
for _, dc := range topo.DataCenterInfos {
|
|
|
|
for _, rack := range dc.RackInfos {
|
|
|
|
for _, dn := range rack.DataNodeInfos {
|
2019-06-11 04:32:56 +00:00
|
|
|
fn(dc.Id, RackId(rack.Id), dn)
|
2019-06-03 09:26:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 19:06:48 +00:00
|
|
|
func sortEcNodesByFreeslotsDescending(ecNodes []*EcNode) {
|
2023-09-18 23:12:50 +00:00
|
|
|
slices.SortFunc(ecNodes, func(a, b *EcNode) bool {
|
|
|
|
return a.freeEcSlot > b.freeEcSlot
|
2019-06-03 09:26:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-12 21:47:36 +00:00
|
|
|
func sortEcNodesByFreeslotsAscending(ecNodes []*EcNode) {
|
2023-09-18 23:12:50 +00:00
|
|
|
slices.SortFunc(ecNodes, func(a, b *EcNode) bool {
|
|
|
|
return a.freeEcSlot < b.freeEcSlot
|
2019-11-12 21:47:36 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-11 04:32:56 +00:00
|
|
|
type CandidateEcNode struct {
|
|
|
|
ecNode *EcNode
|
|
|
|
shardCount int
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the index node changed the freeEcSlot, need to keep every EcNode still sorted
|
|
|
|
func ensureSortedEcNodes(data []*CandidateEcNode, index int, lessThan func(i, j int) bool) {
|
|
|
|
for i := index - 1; i >= 0; i-- {
|
|
|
|
if lessThan(i+1, i) {
|
|
|
|
swap(data, i, i+1)
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := index + 1; i < len(data); i++ {
|
|
|
|
if lessThan(i, i-1) {
|
|
|
|
swap(data, i, i-1)
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func swap(data []*CandidateEcNode, i, j int) {
|
|
|
|
t := data[i]
|
|
|
|
data[i] = data[j]
|
|
|
|
data[j] = t
|
|
|
|
}
|
|
|
|
|
2019-06-03 09:26:31 +00:00
|
|
|
func countShards(ecShardInfos []*master_pb.VolumeEcShardInformationMessage) (count int) {
|
|
|
|
for _, ecShardInfo := range ecShardInfos {
|
|
|
|
shardBits := erasure_coding.ShardBits(ecShardInfo.EcIndexBits)
|
|
|
|
count += shardBits.ShardIdCount()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-16 10:47:02 +00:00
|
|
|
func countFreeShardSlots(dn *master_pb.DataNodeInfo, diskType types.DiskType) (count int) {
|
|
|
|
if dn.DiskInfos == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
diskInfo := dn.DiskInfos[string(diskType)]
|
|
|
|
if diskInfo == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2022-02-08 09:51:13 +00:00
|
|
|
return int(diskInfo.MaxVolumeCount-diskInfo.VolumeCount)*erasure_coding.DataShardsCount - countShards(diskInfo.EcShardInfos)
|
2019-06-03 09:26:31 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 04:32:56 +00:00
|
|
|
type RackId string
|
|
|
|
type EcNodeId string
|
|
|
|
|
2019-06-03 09:26:31 +00:00
|
|
|
type EcNode struct {
|
|
|
|
info *master_pb.DataNodeInfo
|
2019-06-07 07:25:01 +00:00
|
|
|
dc string
|
2019-06-11 04:32:56 +00:00
|
|
|
rack RackId
|
2019-06-03 09:26:31 +00:00
|
|
|
freeEcSlot int
|
|
|
|
}
|
|
|
|
|
2020-09-15 06:47:11 +00:00
|
|
|
func (ecNode *EcNode) localShardIdCount(vid uint32) int {
|
2021-02-16 10:47:02 +00:00
|
|
|
for _, diskInfo := range ecNode.info.DiskInfos {
|
|
|
|
for _, ecShardInfo := range diskInfo.EcShardInfos {
|
|
|
|
if vid == ecShardInfo.Id {
|
|
|
|
shardBits := erasure_coding.ShardBits(ecShardInfo.EcIndexBits)
|
|
|
|
return shardBits.ShardIdCount()
|
|
|
|
}
|
2020-09-15 06:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-06-11 04:32:56 +00:00
|
|
|
type EcRack struct {
|
|
|
|
ecNodes map[EcNodeId]*EcNode
|
|
|
|
freeEcSlot int
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
func collectEcNodes(commandEnv *CommandEnv, selectedDataCenter string) (ecNodes []*EcNode, totalFreeEcSlots int, err error) {
|
2019-06-03 09:26:31 +00:00
|
|
|
|
|
|
|
// list all possible locations
|
2021-02-22 08:28:42 +00:00
|
|
|
// collect topology information
|
2022-02-08 08:53:55 +00:00
|
|
|
topologyInfo, _, err := collectTopologyInfo(commandEnv, 0)
|
2019-06-03 09:26:31 +00:00
|
|
|
if err != nil {
|
2021-02-22 08:28:42 +00:00
|
|
|
return
|
2019-06-03 09:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// find out all volume servers with one slot left.
|
2021-02-22 08:28:42 +00:00
|
|
|
ecNodes, totalFreeEcSlots = collectEcVolumeServersByDc(topologyInfo, selectedDataCenter)
|
2020-09-15 06:47:11 +00:00
|
|
|
|
2022-09-14 19:06:48 +00:00
|
|
|
sortEcNodesByFreeslotsDescending(ecNodes)
|
2020-09-15 06:47:11 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func collectEcVolumeServersByDc(topo *master_pb.TopologyInfo, selectedDataCenter string) (ecNodes []*EcNode, totalFreeEcSlots int) {
|
|
|
|
eachDataNode(topo, func(dc string, rack RackId, dn *master_pb.DataNodeInfo) {
|
2019-06-11 04:32:56 +00:00
|
|
|
if selectedDataCenter != "" && selectedDataCenter != dc {
|
|
|
|
return
|
|
|
|
}
|
2019-11-12 17:33:51 +00:00
|
|
|
|
2021-02-16 10:47:02 +00:00
|
|
|
freeEcSlots := countFreeShardSlots(dn, types.HardDriveType)
|
2019-11-12 17:33:51 +00:00
|
|
|
ecNodes = append(ecNodes, &EcNode{
|
|
|
|
info: dn,
|
|
|
|
dc: dc,
|
|
|
|
rack: rack,
|
|
|
|
freeEcSlot: int(freeEcSlots),
|
|
|
|
})
|
|
|
|
totalFreeEcSlots += freeEcSlots
|
2019-06-03 09:26:31 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
func sourceServerDeleteEcShards(grpcDialOption grpc.DialOption, collection string, volumeId needle.VolumeId, sourceLocation pb.ServerAddress, toBeDeletedShardIds []uint32) error {
|
2019-06-03 09:26:31 +00:00
|
|
|
|
|
|
|
fmt.Printf("delete %d.%v from %s\n", volumeId, toBeDeletedShardIds, sourceLocation)
|
|
|
|
|
2021-12-26 08:15:03 +00:00
|
|
|
return operation.WithVolumeServerClient(false, sourceLocation, grpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
|
2020-02-26 05:50:12 +00:00
|
|
|
_, deleteErr := volumeServerClient.VolumeEcShardsDelete(context.Background(), &volume_server_pb.VolumeEcShardsDeleteRequest{
|
2019-06-03 09:26:31 +00:00
|
|
|
VolumeId: uint32(volumeId),
|
|
|
|
Collection: collection,
|
|
|
|
ShardIds: toBeDeletedShardIds,
|
|
|
|
})
|
|
|
|
return deleteErr
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
func unmountEcShards(grpcDialOption grpc.DialOption, volumeId needle.VolumeId, sourceLocation pb.ServerAddress, toBeUnmountedhardIds []uint32) error {
|
2019-06-03 09:26:31 +00:00
|
|
|
|
|
|
|
fmt.Printf("unmount %d.%v from %s\n", volumeId, toBeUnmountedhardIds, sourceLocation)
|
|
|
|
|
2021-12-26 08:15:03 +00:00
|
|
|
return operation.WithVolumeServerClient(false, sourceLocation, grpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
|
2020-02-26 05:50:12 +00:00
|
|
|
_, deleteErr := volumeServerClient.VolumeEcShardsUnmount(context.Background(), &volume_server_pb.VolumeEcShardsUnmountRequest{
|
2019-06-03 09:26:31 +00:00
|
|
|
VolumeId: uint32(volumeId),
|
|
|
|
ShardIds: toBeUnmountedhardIds,
|
|
|
|
})
|
|
|
|
return deleteErr
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
func mountEcShards(grpcDialOption grpc.DialOption, collection string, volumeId needle.VolumeId, sourceLocation pb.ServerAddress, toBeMountedhardIds []uint32) error {
|
2019-06-03 09:26:31 +00:00
|
|
|
|
|
|
|
fmt.Printf("mount %d.%v on %s\n", volumeId, toBeMountedhardIds, sourceLocation)
|
|
|
|
|
2021-12-26 08:15:03 +00:00
|
|
|
return operation.WithVolumeServerClient(false, sourceLocation, grpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
|
2020-02-26 05:50:12 +00:00
|
|
|
_, mountErr := volumeServerClient.VolumeEcShardsMount(context.Background(), &volume_server_pb.VolumeEcShardsMountRequest{
|
2019-06-03 09:26:31 +00:00
|
|
|
VolumeId: uint32(volumeId),
|
|
|
|
Collection: collection,
|
|
|
|
ShardIds: toBeMountedhardIds,
|
|
|
|
})
|
|
|
|
return mountErr
|
|
|
|
})
|
|
|
|
}
|
2019-06-11 04:32:56 +00:00
|
|
|
|
|
|
|
func ceilDivide(total, n int) int {
|
|
|
|
return int(math.Ceil(float64(total) / float64(n)))
|
|
|
|
}
|
|
|
|
|
|
|
|
func findEcVolumeShards(ecNode *EcNode, vid needle.VolumeId) erasure_coding.ShardBits {
|
|
|
|
|
2021-02-16 13:13:48 +00:00
|
|
|
if diskInfo, found := ecNode.info.DiskInfos[string(types.HardDriveType)]; found {
|
|
|
|
for _, shardInfo := range diskInfo.EcShardInfos {
|
|
|
|
if needle.VolumeId(shardInfo.Id) == vid {
|
|
|
|
return erasure_coding.ShardBits(shardInfo.EcIndexBits)
|
|
|
|
}
|
2019-06-11 04:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ecNode *EcNode) addEcVolumeShards(vid needle.VolumeId, collection string, shardIds []uint32) *EcNode {
|
|
|
|
|
|
|
|
foundVolume := false
|
2021-02-16 13:33:38 +00:00
|
|
|
diskInfo, found := ecNode.info.DiskInfos[string(types.HardDriveType)]
|
|
|
|
if found {
|
2021-02-16 13:13:48 +00:00
|
|
|
for _, shardInfo := range diskInfo.EcShardInfos {
|
|
|
|
if needle.VolumeId(shardInfo.Id) == vid {
|
|
|
|
oldShardBits := erasure_coding.ShardBits(shardInfo.EcIndexBits)
|
|
|
|
newShardBits := oldShardBits
|
|
|
|
for _, shardId := range shardIds {
|
|
|
|
newShardBits = newShardBits.AddShardId(erasure_coding.ShardId(shardId))
|
|
|
|
}
|
|
|
|
shardInfo.EcIndexBits = uint32(newShardBits)
|
|
|
|
ecNode.freeEcSlot -= newShardBits.ShardIdCount() - oldShardBits.ShardIdCount()
|
|
|
|
foundVolume = true
|
|
|
|
break
|
2019-06-11 04:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-16 13:33:38 +00:00
|
|
|
} else {
|
|
|
|
diskInfo = &master_pb.DiskInfo{
|
|
|
|
Type: string(types.HardDriveType),
|
|
|
|
}
|
|
|
|
ecNode.info.DiskInfos[string(types.HardDriveType)] = diskInfo
|
2019-06-11 04:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !foundVolume {
|
|
|
|
var newShardBits erasure_coding.ShardBits
|
|
|
|
for _, shardId := range shardIds {
|
|
|
|
newShardBits = newShardBits.AddShardId(erasure_coding.ShardId(shardId))
|
|
|
|
}
|
2021-02-16 10:47:02 +00:00
|
|
|
diskInfo.EcShardInfos = append(diskInfo.EcShardInfos, &master_pb.VolumeEcShardInformationMessage{
|
2019-06-11 04:32:56 +00:00
|
|
|
Id: uint32(vid),
|
|
|
|
Collection: collection,
|
|
|
|
EcIndexBits: uint32(newShardBits),
|
2021-02-16 10:47:02 +00:00
|
|
|
DiskType: string(types.HardDriveType),
|
2019-06-11 04:32:56 +00:00
|
|
|
})
|
|
|
|
ecNode.freeEcSlot -= len(shardIds)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ecNode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ecNode *EcNode) deleteEcVolumeShards(vid needle.VolumeId, shardIds []uint32) *EcNode {
|
|
|
|
|
2021-02-16 13:13:48 +00:00
|
|
|
if diskInfo, found := ecNode.info.DiskInfos[string(types.HardDriveType)]; found {
|
|
|
|
for _, shardInfo := range diskInfo.EcShardInfos {
|
|
|
|
if needle.VolumeId(shardInfo.Id) == vid {
|
|
|
|
oldShardBits := erasure_coding.ShardBits(shardInfo.EcIndexBits)
|
|
|
|
newShardBits := oldShardBits
|
|
|
|
for _, shardId := range shardIds {
|
|
|
|
newShardBits = newShardBits.RemoveShardId(erasure_coding.ShardId(shardId))
|
|
|
|
}
|
|
|
|
shardInfo.EcIndexBits = uint32(newShardBits)
|
|
|
|
ecNode.freeEcSlot -= newShardBits.ShardIdCount() - oldShardBits.ShardIdCount()
|
2019-06-11 04:32:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ecNode
|
|
|
|
}
|
|
|
|
|
|
|
|
func groupByCount(data []*EcNode, identifierFn func(*EcNode) (id string, count int)) map[string]int {
|
|
|
|
countMap := make(map[string]int)
|
|
|
|
for _, d := range data {
|
|
|
|
id, count := identifierFn(d)
|
|
|
|
countMap[id] += count
|
|
|
|
}
|
|
|
|
return countMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func groupBy(data []*EcNode, identifierFn func(*EcNode) (id string)) map[string][]*EcNode {
|
|
|
|
groupMap := make(map[string][]*EcNode)
|
|
|
|
for _, d := range data {
|
|
|
|
id := identifierFn(d)
|
|
|
|
groupMap[id] = append(groupMap[id], d)
|
|
|
|
}
|
|
|
|
return groupMap
|
|
|
|
}
|