feat(proxyd): use a specific redis instance for consensus_ha (#9877)

This commit is contained in:
felipe 2024-03-18 11:26:39 -07:00 committed by GitHub
parent 89cb5f5057
commit fcf6e3323d
2 changed files with 8 additions and 3 deletions

@ -123,6 +123,7 @@ type BackendGroupConfig struct {
ConsensusHA bool `toml:"consensus_ha"` ConsensusHA bool `toml:"consensus_ha"`
ConsensusHAHeartbeatInterval TOMLDuration `toml:"consensus_ha_heartbeat_interval"` ConsensusHAHeartbeatInterval TOMLDuration `toml:"consensus_ha_heartbeat_interval"`
ConsensusHALockPeriod TOMLDuration `toml:"consensus_ha_lock_period"` ConsensusHALockPeriod TOMLDuration `toml:"consensus_ha_lock_period"`
ConsensusHARedis RedisConfig `toml:"consensus_ha_redis"`
} }
type BackendGroupsConfig map[string]*BackendGroupConfig type BackendGroupsConfig map[string]*BackendGroupConfig

@ -335,8 +335,8 @@ func Start(config *Config) (*Server, func(), error) {
var tracker ConsensusTracker var tracker ConsensusTracker
if bgcfg.ConsensusHA { if bgcfg.ConsensusHA {
if redisClient == nil { if bgcfg.ConsensusHARedis.URL == "" {
log.Crit("cant start - consensus high availability requires redis") log.Crit("must specify a consensus_ha_redis config when consensus_ha is true")
} }
topts := make([]RedisConsensusTrackerOpt, 0) topts := make([]RedisConsensusTrackerOpt, 0)
if bgcfg.ConsensusHALockPeriod > 0 { if bgcfg.ConsensusHALockPeriod > 0 {
@ -345,7 +345,11 @@ func Start(config *Config) (*Server, func(), error) {
if bgcfg.ConsensusHAHeartbeatInterval > 0 { if bgcfg.ConsensusHAHeartbeatInterval > 0 {
topts = append(topts, WithLockPeriod(time.Duration(bgcfg.ConsensusHAHeartbeatInterval))) topts = append(topts, WithLockPeriod(time.Duration(bgcfg.ConsensusHAHeartbeatInterval)))
} }
tracker = NewRedisConsensusTracker(context.Background(), redisClient, bg, bg.Name, topts...) consensusHARedisClient, err := NewRedisClient(bgcfg.ConsensusHARedis.URL)
if err != nil {
return nil, nil, err
}
tracker = NewRedisConsensusTracker(context.Background(), consensusHARedisClient, bg, bg.Name, topts...)
copts = append(copts, WithTracker(tracker)) copts = append(copts, WithTracker(tracker))
} }