diff --git a/clientv3/compact_op.go b/clientv3/compact_op.go index 264f4037b..32d97eb0c 100644 --- a/clientv3/compact_op.go +++ b/clientv3/compact_op.go @@ -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 diff --git a/etcdctl/ctlv3/command/compaction_command.go b/etcdctl/ctlv3/command/compaction_command.go index a0ae92a35..d1296aaf1 100644 --- a/etcdctl/ctlv3/command/compaction_command.go +++ b/etcdctl/ctlv3/command/compaction_command.go @@ -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 ", 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)