Rename 'reclaim' to 'noErrorUnknown' which describes the behaviour better

This commit is contained in:
Bryan Boreham committed 2015-07-23 20:16:30 +01:00
1 parent 647b755b64
commit f0915221d1
4 files changed
+13 -14

No files matched your search

+2 -2
View File
@@ -215,9 +215,9 @@ func (alloc *Allocator) Lookup(ident string, r address.Range) (address.Address,
} }
// Claim an address that we think we should own (Sync) // Claim an address that we think we should own (Sync)
func (alloc *Allocator) Claim(ident string, addr address.Address, reclaim bool) error { func (alloc *Allocator) Claim(ident string, addr address.Address, noErrorOnUnknown bool) error {
resultChan := make(chan error) resultChan := make(chan error)
op := &claim{resultChan: resultChan, ident: ident, addr: addr, reclaim: reclaim} op := &claim{resultChan: resultChan, ident: ident, addr: addr, noErrorOnUnknown: noErrorOnUnknown}
alloc.doOperation(op, &alloc.pendingClaims) alloc.doOperation(op, &alloc.pendingClaims)
return <-resultChan return <-resultChan
} }
+8 -9
View File
@@ -9,12 +9,13 @@ import (
) )
type claim struct { type claim struct {
resultChan chan<- error resultChan chan<- error
ident string ident string
addr address.Address addr address.Address
reclaim bool noErrorOnUnknown bool
} }
// 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
if c.resultChan != nil { if c.resultChan != nil {
@@ -32,9 +33,7 @@ func (c *claim) sendResult(result error) {
func (c *claim) Try(alloc *Allocator) bool { func (c *claim) Try(alloc *Allocator) bool {
if !alloc.ring.Contains(c.addr) { if !alloc.ring.Contains(c.addr) {
// Address not within our universe; assume user knows what they are doing // Address not within our universe; assume user knows what they are doing
if c.reclaim { alloc.infof("Ignored address %s claimed by %s - not in our universe", c.addr, c.ident)
alloc.infof("Ignored address %s claimed by %s - not in our universe", c.addr, c.ident)
}
c.sendResult(nil) c.sendResult(nil)
return true return true
} }
@@ -44,7 +43,7 @@ func (c *claim) Try(alloc *Allocator) bool {
// success // success
case router.UnknownPeerName: case router.UnknownPeerName:
// If our ring doesn't know, it must be empty. // If our ring doesn't know, it must be empty.
if c.reclaim { if c.noErrorOnUnknown {
alloc.infof("Claim %s for %s: address allocator still initializing; will try later.", c.addr, c.ident) alloc.infof("Claim %s for %s: address allocator still initializing; will try later.", c.addr, c.ident)
c.sendResult(nil) // don't make the caller wait c.sendResult(nil) // don't make the caller wait
} else { } else {
@@ -55,7 +54,7 @@ func (c *claim) Try(alloc *Allocator) bool {
alloc.debugf("requesting address %s from other peer %s", c.addr, owner) alloc.debugf("requesting address %s from other peer %s", c.addr, owner)
err := alloc.sendSpaceRequest(owner, address.NewRange(c.addr, 1)) err := alloc.sendSpaceRequest(owner, address.NewRange(c.addr, 1))
if err != nil { // can't speak to owner right now if err != nil { // can't speak to owner right now
if c.reclaim { // don't hold up launch; figure it out later if c.noErrorOnUnknown {
alloc.infof("Claim %s for %s: %s; will try later.", c.addr, c.ident, err) alloc.infof("Claim %s for %s: %s; will try later.", c.addr, c.ident, err)
c.sendResult(nil) c.sendResult(nil)
} else { // just tell the user they can't do this. } else { // just tell the user they can't do this.
+2 -2
View File
@@ -22,11 +22,11 @@ func (alloc *Allocator) HandleHTTP(router *mux.Router, defaultSubnet address.CID
vars := mux.Vars(r) vars := mux.Vars(r)
ident := vars["id"] ident := vars["id"]
ipStr := vars["ip"] ipStr := vars["ip"]
reclaim := r.FormValue("reclaim") == "true" noErrorOnUnknown := r.FormValue("noErrorOnUnknown") == "true"
if ip, err := address.ParseIP(ipStr); err != nil { if ip, err := address.ParseIP(ipStr); err != nil {
badRequest(w, err) badRequest(w, err)
return return
} else if err := alloc.Claim(ident, ip, reclaim); err != nil { } else if err := alloc.Claim(ident, ip, noErrorOnUnknown); err != nil {
badRequest(w, fmt.Errorf("Unable to claim: %s", err)) badRequest(w, fmt.Errorf("Unable to claim: %s", err))
return return
} }
+1 -1
View File
@@ -815,7 +815,7 @@ delete_dns_fqdn() {
ipam_reclaim() { ipam_reclaim() {
for CIDR in $3 ; do for CIDR in $3 ; do
# NB: CONTAINER_IP is the IP of the weave container; it is set by wait_for_status. # NB: CONTAINER_IP is the IP of the weave container; it is set by wait_for_status.
http_call_ip $CONTAINER_IP $HTTP_PORT PUT /ip/$1/${CIDR%/*}?reclaim=true http_call_ip $CONTAINER_IP $HTTP_PORT PUT /ip/$1/${CIDR%/*}?noErrorOnUnknown=true
done done
} }