From b83a79092753cbad66f7bafc70c3e85a754feb8b Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Mon, 25 Apr 2022 10:19:26 -0400 Subject: [PATCH] update raft to v1.3.8 (#12844) * update raft to v1.3.7 * add changelog * fix compilation error * fix HeartbeatTimeout * fix ElectionTimeout to reload only if value is valid * fix default values for `ElectionTimeout` and `HeartbeatTimeout` * fix test defaults * bump raft to v1.3.8 --- .changelog/12844.txt | 3 +++ agent/agent.go | 2 ++ agent/consul/config.go | 2 ++ agent/consul/server.go | 10 +++++++++- agent/consul/server_test.go | 12 ++++++++++++ go.mod | 2 +- go.sum | 4 ++-- 7 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 .changelog/12844.txt diff --git a/.changelog/12844.txt b/.changelog/12844.txt new file mode 100644 index 0000000000..477193881a --- /dev/null +++ b/.changelog/12844.txt @@ -0,0 +1,3 @@ +```release-note:bug +raft: upgrade to v1.3.8 which fixes a bug where non cluster member can still be able to participate in an election. +``` diff --git a/agent/agent.go b/agent/agent.go index a3f3cfab83..3978f27378 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -3906,6 +3906,8 @@ func (a *Agent) reloadConfigInternal(newCfg *config.RuntimeConfig) error { ConfigEntryBootstrap: newCfg.ConfigEntryBootstrap, RaftSnapshotThreshold: newCfg.RaftSnapshotThreshold, RaftSnapshotInterval: newCfg.RaftSnapshotInterval, + HeartbeatTimeout: newCfg.ConsulRaftHeartbeatTimeout, + ElectionTimeout: newCfg.ConsulRaftElectionTimeout, RaftTrailingLogs: newCfg.RaftTrailingLogs, } if err := a.delegate.ReloadConfig(cc); err != nil { diff --git a/agent/consul/config.go b/agent/consul/config.go index 4b017da6bc..40d627bede 100644 --- a/agent/consul/config.go +++ b/agent/consul/config.go @@ -604,6 +604,8 @@ type ReloadableConfig struct { RaftSnapshotThreshold int RaftSnapshotInterval time.Duration RaftTrailingLogs int + HeartbeatTimeout time.Duration + ElectionTimeout time.Duration } type RaftBoltDBConfig struct { diff --git a/agent/consul/server.go b/agent/consul/server.go index 6147df3bd4..2f64fa6729 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -1573,6 +1573,8 @@ func computeRaftReloadableConfig(config ReloadableConfig) raft.ReloadableConfig TrailingLogs: defaultConf.RaftConfig.TrailingLogs, SnapshotInterval: defaultConf.RaftConfig.SnapshotInterval, SnapshotThreshold: defaultConf.RaftConfig.SnapshotThreshold, + ElectionTimeout: defaultConf.RaftConfig.ElectionTimeout, + HeartbeatTimeout: defaultConf.RaftConfig.HeartbeatTimeout, } if config.RaftSnapshotThreshold != 0 { raftCfg.SnapshotThreshold = uint64(config.RaftSnapshotThreshold) @@ -1583,6 +1585,12 @@ func computeRaftReloadableConfig(config ReloadableConfig) raft.ReloadableConfig if config.RaftTrailingLogs != 0 { raftCfg.TrailingLogs = uint64(config.RaftTrailingLogs) } + if config.HeartbeatTimeout >= 5*time.Millisecond { + raftCfg.HeartbeatTimeout = config.HeartbeatTimeout + } + if config.ElectionTimeout >= 5*time.Millisecond { + raftCfg.ElectionTimeout = config.ElectionTimeout + } return raftCfg } @@ -1620,7 +1628,7 @@ func (s *Server) trackLeaderChanges() { continue } - s.grpcLeaderForwarder.UpdateLeaderAddr(s.config.Datacenter, string(leaderObs.Leader)) + s.grpcLeaderForwarder.UpdateLeaderAddr(s.config.Datacenter, string(leaderObs.LeaderAddr)) case <-s.shutdownCh: s.raft.DeregisterObserver(observer) return diff --git a/agent/consul/server_test.go b/agent/consul/server_test.go index 7b0dafb2b9..c375ff7945 100644 --- a/agent/consul/server_test.go +++ b/agent/consul/server_test.go @@ -1858,6 +1858,8 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) { SnapshotThreshold: defaults.SnapshotThreshold, SnapshotInterval: defaults.SnapshotInterval, TrailingLogs: defaults.TrailingLogs, + ElectionTimeout: defaults.ElectionTimeout, + HeartbeatTimeout: defaults.HeartbeatTimeout, }, }, { @@ -1869,6 +1871,8 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) { SnapshotThreshold: 123456, SnapshotInterval: defaults.SnapshotInterval, TrailingLogs: defaults.TrailingLogs, + ElectionTimeout: defaults.ElectionTimeout, + HeartbeatTimeout: defaults.HeartbeatTimeout, }, }, { @@ -1880,6 +1884,8 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) { SnapshotThreshold: defaults.SnapshotThreshold, SnapshotInterval: 13 * time.Minute, TrailingLogs: defaults.TrailingLogs, + ElectionTimeout: defaults.ElectionTimeout, + HeartbeatTimeout: defaults.HeartbeatTimeout, }, }, { @@ -1891,6 +1897,8 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) { SnapshotThreshold: defaults.SnapshotThreshold, SnapshotInterval: defaults.SnapshotInterval, TrailingLogs: 78910, + ElectionTimeout: defaults.ElectionTimeout, + HeartbeatTimeout: defaults.HeartbeatTimeout, }, }, { @@ -1899,11 +1907,15 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) { RaftSnapshotThreshold: 123456, RaftSnapshotInterval: 13 * time.Minute, RaftTrailingLogs: 78910, + ElectionTimeout: 300 * time.Millisecond, + HeartbeatTimeout: 400 * time.Millisecond, }, want: raft.ReloadableConfig{ SnapshotThreshold: 123456, SnapshotInterval: 13 * time.Minute, TrailingLogs: 78910, + ElectionTimeout: 300 * time.Millisecond, + HeartbeatTimeout: 400 * time.Millisecond, }, }, } diff --git a/go.mod b/go.mod index 15e82d5fe4..b3fb5807ed 100644 --- a/go.mod +++ b/go.mod @@ -53,7 +53,7 @@ require ( github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hil v0.0.0-20200423225030-a18a1cd20038 github.com/hashicorp/memberlist v0.3.1 - github.com/hashicorp/raft v1.3.6 + github.com/hashicorp/raft v1.3.8 github.com/hashicorp/raft-autopilot v0.1.6 github.com/hashicorp/raft-boltdb v0.0.0-20211202195631-7d34b9fb3f42 // indirect github.com/hashicorp/raft-boltdb/v2 v2.2.2 diff --git a/go.sum b/go.sum index 1e6194da77..ca0e61768b 100644 --- a/go.sum +++ b/go.sum @@ -368,8 +368,8 @@ github.com/hashicorp/memberlist v0.3.1/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn github.com/hashicorp/raft v1.1.0/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= github.com/hashicorp/raft v1.1.1/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8= github.com/hashicorp/raft v1.2.0/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8= -github.com/hashicorp/raft v1.3.6 h1:v5xW5KzByoerQlN/o31VJrFNiozgzGyDoMgDJgXpsto= -github.com/hashicorp/raft v1.3.6/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= +github.com/hashicorp/raft v1.3.8 h1:lrhx4wesQLOSv3ERX/pK4cwfzQ0J2RgzsvAkBxHe1bA= +github.com/hashicorp/raft v1.3.8/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= github.com/hashicorp/raft-autopilot v0.1.6 h1:C1q3RNF2FfXNZfHWbvVAu0QixaQK8K5pX4O5lh+9z4I= github.com/hashicorp/raft-autopilot v0.1.6/go.mod h1:Af4jZBwaNOI+tXfIqIdbcAnh/UyyqIMj/pOISIfhArw= github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea/go.mod h1:pNv7Wc3ycL6F5oOWn+tPGo2gWD4a5X+yp/ntwdKLjRk=