From b3cb38eda4b5bed60b4828c1e3fb7f9590b3ba40 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Mon, 24 Sep 2018 17:53:28 +0530 Subject: [PATCH] addressing review comments --- router/fastdp.go | 23 ++++++++++++++++++----- router/overlay_switch.go | 11 +++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/router/fastdp.go b/router/fastdp.go index 439c6c31..b9032e89 100644 --- a/router/fastdp.go +++ b/router/fastdp.go @@ -583,10 +583,10 @@ type fastDatapathForwarder struct { stopChan chan struct{} stopped bool healthy bool - - establishedChan chan struct{} - errorChan chan error - healthChan chan bool + established bool + establishedChan chan struct{} + errorChan chan error + healthChan chan bool } func (fastdp fastDatapathOverlay) PrepareConnection(params mesh.OverlayConnectionParams) (mesh.OverlayConnection, error) { @@ -725,6 +725,15 @@ func (fwd *fastDatapathForwarder) doHeartbeats() { // that Forwarder is un-healthy so it can pick next best forwarder fwd.healthChan <- false + // switch from fast-heartbeat to slow-heartbeat to avoid aggressive heartbeats + // when there is no estbalished session with peer yet + if fwd.heartbeatInterval != SlowHeartbeat { + fwd.heartbeatInterval = SlowHeartbeat + if fwd.heartbeatTimer != nil { + fwd.heartbeatTimer.Reset(fwd.heartbeatInterval) + } + } + if fwd.healthy { fwd.healthy = false } else { @@ -860,8 +869,12 @@ func (fwd *fastDatapathForwarder) Attrs() map[string]interface{} { func (fwd *fastDatapathForwarder) handleHeartbeatAck() { log.Debug(fwd.logPrefix(), "handleHeartbeatAck") - if fwd.heartbeatInterval != SlowHeartbeat { + if !fwd.established { close(fwd.establishedChan) + fwd.established = true + } + + if fwd.heartbeatInterval != SlowHeartbeat { fwd.heartbeatInterval = SlowHeartbeat if fwd.heartbeatTimer != nil { fwd.heartbeatTimer.Reset(fwd.heartbeatInterval) diff --git a/router/overlay_switch.go b/router/overlay_switch.go index b7268846..7fcd564d 100644 --- a/router/overlay_switch.go +++ b/router/overlay_switch.go @@ -172,7 +172,7 @@ type subForwarderEvent struct { err error // event to indicate if forwarder is in healthy state to be considered for best forwarded - healthy bool + healthy *bool } func (osw *OverlaySwitch) PrepareConnection(params mesh.OverlayConnectionParams) (mesh.OverlayConnection, error) { @@ -246,7 +246,6 @@ func (osw *OverlaySwitch) PrepareConnection(params mesh.OverlayConnectionParams) func monitorForwarder(index int, eventsChan chan<- subForwarderEvent, stopChan <-chan struct{}, fwd OverlayForwarder) { establishedChan := fwd.EstablishedChannel() - healthChan := fwd.HealthChannel() loop: for { e := subForwarderEvent{index: index} @@ -256,8 +255,8 @@ loop: e.established = true establishedChan = nil - case healthy := <-healthChan: - e.healthy = healthy + case healthy := <-fwd.HealthChannel(): + e.healthy = &healthy case err := <-fwd.ErrorChannel(): e.err = err @@ -293,8 +292,8 @@ loop: fwd.established(e.index) case e.err != nil: fwd.error(e.index, e.err) - default: - fwd.healthCheck(e.index, e.healthy) + case e.healthy != nil: + fwd.healthCheck(e.index, *e.healthy) } } }