|
|
@@ -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)
|