discarded host handler
This commit is contained in:
@@ -22,12 +22,13 @@ type HealthHandler interface {
|
||||
}
|
||||
|
||||
type SyncedPool struct {
|
||||
Server *GenericListener
|
||||
mu sync.RWMutex
|
||||
Hostname string
|
||||
local *GrainLocalPool
|
||||
remotes map[string]*RemoteHost
|
||||
remoteIndex map[CartId]*RemoteGrain
|
||||
Server *GenericListener
|
||||
mu sync.RWMutex
|
||||
discardedHostHandler *DiscardedHostHandler
|
||||
Hostname string
|
||||
local *GrainLocalPool
|
||||
remotes map[string]*RemoteHost
|
||||
remoteIndex map[CartId]*RemoteGrain
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -110,13 +111,13 @@ func (p *SyncedPool) GrainOwnerChangeHandler(data *FrameWithPayload, resultChan
|
||||
|
||||
idAndHostParts := strings.Split(string(data.Payload), ";")
|
||||
if len(idAndHostParts) != 2 {
|
||||
log.Printf("Invalid remote grain change message\n")
|
||||
log.Printf("Invalid remote grain change message")
|
||||
resultChan <- MakeFrameWithPayload(AckError, 500, []byte("invalid"))
|
||||
return nil
|
||||
}
|
||||
id := ToCartId(idAndHostParts[0])
|
||||
host := idAndHostParts[1]
|
||||
log.Printf("Handling remote grain owner change to %s for id %s\n", host, id)
|
||||
log.Printf("Handling remote grain owner change to %s for id %s", host, id)
|
||||
for _, r := range p.remotes {
|
||||
if r.Host == host && r.IsHealthy() {
|
||||
go p.SpawnRemoteGrain(id, host)
|
||||
@@ -136,11 +137,11 @@ func (p *SyncedPool) RemoveRemoteGrain(id CartId) {
|
||||
|
||||
func (p *SyncedPool) SpawnRemoteGrain(id CartId, host string) {
|
||||
if id.String() == "" {
|
||||
log.Printf("Invalid grain id, %s\n", id)
|
||||
log.Printf("Invalid grain id, %s", id)
|
||||
return
|
||||
}
|
||||
if p.local.grains[id] != nil {
|
||||
log.Printf("Grain %s already exists locally, owner is (%s)\n", id, host)
|
||||
log.Printf("Grain %s already exists locally, owner is (%s)", id, host)
|
||||
p.mu.Lock()
|
||||
delete(p.local.grains, id)
|
||||
p.mu.Unlock()
|
||||
@@ -148,15 +149,9 @@ func (p *SyncedPool) SpawnRemoteGrain(id CartId, host string) {
|
||||
|
||||
remote, err := NewRemoteGrain(id, host)
|
||||
if err != nil {
|
||||
log.Printf("Error creating remote grain %v\n", err)
|
||||
log.Printf("Error creating remote grain %v", err)
|
||||
return
|
||||
}
|
||||
// go func() {
|
||||
// <-remote.Died
|
||||
// p.RemoveRemoteGrain(id)
|
||||
// p.HandleHostError(host)
|
||||
// log.Printf("Remote grain %s died, host: %s\n", id.String(), host)
|
||||
// }()
|
||||
|
||||
p.mu.Lock()
|
||||
p.remoteIndex[id] = remote
|
||||
@@ -183,16 +178,16 @@ func NewSyncedPool(local *GrainLocalPool, hostname string, discovery Discovery)
|
||||
}
|
||||
|
||||
log.Printf("Listening on %s", listen)
|
||||
|
||||
dh := NewDiscardedHostHandler(1338)
|
||||
pool := &SyncedPool{
|
||||
Server: server,
|
||||
Hostname: hostname,
|
||||
local: local,
|
||||
|
||||
remotes: make(map[string]*RemoteHost),
|
||||
remoteIndex: make(map[CartId]*RemoteGrain),
|
||||
Server: server,
|
||||
Hostname: hostname,
|
||||
local: local,
|
||||
discardedHostHandler: dh,
|
||||
remotes: make(map[string]*RemoteHost),
|
||||
remoteIndex: make(map[CartId]*RemoteGrain),
|
||||
}
|
||||
|
||||
dh.SetReconnectHandler(pool.AddRemote)
|
||||
server.AddHandler(Ping, pool.PongHandler)
|
||||
server.AddHandler(GetCartIds, pool.GetCartIdHandler)
|
||||
server.AddHandler(RemoteNegotiate, pool.NegotiateHandler)
|
||||
@@ -266,11 +261,11 @@ func (p *SyncedPool) ExcludeKnown(hosts []string) []string {
|
||||
}
|
||||
|
||||
func (p *SyncedPool) RemoveHost(host *RemoteHost) {
|
||||
|
||||
p.mu.Lock()
|
||||
delete(p.remotes, host.Host)
|
||||
p.mu.Unlock()
|
||||
p.RemoveHostMappedCarts(host)
|
||||
p.discardedHostHandler.AppendHost(host.Host)
|
||||
connectedRemotes.Set(float64(len(p.remotes)))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user