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
This commit is contained in:
Dhia Ayachi 2022-04-25 10:19:26 -04:00 committed by GitHub
parent a0dcd53659
commit 9dc5200155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 4 deletions

3
.changelog/12844.txt Normal file
View File

@ -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.
```

View File

@ -3906,6 +3906,8 @@ func (a *Agent) reloadConfigInternal(newCfg *config.RuntimeConfig) error {
ConfigEntryBootstrap: newCfg.ConfigEntryBootstrap, ConfigEntryBootstrap: newCfg.ConfigEntryBootstrap,
RaftSnapshotThreshold: newCfg.RaftSnapshotThreshold, RaftSnapshotThreshold: newCfg.RaftSnapshotThreshold,
RaftSnapshotInterval: newCfg.RaftSnapshotInterval, RaftSnapshotInterval: newCfg.RaftSnapshotInterval,
HeartbeatTimeout: newCfg.ConsulRaftHeartbeatTimeout,
ElectionTimeout: newCfg.ConsulRaftElectionTimeout,
RaftTrailingLogs: newCfg.RaftTrailingLogs, RaftTrailingLogs: newCfg.RaftTrailingLogs,
} }
if err := a.delegate.ReloadConfig(cc); err != nil { if err := a.delegate.ReloadConfig(cc); err != nil {

View File

@ -604,6 +604,8 @@ type ReloadableConfig struct {
RaftSnapshotThreshold int RaftSnapshotThreshold int
RaftSnapshotInterval time.Duration RaftSnapshotInterval time.Duration
RaftTrailingLogs int RaftTrailingLogs int
HeartbeatTimeout time.Duration
ElectionTimeout time.Duration
} }
type RaftBoltDBConfig struct { type RaftBoltDBConfig struct {

View File

@ -1573,6 +1573,8 @@ func computeRaftReloadableConfig(config ReloadableConfig) raft.ReloadableConfig
TrailingLogs: defaultConf.RaftConfig.TrailingLogs, TrailingLogs: defaultConf.RaftConfig.TrailingLogs,
SnapshotInterval: defaultConf.RaftConfig.SnapshotInterval, SnapshotInterval: defaultConf.RaftConfig.SnapshotInterval,
SnapshotThreshold: defaultConf.RaftConfig.SnapshotThreshold, SnapshotThreshold: defaultConf.RaftConfig.SnapshotThreshold,
ElectionTimeout: defaultConf.RaftConfig.ElectionTimeout,
HeartbeatTimeout: defaultConf.RaftConfig.HeartbeatTimeout,
} }
if config.RaftSnapshotThreshold != 0 { if config.RaftSnapshotThreshold != 0 {
raftCfg.SnapshotThreshold = uint64(config.RaftSnapshotThreshold) raftCfg.SnapshotThreshold = uint64(config.RaftSnapshotThreshold)
@ -1583,6 +1585,12 @@ func computeRaftReloadableConfig(config ReloadableConfig) raft.ReloadableConfig
if config.RaftTrailingLogs != 0 { if config.RaftTrailingLogs != 0 {
raftCfg.TrailingLogs = uint64(config.RaftTrailingLogs) 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 return raftCfg
} }
@ -1620,7 +1628,7 @@ func (s *Server) trackLeaderChanges() {
continue continue
} }
s.grpcLeaderForwarder.UpdateLeaderAddr(s.config.Datacenter, string(leaderObs.Leader)) s.grpcLeaderForwarder.UpdateLeaderAddr(s.config.Datacenter, string(leaderObs.LeaderAddr))
case <-s.shutdownCh: case <-s.shutdownCh:
s.raft.DeregisterObserver(observer) s.raft.DeregisterObserver(observer)
return return

View File

@ -1858,6 +1858,8 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) {
SnapshotThreshold: defaults.SnapshotThreshold, SnapshotThreshold: defaults.SnapshotThreshold,
SnapshotInterval: defaults.SnapshotInterval, SnapshotInterval: defaults.SnapshotInterval,
TrailingLogs: defaults.TrailingLogs, TrailingLogs: defaults.TrailingLogs,
ElectionTimeout: defaults.ElectionTimeout,
HeartbeatTimeout: defaults.HeartbeatTimeout,
}, },
}, },
{ {
@ -1869,6 +1871,8 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) {
SnapshotThreshold: 123456, SnapshotThreshold: 123456,
SnapshotInterval: defaults.SnapshotInterval, SnapshotInterval: defaults.SnapshotInterval,
TrailingLogs: defaults.TrailingLogs, TrailingLogs: defaults.TrailingLogs,
ElectionTimeout: defaults.ElectionTimeout,
HeartbeatTimeout: defaults.HeartbeatTimeout,
}, },
}, },
{ {
@ -1880,6 +1884,8 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) {
SnapshotThreshold: defaults.SnapshotThreshold, SnapshotThreshold: defaults.SnapshotThreshold,
SnapshotInterval: 13 * time.Minute, SnapshotInterval: 13 * time.Minute,
TrailingLogs: defaults.TrailingLogs, TrailingLogs: defaults.TrailingLogs,
ElectionTimeout: defaults.ElectionTimeout,
HeartbeatTimeout: defaults.HeartbeatTimeout,
}, },
}, },
{ {
@ -1891,6 +1897,8 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) {
SnapshotThreshold: defaults.SnapshotThreshold, SnapshotThreshold: defaults.SnapshotThreshold,
SnapshotInterval: defaults.SnapshotInterval, SnapshotInterval: defaults.SnapshotInterval,
TrailingLogs: 78910, TrailingLogs: 78910,
ElectionTimeout: defaults.ElectionTimeout,
HeartbeatTimeout: defaults.HeartbeatTimeout,
}, },
}, },
{ {
@ -1899,11 +1907,15 @@ func TestServer_computeRaftReloadableConfig(t *testing.T) {
RaftSnapshotThreshold: 123456, RaftSnapshotThreshold: 123456,
RaftSnapshotInterval: 13 * time.Minute, RaftSnapshotInterval: 13 * time.Minute,
RaftTrailingLogs: 78910, RaftTrailingLogs: 78910,
ElectionTimeout: 300 * time.Millisecond,
HeartbeatTimeout: 400 * time.Millisecond,
}, },
want: raft.ReloadableConfig{ want: raft.ReloadableConfig{
SnapshotThreshold: 123456, SnapshotThreshold: 123456,
SnapshotInterval: 13 * time.Minute, SnapshotInterval: 13 * time.Minute,
TrailingLogs: 78910, TrailingLogs: 78910,
ElectionTimeout: 300 * time.Millisecond,
HeartbeatTimeout: 400 * time.Millisecond,
}, },
}, },
} }

2
go.mod
View File

@ -53,7 +53,7 @@ require (
github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hil v0.0.0-20200423225030-a18a1cd20038 github.com/hashicorp/hil v0.0.0-20200423225030-a18a1cd20038
github.com/hashicorp/memberlist v0.3.1 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-autopilot v0.1.6
github.com/hashicorp/raft-boltdb v0.0.0-20211202195631-7d34b9fb3f42 // indirect github.com/hashicorp/raft-boltdb v0.0.0-20211202195631-7d34b9fb3f42 // indirect
github.com/hashicorp/raft-boltdb/v2 v2.2.2 github.com/hashicorp/raft-boltdb/v2 v2.2.2

4
go.sum
View File

@ -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.0/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM=
github.com/hashicorp/raft v1.1.1/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8= 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.2.0/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8=
github.com/hashicorp/raft v1.3.6 h1:v5xW5KzByoerQlN/o31VJrFNiozgzGyDoMgDJgXpsto= github.com/hashicorp/raft v1.3.8 h1:lrhx4wesQLOSv3ERX/pK4cwfzQ0J2RgzsvAkBxHe1bA=
github.com/hashicorp/raft v1.3.6/go.mod h1:4Ak7FSPnuvmb0GV6vgIAJ4vYT4bek9bb6Q+7HVbyzqM= 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 h1:C1q3RNF2FfXNZfHWbvVAu0QixaQK8K5pX4O5lh+9z4I=
github.com/hashicorp/raft-autopilot v0.1.6/go.mod h1:Af4jZBwaNOI+tXfIqIdbcAnh/UyyqIMj/pOISIfhArw= 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= github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea/go.mod h1:pNv7Wc3ycL6F5oOWn+tPGo2gWD4a5X+yp/ntwdKLjRk=