Implement weave consense
This commit is contained in:
1 parent
7c65b6e3bb
commit
6584df274e
5 files changed
+59
No files matched your search
@@ -54,6 +54,7 @@ type Allocator struct {
|
||||
nicknames map[mesh.PeerName]string // so we can map nicknames for rmpeer
|
||||
pendingAllocates []operation // held until we get some free space
|
||||
pendingClaims []operation // held until we know who owns the space
|
||||
pendingConsenses []operation // held until consensus achieved
|
||||
dead map[string]time.Time // containers we heard were dead, and when
|
||||
db db.DB // persistence
|
||||
gossip mesh.Gossip // our link to the outside world for sending messages
|
||||
@@ -165,6 +166,8 @@ func (alloc *Allocator) tryOps(ops *[]operation) {
|
||||
|
||||
// Try all pending operations
|
||||
func (alloc *Allocator) tryPendingOps() {
|
||||
// Unblock pending consenses first
|
||||
alloc.tryOps(&alloc.pendingConsenses)
|
||||
// Process existing claims before servicing new allocations
|
||||
alloc.tryOps(&alloc.pendingClaims)
|
||||
alloc.tryOps(&alloc.pendingAllocates)
|
||||
@@ -193,6 +196,14 @@ func (e *errorCancelled) Error() string {
|
||||
|
||||
// Actor client API
|
||||
|
||||
// Consense (Sync) - wait for consensus
|
||||
func (alloc *Allocator) Consense() {
|
||||
resultChan := make(chan struct{})
|
||||
op := &consense{resultChan: resultChan}
|
||||
alloc.doOperation(op, &alloc.pendingConsenses)
|
||||
<-resultChan
|
||||
}
|
||||
|
||||
// Allocate (Sync) - get new IP address for container with given name in range
|
||||
// if there isn't any space in that range we block indefinitely
|
||||
func (alloc *Allocator) Allocate(ident string, r address.CIDR, hasBeenCancelled func() bool) (address.Address, error) {
|
||||
@@ -343,6 +354,7 @@ func (alloc *Allocator) Shutdown() {
|
||||
alloc.shuttingDown = true
|
||||
alloc.cancelOps(&alloc.pendingClaims)
|
||||
alloc.cancelOps(&alloc.pendingAllocates)
|
||||
alloc.cancelOps(&alloc.pendingConsenses)
|
||||
if heir := alloc.pickPeerForTransfer(); heir != mesh.UnknownPeerName {
|
||||
alloc.ring.Transfer(alloc.ourName, heir)
|
||||
alloc.space.Clear()
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package ipam
|
||||
|
||||
type consense struct {
|
||||
resultChan chan<- struct{}
|
||||
}
|
||||
|
||||
func (c *consense) Try(alloc *Allocator) bool {
|
||||
if !alloc.ring.Empty() {
|
||||
close(c.resultChan)
|
||||
return true
|
||||
}
|
||||
|
||||
alloc.establishRing()
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *consense) Cancel() {
|
||||
close(c.resultChan)
|
||||
}
|
||||
|
||||
func (c *consense) ForContainer(ident string) bool {
|
||||
return false
|
||||
}
|
||||
@@ -82,6 +82,10 @@ func (alloc *Allocator) HandleHTTP(router *mux.Router, defaultSubnet address.CID
|
||||
}
|
||||
})
|
||||
|
||||
router.Methods("GET").Path("/consensus").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
alloc.Consense()
|
||||
})
|
||||
|
||||
router.Methods("GET").Path("/ip/{id}/{ip}/{prefixlen}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
if subnet, ok := parseCIDR(w, vars["ip"]+"/"+vars["prefixlen"], true); ok {
|
||||
|
||||
Reference in new issue
Block a user