Browse Source

etcdctl: v3 compact with physical flag

Gyu-Ho Lee 9 years ago
parent
commit
76e2bf03b8
2 changed files with 13 additions and 3 deletions
  1. 1 1
      clientv3/compact_op.go
  2. 12 2
      etcdctl/ctlv3/command/compaction_command.go

+ 1 - 1
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

+ 12 - 2
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 <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)