aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_volume_grow.go
blob: 21d98ddddbe94e0b58976e5bf6430fdcb77bda0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package shell

import (
	"context"
	"flag"
	"fmt"
	"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
	"io"
)

func init() {
	Commands = append(Commands, &commandGrow{})
}

type commandGrow struct {
}

func (c *commandGrow) Name() string {
	return "volume.grow"
}

func (c *commandGrow) Help() string {
	return `grow volumes

	volume.grow [-collection=<collection name>] [-dataCenter=<data center name>]

`
}

func (c *commandGrow) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {

	volumeVacuumCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
	growCount := volumeVacuumCommand.Uint("count", 2, "")
	collection := volumeVacuumCommand.String("collection", "", "grow this collection")
	dataCenter := volumeVacuumCommand.String("dataCenter", "", "grow volumes only from the specified data center")

	if err = volumeVacuumCommand.Parse(args); err != nil {
		return nil
	}

	assignRequest := &master_pb.AssignRequest{
		Count:               0,
		Collection:          *collection,
		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)
		}
		return nil
	})

	if err != nil {
		return
	}

	return nil
}