command_volume_delete.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package shell
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  7. )
  8. func init() {
  9. Commands = append(Commands, &commandVolumeDelete{})
  10. }
  11. type commandVolumeDelete struct {
  12. }
  13. func (c *commandVolumeDelete) Name() string {
  14. return "volume.delete"
  15. }
  16. func (c *commandVolumeDelete) Help() string {
  17. return `delete a live volume from one volume server
  18. volume.delete <volume server host:port> <volume id>
  19. This command deletes a volume from one volume server.
  20. `
  21. }
  22. func (c *commandVolumeDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  23. if len(args) != 2 {
  24. fmt.Fprintf(writer, "received args: %+v\n", args)
  25. return fmt.Errorf("need 2 args of <volume server host:port> <volume id>")
  26. }
  27. sourceVolumeServer, volumeIdString := args[0], args[1]
  28. volumeId, err := needle.NewVolumeId(volumeIdString)
  29. if err != nil {
  30. return fmt.Errorf("wrong volume id format %s: %v", volumeId, err)
  31. }
  32. ctx := context.Background()
  33. return deleteVolume(ctx, commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer)
  34. }