handle ping
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 27s
Build and Publish / BuildAndDeploy (push) Successful in 2m24s

This commit is contained in:
matst80
2024-11-14 08:54:16 +01:00
parent 8bbe3a6f51
commit d9563460f7

View File

@@ -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,39 +390,37 @@ 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() {
for range time.Tick(time.Second * 3) {
err := remote.Ping()
for err != nil {
time.Sleep(time.Millisecond * 200)
if !remote.IsHealthy() {
log.Printf("Removing host, unable to communicate with %s", host)
p.RemoveHost(&remote)
return
}
err = remote.Ping()
}
}
}()
connectedRemotes.Set(float64(len(p.remotes)))
log.Printf("Added remote %s\n", remote.Host)
go p.HandlePing(&remote)
go remote.Initialize(p)
return
}
func (p *SyncedPool) HandlePing(remote *RemoteHost) {
for range time.Tick(time.Second * 3) {
err := remote.Ping()
for err != nil {
time.Sleep(time.Millisecond * 200)
if !remote.IsHealthy() {
log.Printf("Removing host, unable to communicate with %s", remote.Host)
p.RemoveHost(remote)
return
}
err = remote.Ping()
}
}
}
func (p *SyncedPool) getGrain(id CartId) (Grain, error) {