From 0bd9bea2e93d6d5014691c29546f2aadfa93e63e Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 30 Aug 2016 10:43:36 -0700 Subject: [PATCH] etcdserver: allow zero kv index for cluster upgrade If a user upgrades etcd from 2.3.x to 3.0 and shutdown the cluster immediately without triggering any new backend writes, then the consistent index in backend would be zero. The user cannot restart etcdserver due to today's strick index match checking. We now have to lose this a bit for this case. --- etcdserver/server.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/etcdserver/server.go b/etcdserver/server.go index afbbfc656..dd232d5ef 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -412,8 +412,13 @@ func NewServer(cfg *ServerConfig) (srv *EtcdServer, err error) { srv.kv = mvcc.New(srv.be, srv.lessor, &srv.consistIndex) if beExist { kvindex := srv.kv.ConsistentIndex() + // TODO: remove kvindex != 0 checking when we do not expect users to upgrade + // etcd from pre-3.0 release. if snapshot != nil && kvindex < snapshot.Metadata.Index { - return nil, fmt.Errorf("database file (%v index %d) does not match with snapshot (index %d).", bepath, kvindex, snapshot.Metadata.Index) + if kvindex != 0 { + return nil, fmt.Errorf("database file (%v index %d) does not match with snapshot (index %d).", bepath, kvindex, snapshot.Metadata.Index) + } + plog.Warningf("consistent index never saved (snapshot index=%d)", snapshot.Metadata.Index) } } srv.consistIndex.setConsistentIndex(srv.kv.ConsistentIndex())