From 97e96feb1d949dccebcffa097814ebe813422c7e Mon Sep 17 00:00:00 2001 From: "Timothy St. Clair" Date: Wed, 2 Nov 2016 18:10:30 -0500 Subject: [PATCH] ctlv3: Add a no-ttl flag to etcdctl migrate to discard keys on transform. --- etcdctl/ctlv3/command/migrate_command.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/etcdctl/ctlv3/command/migrate_command.go b/etcdctl/ctlv3/command/migrate_command.go index 5b616c577f2..c4e8d7e6d59 100644 --- a/etcdctl/ctlv3/command/migrate_command.go +++ b/etcdctl/ctlv3/command/migrate_command.go @@ -42,9 +42,10 @@ import ( ) var ( - migrateDatadir string - migrateWALdir string - migrateTransformer string + migrateExcludeTTLKey bool + migrateDatadir string + migrateWALdir string + migrateTransformer string ) // NewMigrateCommand returns the cobra command for "migrate". @@ -55,6 +56,7 @@ func NewMigrateCommand() *cobra.Command { Run: migrateCommandFunc, } + mc.Flags().BoolVar(&migrateExcludeTTLKey, "no-ttl", false, "Do not convert TTL keys") mc.Flags().StringVar(&migrateDatadir, "data-dir", "", "Path to the data directory") mc.Flags().StringVar(&migrateWALdir, "wal-dir", "", "Path to the WAL directory") mc.Flags().StringVar(&migrateTransformer, "transformer", "", "Path to the user-provided transformer program") @@ -216,11 +218,13 @@ func writeKeys(w io.Writer, n *store.NodeExtern) uint64 { if n.Dir { n.Nodes = nil } - b, err := json.Marshal(n) - if err != nil { - ExitWithError(ExitError, err) + if !migrateExcludeTTLKey || n.TTL == 0 { + b, err := json.Marshal(n) + if err != nil { + ExitWithError(ExitError, err) + } + fmt.Fprint(w, string(b)) } - fmt.Fprint(w, string(b)) for _, nn := range nodes { max := writeKeys(w, nn) if max > maxIndex {