From fa37db6f637beada8dabdbeee19b75c6e7d246e2 Mon Sep 17 00:00:00 2001 From: matst80 Date: Sat, 9 Nov 2024 20:13:47 +0100 Subject: [PATCH] pointer and ping misses --- synced-pool.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/synced-pool.go b/synced-pool.go index 5f31a5d..d839343 100644 --- a/synced-pool.go +++ b/synced-pool.go @@ -55,9 +55,10 @@ type Quorum interface { } type RemoteHost struct { - Host string - Pool *RemoteGrainPool - connection net.Conn + Host string + MissedPings int + Pool *RemoteGrainPool + connection net.Conn } type SyncedPool struct { @@ -65,7 +66,7 @@ type SyncedPool struct { listener net.Listener Hostname string local *GrainLocalPool - remotes []RemoteHost + remotes []*RemoteHost remoteIndex map[CartId]*RemoteGrainPool } @@ -81,7 +82,7 @@ func NewSyncedPool(local *GrainLocalPool, hostname string, d Discovery) (*Synced Hostname: hostname, local: local, listener: l, - remotes: make([]RemoteHost, 0), + remotes: make([]*RemoteHost, 0), remoteIndex: make(map[CartId]*RemoteGrainPool), } if d != nil { @@ -126,6 +127,13 @@ func NewSyncedPool(local *GrainLocalPool, hostname string, d Discovery) (*Synced log.Printf("Error adding undiscovered remote %s: %v\n", h, err) } } + for _, r := range pool.remotes { + err := DoPing(r.connection) + if err != nil { + r.MissedPings++ + log.Printf("Error pinging remote %s: %v\n, missed pings: %d", r.Host, err, r.MissedPings) + } + } }() } go func() { @@ -324,7 +332,7 @@ func (p *SyncedPool) AddRemoteWithConnection(address string, connection net.Conn Pool: pool, Host: address, } - return p.addRemoteHost(address, remote) + return p.addRemoteHost(address, &remote) } func DoPing(connection net.Conn) error { @@ -341,7 +349,7 @@ func DoPing(connection net.Conn) error { return nil } -func (p *SyncedPool) addRemoteHost(address string, remote RemoteHost) error { +func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error { for _, r := range p.remotes { if r.Host == address { log.Printf("Remote %s already exists\n", address) @@ -376,7 +384,7 @@ func (p *SyncedPool) AddRemote(address string) error { Host: address, } - return p.addRemoteHost(address, remote) + return p.addRemoteHost(address, &remote) } func (p *SyncedPool) Process(id CartId, messages ...Message) ([]byte, error) {