From 4bec0d7d6727965411a4fdc4a3c1a623238be2ca Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Thu, 19 Apr 2018 14:00:31 -0700 Subject: [PATCH] etcdserver: add "InitialElectionTickAdvance" Signed-off-by: Gyuho Lee --- etcdserver/config.go | 34 ++++++++++++++++++++++++++++++++-- etcdserver/server.go | 4 ++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/etcdserver/config.go b/etcdserver/config.go index 9d9cd4047..e67628f94 100644 --- a/etcdserver/config.go +++ b/etcdserver/config.go @@ -55,8 +55,38 @@ type ServerConfig struct { // whose Host header value exists in this white list. HostWhitelist map[string]struct{} - TickMs uint - ElectionTicks int + TickMs uint + ElectionTicks int + + // InitialElectionTickAdvance is true, then local member fast-forwards + // election ticks to speed up "initial" leader election trigger. This + // benefits the case of larger election ticks. For instance, cross + // datacenter deployment may require longer election timeout of 10-second. + // If true, local node does not need wait up to 10-second. Instead, + // forwards its election ticks to 8-second, and have only 2-second left + // before leader election. + // + // Major assumptions are that: + // - cluster has no active leader thus advancing ticks enables faster + // leader election, or + // - cluster already has an established leader, and rejoining follower + // is likely to receive heartbeats from the leader after tick advance + // and before election timeout. + // + // However, when network from leader to rejoining follower is congested, + // and the follower does not receive leader heartbeat within left election + // ticks, disruptive election has to happen thus affecting cluster + // availabilities. + // + // Disabling this would slow down initial bootstrap process for cross + // datacenter deployments. Make your own tradeoffs by configuring + // --initial-election-tick-advance at the cost of slow initial bootstrap. + // + // If single-node, it advances ticks regardless. + // + // See https://github.com/coreos/etcd/issues/9333 for more detail. + InitialElectionTickAdvance bool + BootstrapTimeout time.Duration AutoCompactionRetention time.Duration diff --git a/etcdserver/server.go b/etcdserver/server.go index e61bcc92a..f7e32fec2 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -635,6 +635,10 @@ func (s *EtcdServer) adjustTicks() { return } + if !s.Cfg.InitialElectionTickAdvance { + return + } + // retry up to "rafthttp.ConnReadTimeout", which is 5-sec // until peer connection reports; otherwise: // 1. all connections failed, or