handle ping
This commit is contained in:
@@ -369,18 +369,19 @@ func (p *SyncedPool) removeLocalGrain(id CartId) {
|
||||
}
|
||||
|
||||
func (p *SyncedPool) AddRemote(host string) {
|
||||
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
_, hasHost := p.remotes[host]
|
||||
if host == "" || hasHost || host == p.Hostname {
|
||||
return
|
||||
}
|
||||
|
||||
client := NewConnection(fmt.Sprintf("%s:1338", host))
|
||||
var r *FrameWithPayload
|
||||
|
||||
var err error
|
||||
pings := 3
|
||||
for pings >= 0 {
|
||||
r, err = client.Call(Ping, nil)
|
||||
_, err = client.Call(Ping, nil)
|
||||
if err != nil {
|
||||
log.Printf("Ping failed when adding %s, trying %d more times\n", host, pings)
|
||||
pings--
|
||||
@@ -389,18 +390,23 @@ func (p *SyncedPool) AddRemote(host string) {
|
||||
}
|
||||
break
|
||||
}
|
||||
log.Printf("Connected to remote %s: %v\n", host, r)
|
||||
log.Printf("Connected to remote %s", host)
|
||||
|
||||
remote := RemoteHost{
|
||||
Connection: client,
|
||||
MissedPings: 0,
|
||||
Host: host,
|
||||
}
|
||||
p.mu.Lock()
|
||||
p.remotes[host] = &remote
|
||||
p.mu.Unlock()
|
||||
|
||||
go func() {
|
||||
p.remotes[host] = &remote
|
||||
|
||||
connectedRemotes.Set(float64(len(p.remotes)))
|
||||
|
||||
go p.HandlePing(&remote)
|
||||
go remote.Initialize(p)
|
||||
}
|
||||
|
||||
func (p *SyncedPool) HandlePing(remote *RemoteHost) {
|
||||
for range time.Tick(time.Second * 3) {
|
||||
|
||||
err := remote.Ping()
|
||||
@@ -408,20 +414,13 @@ func (p *SyncedPool) AddRemote(host string) {
|
||||
for err != nil {
|
||||
time.Sleep(time.Millisecond * 200)
|
||||
if !remote.IsHealthy() {
|
||||
log.Printf("Removing host, unable to communicate with %s", host)
|
||||
p.RemoveHost(&remote)
|
||||
log.Printf("Removing host, unable to communicate with %s", remote.Host)
|
||||
p.RemoveHost(remote)
|
||||
return
|
||||
}
|
||||
err = remote.Ping()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
connectedRemotes.Set(float64(len(p.remotes)))
|
||||
log.Printf("Added remote %s\n", remote.Host)
|
||||
|
||||
go remote.Initialize(p)
|
||||
return
|
||||
}
|
||||
|
||||
func (p *SyncedPool) getGrain(id CartId) (Grain, error) {
|
||||
|
||||
Reference in New Issue
Block a user