From e71ff361a4e1a6519ec92aa4c1f87ac4af71eeae Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Thu, 15 Dec 2016 18:54:31 -0800 Subject: [PATCH] etcdctl: warn when backend takes too long to open on migrate --- etcdctl/ctlv3/command/migrate_command.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/etcdctl/ctlv3/command/migrate_command.go b/etcdctl/ctlv3/command/migrate_command.go index be0ae06fd..32f33bab8 100644 --- a/etcdctl/ctlv3/command/migrate_command.go +++ b/etcdctl/ctlv3/command/migrate_command.go @@ -100,8 +100,22 @@ func migrateCommandFunc(cmd *cobra.Command, args []string) { } func prepareBackend() backend.Backend { + var be backend.Backend + + bch := make(chan struct{}) dbpath := path.Join(migrateDatadir, "member", "snap", "db") - be := backend.New(dbpath, time.Second, 10000) + go func() { + defer close(bch) + be = backend.New(dbpath, time.Second, 10000) + + }() + select { + case <-bch: + case <-time.After(time.Second): + fmt.Fprintf(os.Stderr, "waiting for etcd to close and release its lock on %q\n", dbpath) + <-bch + } + tx := be.BatchTx() tx.Lock() tx.UnsafeCreateBucket([]byte("key"))