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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
shell: move volume operations to use flag parsing arguments
Chris Luf498c7119906
diff --git a/weed/shell/command_volume_configure_replication.go b/weed/shell/command_volume_configure_replication.goindex ff976c3456..539bdb5154 100644--- a/weed/shell/command_volume_configure_replication.go+++ b/weed/shell/command_volume_configure_replication.go@@ -28,7 +28,7 @@ func (c *commandVolumeConfigureReplication) Name() string {func (c *commandVolumeConfigureReplication) Help() string {return `change volume replication value- This command changes a volume replication value. It should be followed by volume.fix.replication.+ This command changes a volume replication value. It should be followed by "volume.fix.replication".`}diff --git a/weed/shell/command_volume_copy.go b/weed/shell/command_volume_copy.goindex cdd10863ff..f9edf9431e 100644--- a/weed/shell/command_volume_copy.go+++ b/weed/shell/command_volume_copy.go@@ -1,6 +1,7 @@package shellimport (+ "flag""fmt""io"@@ -21,7 +22,7 @@ func (c *commandVolumeCopy) Name() string {func (c *commandVolumeCopy) Help() string {return `copy a volume from one volume server to another volume server- volume.copy <source volume server host:port> <target volume server host:port> <volume id>+ volume.copy -source <source volume server host:port> -target <target volume server host:port> -volumeId <volume id>This command copies a volume from one volume server to another volume server.Usually you will want to unmount the volume first before copying.@@ -35,16 +36,17 @@ func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.return}- if len(args) != 3 {- fmt.Fprintf(writer, "received args: %+v\n", args)- return fmt.Errorf("need 3 args of <source volume server host:port> <target volume server host:port> <volume id>")+ volCopyCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)+ volumeIdInt := volCopyCommand.Int("volumeId", 0, "the volume id")+ sourceNodeStr := volCopyCommand.String("source", "", "the source volume server <host>:<port>")+ targetNodeStr := volCopyCommand.String("target", "", "the target volume server <host>:<port>")+ if err = volCopyCommand.Parse(args); err != nil {+ return nil}- sourceVolumeServer, targetVolumeServer, volumeIdString := args[0], args[1], args[2]- volumeId, err := needle.NewVolumeId(volumeIdString)- if err != nil {- return fmt.Errorf("wrong volume id format %s: %v", volumeId, err)- }+ sourceVolumeServer, targetVolumeServer := *sourceNodeStr, *targetNodeStr++ volumeId := needle.VolumeId(*volumeIdInt)if sourceVolumeServer == targetVolumeServer {return fmt.Errorf("source and target volume servers are the same!")diff --git a/weed/shell/command_volume_delete.go b/weed/shell/command_volume_delete.goindex c5cc9e2778..187caa1a46 100644--- a/weed/shell/command_volume_delete.go+++ b/weed/shell/command_volume_delete.go@@ -1,7 +1,7 @@package shellimport (- "fmt"+ "flag""io""github.com/chrislusf/seaweedfs/weed/storage/needle"@@ -21,7 +21,7 @@ func (c *commandVolumeDelete) Name() string {func (c *commandVolumeDelete) Help() string {return `delete a live volume from one volume server- volume.delete <volume server host:port> <volume id>+ volume.delete -node <volume server host:port> -volumeId <volume id>This command deletes a volume from one volume server.@@ -34,16 +34,16 @@ func (c *commandVolumeDelete) Do(args []string, commandEnv *CommandEnv, writer ireturn}- if len(args) != 2 {- fmt.Fprintf(writer, "received args: %+v\n", args)- return fmt.Errorf("need 2 args of <volume server host:port> <volume id>")+ volDeleteCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)+ volumeIdInt := volDeleteCommand.Int("volumeId", 0, "the volume id")+ nodeStr := volDeleteCommand.String("node", "", "the volume server <host>:<port>")+ if err = volDeleteCommand.Parse(args); err != nil {+ return nil}- sourceVolumeServer, volumeIdString := args[0], args[1]- volumeId, err := needle.NewVolumeId(volumeIdString)- if err != nil {- return fmt.Errorf("wrong volume id format %s: %v", volumeId, err)- }+ sourceVolumeServer := *nodeStr++ volumeId := needle.VolumeId(*volumeIdInt)return deleteVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer)diff --git a/weed/shell/command_volume_fix_replication.go b/weed/shell/command_volume_fix_replication.goindex b32ccaaaba..471b24a2ac 100644--- a/weed/shell/command_volume_fix_replication.go+++ b/weed/shell/command_volume_fix_replication.go@@ -2,6 +2,7 @@ package shellimport ("context"+ "flag""fmt""github.com/chrislusf/seaweedfs/weed/storage/needle""io"@@ -50,11 +51,14 @@ func (c *commandVolumeFixReplication) Do(args []string, commandEnv *CommandEnv,return}- takeAction := true- if len(args) > 0 && args[0] == "-n" {- takeAction = false+ volFixReplicationCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)+ skipChange := volFixReplicationCommand.Bool("n", false, "skip the changes")+ if err = volFixReplicationCommand.Parse(args); err != nil {+ return nil}+ takeAction := !*skipChange+var resp *master_pb.VolumeListResponseerr = commandEnv.MasterClient.WithClient(func(client master_pb.SeaweedClient) error {resp, err = client.VolumeList(context.Background(), &master_pb.VolumeListRequest{})diff --git a/weed/shell/command_volume_mount.go b/weed/shell/command_volume_mount.goindex ded7b7e666..bd588d0b52 100644--- a/weed/shell/command_volume_mount.go+++ b/weed/shell/command_volume_mount.go@@ -2,7 +2,7 @@ package shellimport ("context"- "fmt"+ "flag""io""github.com/chrislusf/seaweedfs/weed/operation"@@ -25,7 +25,7 @@ func (c *commandVolumeMount) Name() string {func (c *commandVolumeMount) Help() string {return `mount a volume from one volume server- volume.mount <volume server host:port> <volume id>+ volume.mount -node <volume server host:port> -volumeId <volume id>This command mounts a volume from one volume server.@@ -38,16 +38,16 @@ func (c *commandVolumeMount) Do(args []string, commandEnv *CommandEnv, writer ioreturn}- if len(args) != 2 {- fmt.Fprintf(writer, "received args: %+v\n", args)- return fmt.Errorf("need 2 args of <volume server host:port> <volume id>")+ volMountCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)+ volumeIdInt := volMountCommand.Int("volumeId", 0, "the volume id")+ nodeStr := volMountCommand.String("node", "", "the volume server <host>:<port>")+ if err = volMountCommand.Parse(args); err != nil {+ return nil}- sourceVolumeServer, volumeIdString := args[0], args[1]- volumeId, err := needle.NewVolumeId(volumeIdString)- if err != nil {- return fmt.Errorf("wrong volume id format %s: %v", volumeId, err)- }+ sourceVolumeServer := *nodeStr++ volumeId := needle.VolumeId(*volumeIdInt)return mountVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer)diff --git a/weed/shell/command_volume_move.go b/weed/shell/command_volume_move.goindex 37174d1d9f..b136604e56 100644--- a/weed/shell/command_volume_move.go+++ b/weed/shell/command_volume_move.go@@ -2,6 +2,7 @@ package shellimport ("context"+ "flag""fmt""io""log"@@ -27,7 +28,7 @@ func (c *commandVolumeMove) Name() string {func (c *commandVolumeMove) Help() string {return `move a live volume from one volume server to another volume server- volume.move <source volume server host:port> <target volume server host:port> <volume id>+ volume.move -source <source volume server host:port> -target <target volume server host:port> -volumeId <volume id>This command move a live volume from one volume server to another volume server. Here are the steps:@@ -48,16 +49,17 @@ func (c *commandVolumeMove) Do(args []string, commandEnv *CommandEnv, writer io.return}- if len(args) != 3 {- fmt.Fprintf(writer, "received args: %+v\n", args)- return fmt.Errorf("need 3 args of <source volume server host:port> <target volume server host:port> <volume id>")+ volMoveCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)+ volumeIdInt := volMoveCommand.Int("volumeId", 0, "the volume id")+ sourceNodeStr := volMoveCommand.String("source", "", "the source volume server <host>:<port>")+ targetNodeStr := volMoveCommand.String("target", "", "the target volume server <host>:<port>")+ if err = volMoveCommand.Parse(args); err != nil {+ return nil}- sourceVolumeServer, targetVolumeServer, volumeIdString := args[0], args[1], args[2]- volumeId, err := needle.NewVolumeId(volumeIdString)- if err != nil {- return fmt.Errorf("wrong volume id format %s: %v", volumeId, err)- }+ sourceVolumeServer, targetVolumeServer := *sourceNodeStr, *targetNodeStr++ volumeId := needle.VolumeId(*volumeIdInt)if sourceVolumeServer == targetVolumeServer {return fmt.Errorf("source and target volume servers are the same!")diff --git a/weed/shell/command_volume_unmount.go b/weed/shell/command_volume_unmount.goindex 7596bb4c8e..f7e5a501b5 100644--- a/weed/shell/command_volume_unmount.go+++ b/weed/shell/command_volume_unmount.go@@ -2,7 +2,7 @@ package shellimport ("context"- "fmt"+ "flag""io""github.com/chrislusf/seaweedfs/weed/operation"@@ -25,7 +25,7 @@ func (c *commandVolumeUnmount) Name() string {func (c *commandVolumeUnmount) Help() string {return `unmount a volume from one volume server- volume.unmount <volume server host:port> <volume id>+ volume.unmount -node <volume server host:port> -volumeId <volume id>This command unmounts a volume from one volume server.@@ -38,16 +38,16 @@ func (c *commandVolumeUnmount) Do(args []string, commandEnv *CommandEnv, writerreturn}- if len(args) != 2 {- fmt.Fprintf(writer, "received args: %+v\n", args)- return fmt.Errorf("need 2 args of <volume server host:port> <volume id>")+ volUnmountCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)+ volumeIdInt := volUnmountCommand.Int("volumeId", 0, "the volume id")+ nodeStr := volUnmountCommand.String("node", "", "the volume server <host>:<port>")+ if err = volUnmountCommand.Parse(args); err != nil {+ return nil}- sourceVolumeServer, volumeIdString := args[0], args[1]- volumeId, err := needle.NewVolumeId(volumeIdString)- if err != nil {- return fmt.Errorf("wrong volume id format %s: %v", volumeId, err)- }+ sourceVolumeServer := *nodeStr++ volumeId := needle.VolumeId(*volumeIdInt)return unmountVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer)