Ver código fonte

Merge pull request #1782 from orls/fix-forcenew-panic

etcdserver: Fix panic when restoring from backup (-force-new-cluster)
Xiang Li 11 anos atrás
pai
commit
c46e30412e
1 arquivos alterados com 6 adições e 2 exclusões
  1. 6 2
      etcdserver/force_cluster.go

+ 6 - 2
etcdserver/force_cluster.go

@@ -33,8 +33,12 @@ func restartAsStandaloneNode(cfg *ServerConfig, index uint64, snapshot *raftpb.S
 	cfg.Cluster.SetID(cid)
 	cfg.Cluster.SetID(cid)
 
 
 	// discard the previously uncommitted entries
 	// discard the previously uncommitted entries
-	if len(ents) != 0 {
-		ents = ents[:st.Commit+1]
+	for i, ent := range ents {
+		if ent.Index > st.Commit {
+			log.Printf("etcdserver: discarding %d uncommited WAL entries ", len(ents)-i)
+			ents = ents[:i]
+			break
+		}
 	}
 	}
 
 
 	// force append the configuration change entries
 	// force append the configuration change entries