Browse Source

etcdctlv3: report compaction error, if any

Anthony Romano 10 years ago
parent
commit
aa9d3c8b74
2 changed files with 9 additions and 6 deletions
  1. 1 1
      clientv3/kv.go
  2. 8 5
      etcdctlv3/command/compaction_command.go

+ 1 - 1
clientv3/kv.go

@@ -124,7 +124,7 @@ func (kv *kv) Compact(rev int64) error {
 	}
 
 	go kv.switchRemote(err)
-	return nil
+	return err
 }
 
 func (kv *kv) Txn() Txn {

+ 8 - 5
etcdctlv3/command/compaction_command.go

@@ -19,14 +19,13 @@ import (
 	"strconv"
 
 	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
-	"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
-	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
+	"github.com/coreos/etcd/clientv3"
 )
 
 // NewCompactionCommand returns the cobra command for "compaction".
 func NewCompactionCommand() *cobra.Command {
 	return &cobra.Command{
-		Use:   "compaction",
+		Use:   "compaction <revision>",
 		Short: "Compaction compacts the event history in etcd.",
 		Run:   compactionCommandFunc,
 	}
@@ -43,6 +42,10 @@ func compactionCommandFunc(cmd *cobra.Command, args []string) {
 		ExitWithError(ExitError, err)
 	}
 
-	req := &pb.CompactionRequest{Revision: rev}
-	mustClient(cmd).KV.Compact(context.Background(), req)
+	c := mustClient(cmd)
+	if cerr := clientv3.NewKV(c).Compact(rev); cerr != nil {
+		ExitWithError(ExitError, cerr)
+		return
+	}
+	fmt.Println("compacted revision", rev)
 }