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