From c67b937d622c7cd812c3636400c937627a87b047 Mon Sep 17 00:00:00 2001 From: Owen Smith Date: Tue, 25 Nov 2014 15:18:14 +0000 Subject: [PATCH] etcdserver: truncate WAL from correct index when forcing new cluster When loading from a backup with a snapshot and WAL, the length of WAL entries can be lower than the current index integer value, causing a panic when slicing off uncommitted entries. This looks for WAL entries higher than the current index before slicing. --- etcdserver/force_cluster.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/etcdserver/force_cluster.go b/etcdserver/force_cluster.go index b0d1c8085..568f28674 100644 --- a/etcdserver/force_cluster.go +++ b/etcdserver/force_cluster.go @@ -33,8 +33,12 @@ func restartAsStandaloneNode(cfg *ServerConfig, index uint64, snapshot *raftpb.S cfg.Cluster.SetID(cid) // 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