1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-07-06 17:17:25 +02:00

add error checking

This commit is contained in:
Chris Lu 2019-05-05 21:58:46 -07:00
parent 89f97777d9
commit 0df6346611

View file

@ -81,12 +81,14 @@ func (c *commandVolumeBalance) Do(args []string, commandEnv *commandEnv, writer
if len(volumeServers) < 2 { if len(volumeServers) < 2 {
continue continue
} }
balanceVolumeServers(commandEnv, volumeServers, resp.VolumeSizeLimitMb*1024*1024, *collection, *applyBalancing) if err = balanceVolumeServers(commandEnv, volumeServers, resp.VolumeSizeLimitMb*1024*1024, *collection, *applyBalancing); err != nil {
return err
}
} }
return nil return nil
} }
func balanceVolumeServers(commandEnv *commandEnv, dataNodeInfos []*master_pb.DataNodeInfo, volumeSizeLimit uint64, collection string, applyBalancing bool) { func balanceVolumeServers(commandEnv *commandEnv, dataNodeInfos []*master_pb.DataNodeInfo, volumeSizeLimit uint64, collection string, applyBalancing bool) error {
var nodes []*Node var nodes []*Node
for _, dn := range dataNodeInfos { for _, dn := range dataNodeInfos {
nodes = append(nodes, &Node{ nodes = append(nodes, &Node{
@ -105,7 +107,9 @@ func balanceVolumeServers(commandEnv *commandEnv, dataNodeInfos []*master_pb.Dat
return !v.ReadOnly && v.Size < volumeSizeLimit return !v.ReadOnly && v.Size < volumeSizeLimit
}) })
} }
balanceSelectedVolume(commandEnv, nodes, sortWritableVolumes, applyBalancing) if err := balanceSelectedVolume(commandEnv, nodes, sortWritableVolumes, applyBalancing); err != nil {
return err
}
// balance readable volumes // balance readable volumes
for _, n := range nodes { for _, n := range nodes {
@ -118,7 +122,11 @@ func balanceVolumeServers(commandEnv *commandEnv, dataNodeInfos []*master_pb.Dat
return v.ReadOnly || v.Size >= volumeSizeLimit return v.ReadOnly || v.Size >= volumeSizeLimit
}) })
} }
balanceSelectedVolume(commandEnv, nodes, sortReadOnlyVolumes, applyBalancing) if err := balanceSelectedVolume(commandEnv, nodes, sortReadOnlyVolumes, applyBalancing); err != nil {
return err
}
return nil
} }
func collectVolumeServersByType(t *master_pb.TopologyInfo) (typeToNodes map[uint64][]*master_pb.DataNodeInfo) { func collectVolumeServersByType(t *master_pb.TopologyInfo) (typeToNodes map[uint64][]*master_pb.DataNodeInfo) {
@ -150,7 +158,7 @@ func sortReadOnlyVolumes(volumes []*master_pb.VolumeInformationMessage) {
}) })
} }
func balanceSelectedVolume(commandEnv *commandEnv, nodes []*Node, sortCandidatesFn func(volumes []*master_pb.VolumeInformationMessage), applyBalancing bool) { func balanceSelectedVolume(commandEnv *commandEnv, nodes []*Node, sortCandidatesFn func(volumes []*master_pb.VolumeInformationMessage), applyBalancing bool) error {
selectedVolumeCount := 0 selectedVolumeCount := 0
for _, dn := range nodes { for _, dn := range nodes {
selectedVolumeCount += len(dn.selectedVolumes) selectedVolumeCount += len(dn.selectedVolumes)
@ -177,19 +185,22 @@ func balanceSelectedVolume(commandEnv *commandEnv, nodes []*Node, sortCandidates
for _, v := range candidateVolumes { for _, v := range candidateVolumes {
if _, found := emptyNode.selectedVolumes[v.Id]; !found { if _, found := emptyNode.selectedVolumes[v.Id]; !found {
moveVolume(commandEnv, v, fullNode, emptyNode, applyBalancing) if err := moveVolume(commandEnv, v, fullNode, emptyNode, applyBalancing); err == nil {
delete(fullNode.selectedVolumes, v.Id) delete(fullNode.selectedVolumes, v.Id)
emptyNode.selectedVolumes[v.Id] = v emptyNode.selectedVolumes[v.Id] = v
hasMove = true hasMove = true
break break
} else {
return err
}
} }
} }
} }
} }
return nil
} }
func moveVolume(commandEnv *commandEnv, v *master_pb.VolumeInformationMessage, fullNode *Node, emptyNode *Node, applyBalancing bool) { func moveVolume(commandEnv *commandEnv, v *master_pb.VolumeInformationMessage, fullNode *Node, emptyNode *Node, applyBalancing bool) error {
collectionPrefix := v.Collection + "_" collectionPrefix := v.Collection + "_"
if v.Collection == "" { if v.Collection == "" {
collectionPrefix = "" collectionPrefix = ""
@ -197,8 +208,9 @@ func moveVolume(commandEnv *commandEnv, v *master_pb.VolumeInformationMessage, f
fmt.Fprintf(os.Stdout, "moving volume %s%d %s => %s\n", collectionPrefix, v.Id, fullNode.info.Id, emptyNode.info.Id) fmt.Fprintf(os.Stdout, "moving volume %s%d %s => %s\n", collectionPrefix, v.Id, fullNode.info.Id, emptyNode.info.Id)
if applyBalancing { if applyBalancing {
ctx := context.Background() ctx := context.Background()
LiveMoveVolume(ctx, commandEnv.option.GrpcDialOption, needle.VolumeId(v.Id), fullNode.info.Id, emptyNode.info.Id, 5*time.Second) return LiveMoveVolume(ctx, commandEnv.option.GrpcDialOption, needle.VolumeId(v.Id), fullNode.info.Id, emptyNode.info.Id, 5*time.Second)
} }
return nil
} }
func (node *Node) prepareVolumes(fn func(v *master_pb.VolumeInformationMessage) bool) { func (node *Node) prepareVolumes(fn func(v *master_pb.VolumeInformationMessage) bool) {