Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ type FailOverConfig struct {
// EnableSlaveHAUpdate controls whether HA logic marks failed slave nodes and
// propagates the updated topology. Requires kvrocks to support node status
// modification (new versions only). Defaults to false for backward compatibility.
EnableSlaveHAUpdate bool `yaml:"enable_slave_ha_update"`
WaitForSync bool `yaml:"wait_for_sync"`
EnableSlaveHAUpdate bool `yaml:"enable_slave_ha_update"`
WaitForSync bool `yaml:"wait_for_sync"`
VoteTimeoutMs int `yaml:"vote_timeout_ms"`
VoteThresholdRatio float64 `yaml:"vote_threshold_ratio"`
}

type ControllerConfig struct {
Expand Down Expand Up @@ -81,6 +83,8 @@ func DefaultFailOverConfig() *FailOverConfig {
return &FailOverConfig{
PingIntervalSeconds: 3,
MaxPingCount: 5,
VoteTimeoutMs: 2000,
VoteThresholdRatio: 0.6,
}
}

Expand All @@ -104,6 +108,12 @@ func (c *Config) Validate() error {
if c.Controller.FailOver.PingIntervalSeconds < 1 {
return errors.New("ping interval required >= 1s")
}
if c.Controller.FailOver.VoteTimeoutMs < 1 {
return errors.New("vote_timeout_ms required >= 1 (0 causes all peer votes to time out immediately)")
}
if c.Controller.FailOver.VoteThresholdRatio <= 0 || c.Controller.FailOver.VoteThresholdRatio > 1.0 {
return errors.New("vote_threshold_ratio must be in range (0, 1.0]")
}
hostPort := strings.Split(c.Addr, ":")
if hostPort[0] == "0.0.0.0" || hostPort[0] == "127.0.0.1" {
logger.Get().Warn("Leader forward may not work if the host is " + hostPort[0])
Expand Down
8 changes: 8 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ import (
"github.com/stretchr/testify/assert"
)

func TestDefaultFailOverConfig_VoteDefaults(t *testing.T) {
cfg := DefaultFailOverConfig()
assert.Equal(t, 2000, cfg.VoteTimeoutMs)
assert.InDelta(t, 0.6, cfg.VoteThresholdRatio, 1e-9)
}

func TestDefaultControllerConfigSet(t *testing.T) {
cfg := Default()
expectedControllerConfig := &ControllerConfig{
FailOver: &FailOverConfig{
PingIntervalSeconds: 3,
MaxPingCount: 5,
VoteTimeoutMs: 2000,
VoteThresholdRatio: 0.6,
},
}

Expand Down
Loading