etcdctl: v3 compact with physical flag

release-3.0
Gyu-Ho Lee 2016-06-27 11:50:28 -07:00
parent 859e336d68
commit 76e2bf03b8
2 changed files with 13 additions and 3 deletions

View File

@ -18,7 +18,7 @@ import (
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
)
// CompactOp represents a compact Operation.
// CompactOp represents a compact operation.
type CompactOp struct {
revision int64
physical bool

View File

@ -18,16 +18,21 @@ import (
"fmt"
"strconv"
"github.com/coreos/etcd/clientv3"
"github.com/spf13/cobra"
)
var compactPhysical bool
// NewCompactionCommand returns the cobra command for "compaction".
func NewCompactionCommand() *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "compaction <revision>",
Short: "Compaction compacts the event history in etcd.",
Run: compactionCommandFunc,
}
cmd.Flags().BoolVar(&compactPhysical, "physical", false, "'true' to wait for compaction to physically remove all old revisions.")
return cmd
}
// compactionCommandFunc executes the "compaction" command.
@ -41,9 +46,14 @@ func compactionCommandFunc(cmd *cobra.Command, args []string) {
ExitWithError(ExitError, err)
}
var opts []clientv3.CompactOption
if compactPhysical {
opts = append(opts, clientv3.WithCompactPhysical())
}
c := mustClientFromCmd(cmd)
ctx, cancel := commandCtx(cmd)
cerr := c.Compact(ctx, rev)
cerr := c.Compact(ctx, rev, opts...)
cancel()
if cerr != nil {
ExitWithError(ExitError, cerr)