etcdctl/ctlv3: add "--cluster" flag to "defrag" command

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
release-3.4
Gyuho Lee 2018-03-05 10:44:57 -08:00
parent 55a7b30377
commit 912c402188
2 changed files with 12 additions and 5 deletions

View File

@ -876,10 +876,7 @@ If NOSPACE alarm is present:
### DEFRAG [options]
DEFRAG defragments the backend database file for a set of given endpoints while etcd is running, or directly defragments an
etcd data directory while etcd is not running. When an etcd member reclaims storage space from deleted and compacted keys, the
space is kept in a free list and the database file remains the same size. By defragmenting the database, the etcd member
releases this free space back to the file system.
DEFRAG defragments the backend database file for a set of given endpoints while etcd is running, or directly defragments an etcd data directory while etcd is not running. When an etcd member reclaims storage space from deleted and compacted keys, the space is kept in a free list and the database file remains the same size. By defragmenting the database, the etcd member releases this free space back to the file system.
#### Options
@ -897,6 +894,15 @@ For each endpoints, prints a message indicating whether the endpoint was success
# Failed to defragment etcd member[badendpoint:2379] (grpc: timed out trying to connect)
```
Run defragment operations for all endpoints in the cluster associated with the default endpoint:
```bash
./etcdctl defrag --cluster
Finished defragmenting etcd member[http://127.0.0.1:2379]
Finished defragmenting etcd member[http://127.0.0.1:22379]
Finished defragmenting etcd member[http://127.0.0.1:32379]
```
To defragment a data directory directly, use the `--data-dir` flag:
``` bash

View File

@ -35,6 +35,7 @@ func NewDefragCommand() *cobra.Command {
Short: "Defragments the storage of the etcd members with given endpoints",
Run: defragCommandFunc,
}
cmd.PersistentFlags().BoolVar(&epClusterEndpoints, "cluster", false, "use all endpoints from the cluster member list")
cmd.Flags().StringVar(&defragDataDir, "data-dir", "", "Optional. If present, defragments a data directory not in use by etcd.")
return cmd
}
@ -51,7 +52,7 @@ func defragCommandFunc(cmd *cobra.Command, args []string) {
failures := 0
c := mustClientFromCmd(cmd)
for _, ep := range c.Endpoints() {
for _, ep := range endpointsFromCluster(cmd) {
ctx, cancel := commandCtx(cmd)
_, err := c.Defragment(ctx, ep)
cancel()