negotiate stuff
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m52s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m52s
This commit is contained in:
@@ -84,10 +84,8 @@ func NewSyncedPool(local *GrainLocalPool, hostname string, d Discovery) (*Synced
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error discovering hosts: %v", err)
|
log.Printf("Error discovering hosts: %v", err)
|
||||||
}
|
}
|
||||||
for _, h := range hosts {
|
for _, h := range pool.ExcludeKnown(hosts) {
|
||||||
if h == hostname {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
log.Printf("Discovered host %s", h)
|
log.Printf("Discovered host %s", h)
|
||||||
|
|
||||||
err := pool.AddRemote(h)
|
err := pool.AddRemote(h)
|
||||||
@@ -115,6 +113,23 @@ func NewSyncedPool(local *GrainLocalPool, hostname string, d Discovery) (*Synced
|
|||||||
return pool, nil
|
return pool, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *SyncedPool) ExcludeKnown(hosts []string) []string {
|
||||||
|
ret := make([]string, 0, len(hosts))
|
||||||
|
for _, h := range hosts {
|
||||||
|
found := false
|
||||||
|
for _, r := range p.remotes {
|
||||||
|
if r.Host == h {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found && h != p.Hostname {
|
||||||
|
ret = append(ret, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func (p *SyncedPool) RemoveHost(host *RemoteHost) {
|
func (p *SyncedPool) RemoveHost(host *RemoteHost) {
|
||||||
|
|
||||||
for i, r := range p.remotes {
|
for i, r := range p.remotes {
|
||||||
@@ -432,7 +447,9 @@ func DoPing(host *RemoteHost) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error {
|
func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error {
|
||||||
|
known := make([]string, 0, len(p.remotes))
|
||||||
for _, r := range p.remotes {
|
for _, r := range p.remotes {
|
||||||
|
known = append(known, r.Host)
|
||||||
if r.Host == address {
|
if r.Host == address {
|
||||||
log.Printf("Remote %s already exists\n", address)
|
log.Printf("Remote %s already exists\n", address)
|
||||||
return fmt.Errorf("remote %s already exists", address)
|
return fmt.Errorf("remote %s already exists", address)
|
||||||
@@ -447,7 +464,9 @@ func (p *SyncedPool) addRemoteHost(address string, remote *RemoteHost) error {
|
|||||||
p.remotes = append(p.remotes, remote)
|
p.remotes = append(p.remotes, remote)
|
||||||
connectedRemotes.Set(float64(len(p.remotes)))
|
connectedRemotes.Set(float64(len(p.remotes)))
|
||||||
log.Printf("Added remote %s\n", remote.Host)
|
log.Printf("Added remote %s\n", remote.Host)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
p.Negotiate(known)
|
||||||
ids := remote.GetCartMappings()
|
ids := remote.GetCartMappings()
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
|
|||||||
Reference in New Issue
Block a user