command_volume_grow.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
  7. "io"
  8. )
  9. func init() {
  10. Commands = append(Commands, &commandGrow{})
  11. }
  12. type commandGrow struct {
  13. }
  14. func (c *commandGrow) Name() string {
  15. return "volume.grow"
  16. }
  17. func (c *commandGrow) Help() string {
  18. return `grow volumes
  19. volume.grow [-collection=<collection name>] [-dataCenter=<data center name>]
  20. `
  21. }
  22. func (c *commandGrow) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  23. volumeVacuumCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  24. growCount := volumeVacuumCommand.Uint("count", 2, "")
  25. collection := volumeVacuumCommand.String("collection", "", "grow this collection")
  26. dataCenter := volumeVacuumCommand.String("dataCenter", "", "grow volumes only from the specified data center")
  27. if err = volumeVacuumCommand.Parse(args); err != nil {
  28. return nil
  29. }
  30. assignRequest := &master_pb.AssignRequest{
  31. Count: 0,
  32. Collection: *collection,
  33. WritableVolumeCount: uint32(*growCount),
  34. }
  35. if *dataCenter != "" {
  36. assignRequest.DataCenter = *dataCenter
  37. }
  38. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  39. _, err := client.Assign(context.Background(), assignRequest)
  40. if err != nil {
  41. return fmt.Errorf("Assign: %v", err)
  42. }
  43. return nil
  44. })
  45. if err != nil {
  46. return
  47. }
  48. return nil
  49. }