aboutsummaryrefslogtreecommitdiff
path: root/weed/shell
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2024-09-09 23:42:56 +0500
committerGitHub <noreply@github.com>2024-09-09 11:42:56 -0700
commit15965f7c5421f60cc8f822ec34e1dc0da23ea1df (patch)
treeee5452e89d95e5263723ae460919c3a76e846cb3 /weed/shell
parent4af21b0dfced547b540a6c20b03151cbc4faa6b5 (diff)
downloadseaweedfs-15965f7c5421f60cc8f822ec34e1dc0da23ea1df.tar.xz
seaweedfs-15965f7c5421f60cc8f822ec34e1dc0da23ea1df.zip
[shell] fix volume grow in shell (#5992)
* fix volume grow in shell * revert add Async * check available volume space * create a VolumeGrowRequest and remove unnecessary fields
Diffstat (limited to 'weed/shell')
-rw-r--r--weed/shell/command_volume_grow.go87
1 files changed, 73 insertions, 14 deletions
diff --git a/weed/shell/command_volume_grow.go b/weed/shell/command_volume_grow.go
index 21d98dddd..026a59b7b 100644
--- a/weed/shell/command_volume_grow.go
+++ b/weed/shell/command_volume_grow.go
@@ -5,6 +5,9 @@ import (
"flag"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
+ "github.com/seaweedfs/seaweedfs/weed/storage/needle"
+ "github.com/seaweedfs/seaweedfs/weed/storage/super_block"
+ "github.com/seaweedfs/seaweedfs/weed/storage/types"
"io"
)
@@ -33,30 +36,86 @@ func (c *commandGrow) Do(args []string, commandEnv *CommandEnv, writer io.Writer
growCount := volumeVacuumCommand.Uint("count", 2, "")
collection := volumeVacuumCommand.String("collection", "", "grow this collection")
dataCenter := volumeVacuumCommand.String("dataCenter", "", "grow volumes only from the specified data center")
+ rack := volumeVacuumCommand.String("rack", "", "grow volumes only from the specified rack")
+ dataNode := volumeVacuumCommand.String("dataNode", "", "grow volumes only from the specified data node")
+ diskType := volumeVacuumCommand.String("diskType", "", "grow volumes only from the specified disk type")
if err = volumeVacuumCommand.Parse(args); err != nil {
return nil
}
-
- assignRequest := &master_pb.AssignRequest{
- Count: 0,
+ if *collection == "" {
+ return fmt.Errorf("collection option is required")
+ }
+ t, _, err := collectTopologyInfo(commandEnv, 0)
+ if err != nil {
+ return err
+ }
+ volumeGrowRequest := &master_pb.VolumeGrowRequest{
Collection: *collection,
+ DataCenter: *dataCenter,
+ Rack: *rack,
+ DataNode: *dataNode,
WritableVolumeCount: uint32(*growCount),
}
- if *dataCenter != "" {
- assignRequest.DataCenter = *dataCenter
- }
-
- err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
- _, err := client.Assign(context.Background(), assignRequest)
- if err != nil {
- return fmt.Errorf("Assign: %v", err)
+ collectionFound := false
+ dataCenterFound := *dataCenter == ""
+ rackFound := *rack == ""
+ dataNodeFound := *dataNode == ""
+ diskTypeFound := *diskType == ""
+ for _, dc := range t.DataCenterInfos {
+ if dc.Id == *dataCenter {
+ dataCenterFound = true
+ }
+ for _, r := range dc.RackInfos {
+ if r.Id == *rack {
+ rackFound = true
+ }
+ for _, dn := range r.DataNodeInfos {
+ if dn.Id == *dataNode {
+ dataNodeFound = true
+ }
+ for _, di := range dn.DiskInfos {
+ if !diskTypeFound && di.Type == types.ToDiskType(*diskType).String() {
+ diskTypeFound = true
+ }
+ for _, vi := range di.VolumeInfos {
+ if !collectionFound && vi.Collection == *collection {
+ replicaPlacement, _ := super_block.NewReplicaPlacementFromByte(byte(vi.ReplicaPlacement))
+ volumeGrowRequest.Ttl = needle.LoadTTLFromUint32(vi.Ttl).String()
+ volumeGrowRequest.DiskType = vi.DiskType
+ volumeGrowRequest.Replication = replicaPlacement.String()
+ collectionFound = true
+ }
+ if collectionFound && dataCenterFound && rackFound && dataNodeFound && diskTypeFound {
+ break
+ }
+ }
+ }
+ }
+ }
+ }
+ if !dataCenterFound {
+ return fmt.Errorf("data center not found")
+ }
+ if !rackFound {
+ return fmt.Errorf("rack not found")
+ }
+ if !dataNodeFound {
+ return fmt.Errorf("data node not found")
+ }
+ if !diskTypeFound {
+ return fmt.Errorf("disk type not found")
+ }
+ if !collectionFound {
+ return fmt.Errorf("collection not found")
+ }
+ if err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
+ if _, err := client.VolumeGrow(context.Background(), volumeGrowRequest); err != nil {
+ return err
}
return nil
- })
-
- if err != nil {
+ }); err != nil {
return
}