Browse Source

etcdctl: warn when backend takes too long to open on migrate

Anthony Romano 9 years ago
parent
commit
e71ff361a4
1 changed files with 15 additions and 1 deletions
  1. 15 1
      etcdctl/ctlv3/command/migrate_command.go

+ 15 - 1
etcdctl/ctlv3/command/migrate_command.go

@@ -100,8 +100,22 @@ func migrateCommandFunc(cmd *cobra.Command, args []string) {
 }
 }
 
 
 func prepareBackend() backend.Backend {
 func prepareBackend() backend.Backend {
+	var be backend.Backend
+
+	bch := make(chan struct{})
 	dbpath := path.Join(migrateDatadir, "member", "snap", "db")
 	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 := be.BatchTx()
 	tx.Lock()
 	tx.Lock()
 	tx.UnsafeCreateBucket([]byte("key"))
 	tx.UnsafeCreateBucket([]byte("key"))