mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Embed: In case KVStoreHash verification fails, close the backend.
In case of failed verification, the server used to keep opened backend (so the file was locked on OS level).
This commit is contained in:
@@ -229,6 +229,9 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
|
||||
if err = e.Server.CheckInitialHashKV(); err != nil {
|
||||
// set "EtcdServer" to nil, so that it does not block on "EtcdServer.Close()"
|
||||
// (nothing to close since rafthttp transports have not been started)
|
||||
|
||||
e.cfg.logger.Error("checkInitialHashKV failed", zap.Error(err))
|
||||
e.Server.Cleanup()
|
||||
e.Server = nil
|
||||
return e, err
|
||||
}
|
||||
|
||||
@@ -1028,7 +1028,6 @@ func (s *EtcdServer) run() {
|
||||
close(s.stopping)
|
||||
s.wgMu.Unlock()
|
||||
s.cancel()
|
||||
|
||||
sched.Stop()
|
||||
|
||||
// wait for gouroutines before closing raft so wal stays open
|
||||
@@ -1040,23 +1039,8 @@ func (s *EtcdServer) run() {
|
||||
// by adding a peer after raft stops the transport
|
||||
s.r.stop()
|
||||
|
||||
// kv, lessor and backend can be nil if running without v3 enabled
|
||||
// or running unit tests.
|
||||
if s.lessor != nil {
|
||||
s.lessor.Stop()
|
||||
}
|
||||
if s.kv != nil {
|
||||
s.kv.Close()
|
||||
}
|
||||
if s.authStore != nil {
|
||||
s.authStore.Close()
|
||||
}
|
||||
if s.be != nil {
|
||||
s.be.Close()
|
||||
}
|
||||
if s.compactor != nil {
|
||||
s.compactor.Stop()
|
||||
}
|
||||
s.Cleanup()
|
||||
|
||||
close(s.done)
|
||||
}()
|
||||
|
||||
@@ -1112,6 +1096,28 @@ func (s *EtcdServer) run() {
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup removes allocated objects by EtcdServer.NewServer in
|
||||
// situation that EtcdServer::Start was not called (that takes care of cleanup).
|
||||
func (s *EtcdServer) Cleanup() {
|
||||
// kv, lessor and backend can be nil if running without v3 enabled
|
||||
// or running unit tests.
|
||||
if s.lessor != nil {
|
||||
s.lessor.Stop()
|
||||
}
|
||||
if s.kv != nil {
|
||||
s.kv.Close()
|
||||
}
|
||||
if s.authStore != nil {
|
||||
s.authStore.Close()
|
||||
}
|
||||
if s.be != nil {
|
||||
s.be.Close()
|
||||
}
|
||||
if s.compactor != nil {
|
||||
s.compactor.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *EtcdServer) applyAll(ep *etcdProgress, apply *apply) {
|
||||
s.applySnapshot(ep, apply)
|
||||
s.applyEntries(ep, apply)
|
||||
|
||||
Reference in New Issue
Block a user