Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1662 from dongluochen/avoidSimultaneousValidation
Browse files Browse the repository at this point in the history
Enforce minimum backoff to avoid simultaneous validation on one engine
  • Loading branch information
vieux committed Jan 21, 2016
2 parents cd68850 + 46a33f7 commit 5cb6f21
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cluster/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,18 @@ func (e *Engine) setState(state engineState) {
// TimeToValidate returns true if a pending node is up for validation
func (e *Engine) TimeToValidate() bool {
const validationLimit time.Duration = 4 * time.Hour
const failureBackoff time.Duration = 30 * time.Second
const minFailureBackoff time.Duration = 30 * time.Second
e.Lock()
defer e.Unlock()
if e.state != statePending {
return false
}
sinceLastUpdate := time.Since(e.updatedAt)
// Increase check interval for a pending engine according to failureCount and cap it at a limit
if sinceLastUpdate > validationLimit || sinceLastUpdate > time.Duration(e.failureCount)*failureBackoff {
// it's exponential backoff = 2 ^ failureCount + minFailureBackoff. A minimum backoff is
// needed because e.failureCount could be 0 at first join, or the engine has a duplicate ID
if sinceLastUpdate > validationLimit ||
sinceLastUpdate > (1<<uint(e.failureCount))*time.Second+minFailureBackoff {
return true
}
return false
Expand Down

0 comments on commit 5cb6f21

Please sign in to comment.