Skip to content

Commit

Permalink
add config to disable raft prevote
Browse files Browse the repository at this point in the history
  • Loading branch information
dhiaayachi committed Sep 17, 2024
1 parent 4e20f8c commit 93e4612
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,9 @@ func newConsulConfig(runtimeCfg *config.RuntimeConfig, logger hclog.Logger) (*co
cfg.GRPCTLSPort = runtimeCfg.GRPCTLSPort

cfg.Segment = runtimeCfg.SegmentName

cfg.RaftConfig.PreVoteDisabled = runtimeCfg.RaftPreVoteDisabled

if len(runtimeCfg.Segments) > 0 {
segments, err := segmentConfig(runtimeCfg)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions agent/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
RaftSnapshotThreshold: intVal(c.RaftSnapshotThreshold),
RaftSnapshotInterval: b.durationVal("raft_snapshot_interval", c.RaftSnapshotInterval),
RaftTrailingLogs: intVal(c.RaftTrailingLogs),
RaftPreVoteDisabled: boolVal(c.RaftPreVoteDisabled),
RaftLogStoreConfig: b.raftLogStoreConfigVal(&c.RaftLogStore),
ReconnectTimeoutLAN: b.durationVal("reconnect_timeout", c.ReconnectTimeoutLAN),
ReconnectTimeoutWAN: b.durationVal("reconnect_timeout_wan", c.ReconnectTimeoutWAN),
Expand Down
4 changes: 3 additions & 1 deletion agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"fmt"
"time"

"github.com/hashicorp/hcl"
"github.com/mitchellh/mapstructure"

"github.com/hashicorp/hcl"

"github.com/hashicorp/consul/lib/decode"
)

Expand Down Expand Up @@ -214,6 +215,7 @@ type Config struct {
RaftSnapshotThreshold *int `mapstructure:"raft_snapshot_threshold" json:"raft_snapshot_threshold,omitempty"`
RaftSnapshotInterval *string `mapstructure:"raft_snapshot_interval" json:"raft_snapshot_interval,omitempty"`
RaftTrailingLogs *int `mapstructure:"raft_trailing_logs" json:"raft_trailing_logs,omitempty"`
RaftPreVoteDisabled *bool `mapstructure:"raft_prevote_disabled" json:"raft_prevote_disabled,omitempty"`
ReconnectTimeoutLAN *string `mapstructure:"reconnect_timeout" json:"reconnect_timeout,omitempty"`
ReconnectTimeoutWAN *string `mapstructure:"reconnect_timeout_wan" json:"reconnect_timeout_wan,omitempty"`
RejoinAfterLeave *bool `mapstructure:"rejoin_after_leave" json:"rejoin_after_leave,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions agent/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func DefaultSource() Source {
raft_snapshot_threshold = ` + strconv.Itoa(int(cfg.RaftConfig.SnapshotThreshold)) + `
raft_snapshot_interval = "` + cfg.RaftConfig.SnapshotInterval.String() + `"
raft_trailing_logs = ` + strconv.Itoa(int(cfg.RaftConfig.TrailingLogs)) + `
raft_prevote_disabled = false
raft_logstore {
wal {
segment_size_mb = 64
Expand Down
6 changes: 5 additions & 1 deletion agent/config/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"strings"
"time"

"github.com/hashicorp/go-uuid"
"golang.org/x/time/rate"

"github.com/hashicorp/go-uuid"

"github.com/hashicorp/consul/agent/cache"
"github.com/hashicorp/consul/agent/consul"
consulrate "github.com/hashicorp/consul/agent/consul/rate"
Expand Down Expand Up @@ -1004,6 +1005,9 @@ type RuntimeConfig struct {
// hcl: raft_trailing_logs = int
RaftTrailingLogs int

// hcl: raft_prevote_disabled = bool
RaftPreVoteDisabled bool

RaftLogStoreConfig consul.RaftLogStoreConfig

// ReconnectTimeoutLAN specifies the amount of time to wait to reconnect with
Expand Down
1 change: 1 addition & 0 deletions agent/config/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6594,6 +6594,7 @@ func TestLoad_FullConfig(t *testing.T) {
RaftSnapshotThreshold: 16384,
RaftSnapshotInterval: 30 * time.Second,
RaftTrailingLogs: 83749,
RaftPreVoteDisabled: false,
ReconnectTimeoutLAN: 23739 * time.Second,
ReconnectTimeoutWAN: 26694 * time.Second,
RequestLimitsMode: consulrate.ModePermissive,
Expand Down
2 changes: 2 additions & 0 deletions agent/config/testdata/TestRuntimeConfig_Sanitize.golden
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"AutopilotDisableUpgradeMigration": false,
"AutopilotLastContactThreshold": "0s",
"AutopilotMaxTrailingLogs": 0,

"AutopilotMinQuorum": 0,
"AutopilotRedundancyZoneTag": "",
"AutopilotServerStabilizationTime": "0s",
Expand Down Expand Up @@ -299,6 +300,7 @@
"RaftSnapshotInterval": "0s",
"RaftSnapshotThreshold": 0,
"RaftTrailingLogs": 0,
"RaftPreVoteDisabled": false,
"ReadReplica": false,
"ReconnectTimeoutLAN": "0s",
"ReconnectTimeoutWAN": "0s",
Expand Down

0 comments on commit 93e4612

Please sign in to comment.