Retry IP allocator claims
It may be that we cannot talk to a peer straight away, so allow claims to be retried a few times before giving up.
This commit is contained in:
1 parent
6a48da60ec
commit
e8fcd21baa
1 file changed
+9
-2
+9
-2
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
type claim struct {
|
type claim struct {
|
||||||
resultChan chan<- error
|
resultChan chan<- error
|
||||||
|
tryCount int
|
||||||
ident string // a container ID, something like "weave:expose", or api.NoContainerID
|
ident string // a container ID, something like "weave:expose", or api.NoContainerID
|
||||||
cidr address.CIDR // single address being claimed
|
cidr address.CIDR // single address being claimed
|
||||||
isContainer bool // true if ident is a container ID
|
isContainer bool // true if ident is a container ID
|
||||||
@@ -19,6 +20,8 @@ type claim struct {
|
|||||||
hasBeenCancelled func() bool
|
hasBeenCancelled func() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxTryCount = 5
|
||||||
|
|
||||||
// Send an error (or nil for success) back to caller listening on resultChan
|
// Send an error (or nil for success) back to caller listening on resultChan
|
||||||
func (c *claim) sendResult(result error) {
|
func (c *claim) sendResult(result error) {
|
||||||
// Make sure we only send a result once, since listener stops listening after that
|
// Make sure we only send a result once, since listener stops listening after that
|
||||||
@@ -40,6 +43,8 @@ func (c *claim) Try(alloc *Allocator) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.tryCount++
|
||||||
|
|
||||||
addOwned := func() {
|
addOwned := func() {
|
||||||
if c.ident == api.NoContainerID {
|
if c.ident == api.NoContainerID {
|
||||||
alloc.addOwned(c.cidr.Addr.String(), c.cidr, c.isContainer)
|
alloc.addOwned(c.cidr.Addr.String(), c.cidr, c.isContainer)
|
||||||
@@ -90,8 +95,10 @@ func (c *claim) Try(alloc *Allocator) bool {
|
|||||||
if c.noErrorOnUnknown {
|
if c.noErrorOnUnknown {
|
||||||
alloc.infof("Claim %s for %s: %s; will try later.", c.cidr, c.ident, err)
|
alloc.infof("Claim %s for %s: %s; will try later.", c.cidr, c.ident, err)
|
||||||
c.sendResult(nil)
|
c.sendResult(nil)
|
||||||
} else { // just tell the user they can't do this.
|
} else if c.tryCount > maxTryCount {
|
||||||
c.deniedBy(alloc, owner)
|
// give up, tell the user they can't do this
|
||||||
|
c.deniedBy(alloc, owner, err)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in new issue
Block a user