mirror of
https://github.com/Icinga/icingadb.git
synced 2026-06-04 06:17:01 -04:00
HA: prefer new Icinga 2 heartbeat over forced update
This commit is contained in:
parent
3f6a6534c1
commit
2957f32c77
1 changed files with 16 additions and 2 deletions
18
ha/ha.go
18
ha/ha.go
|
|
@ -310,15 +310,29 @@ func (h *HA) runHA(chEnv chan *Environment, env *Environment) {
|
|||
updateTimer := time.NewTimer(updateTimerDuration)
|
||||
|
||||
for {
|
||||
var newEnv *Environment
|
||||
|
||||
// Selecting from multiple channels does not guarantee which case gets executed if multiple ones
|
||||
// are ready. However, when both a new environment is available and the update timer expired, we
|
||||
// want to prefer the new environment. Therefore first try to select only from chEnv and only if
|
||||
// there is nothing in the channel, i.e. in the default case, select from both channels.
|
||||
select {
|
||||
case env = <-chEnv:
|
||||
case newEnv = <-chEnv:
|
||||
default:
|
||||
select {
|
||||
case newEnv = <-chEnv:
|
||||
case <-updateTimer.C:
|
||||
}
|
||||
}
|
||||
|
||||
if newEnv != nil {
|
||||
env = newEnv
|
||||
if bytes.Compare(env.ID, h.super.EnvId) != 0 {
|
||||
h.logger.Error("Received environment is not the one we expected. Panic.")
|
||||
h.super.ChErr <- errors.New("received unexpected environment")
|
||||
return
|
||||
}
|
||||
h.lastHeartbeat = utils.TimeToMillisecs(time.Now())
|
||||
case <-updateTimer.C: // force update
|
||||
}
|
||||
|
||||
updateTimer.Reset(updateTimerDuration)
|
||||
|
|
|
|||
Loading…
Reference in a new issue