command_volume_delete.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package shell
  2. import (
  3. "flag"
  4. "github.com/seaweedfs/seaweedfs/weed/pb"
  5. "io"
  6. "github.com/seaweedfs/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 -node <volume server host:port> -volumeId <volume id>
  19. This command deletes a volume from one volume server.
  20. `
  21. }
  22. func (c *commandVolumeDelete) HasTag(CommandTag) bool {
  23. return false
  24. }
  25. func (c *commandVolumeDelete) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  26. volDeleteCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  27. volumeIdInt := volDeleteCommand.Int("volumeId", 0, "the volume id")
  28. nodeStr := volDeleteCommand.String("node", "", "the volume server <host>:<port>")
  29. if err = volDeleteCommand.Parse(args); err != nil {
  30. return nil
  31. }
  32. if err = commandEnv.confirmIsLocked(args); err != nil {
  33. return
  34. }
  35. sourceVolumeServer := pb.ServerAddress(*nodeStr)
  36. volumeId := needle.VolumeId(*volumeIdInt)
  37. return deleteVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, false)
  38. }