testing locks
This commit is contained in:
@@ -319,11 +319,23 @@ func (p *SyncedPool) Negotiate() {
|
||||
|
||||
}
|
||||
|
||||
func (p *SyncedPool) GetHealthyRemotes() []*RemoteHost {
|
||||
p.mu.RLock()
|
||||
defer p.mu.RUnlock()
|
||||
remotes := make([]*RemoteHost, 0, len(p.remotes))
|
||||
for _, r := range p.remotes {
|
||||
if r.IsHealthy() {
|
||||
remotes = append(remotes, r)
|
||||
}
|
||||
}
|
||||
return remotes
|
||||
}
|
||||
|
||||
func (p *SyncedPool) RequestOwnership(id CartId) error {
|
||||
ok := 0
|
||||
all := 0
|
||||
p.mu.RLock()
|
||||
for _, r := range p.remotes {
|
||||
|
||||
for _, r := range p.GetHealthyRemotes() {
|
||||
if !r.IsHealthy() {
|
||||
continue
|
||||
}
|
||||
@@ -342,7 +354,7 @@ func (p *SyncedPool) RequestOwnership(id CartId) error {
|
||||
}
|
||||
ok++
|
||||
}
|
||||
p.mu.RUnlock()
|
||||
|
||||
if ok == 0 && all > 0 {
|
||||
p.removeLocalGrain(id)
|
||||
return fmt.Errorf("no remotes confirmed change")
|
||||
@@ -361,8 +373,7 @@ func (p *SyncedPool) removeLocalGrain(id CartId) {
|
||||
}
|
||||
|
||||
func (p *SyncedPool) AddRemote(host string) error {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
_, hasHost := p.remotes[host]
|
||||
if host == "" || p.IsKnown(host) || hasHost {
|
||||
return nil
|
||||
@@ -378,7 +389,9 @@ func (p *SyncedPool) AddRemote(host string) error {
|
||||
MissedPings: 0,
|
||||
Host: host,
|
||||
}
|
||||
p.mu.Lock()
|
||||
p.remotes[host] = &remote
|
||||
p.mu.Unlock()
|
||||
go func() {
|
||||
<-remote.PersistentConnection.Died
|
||||
log.Printf("Removing host, remote died %s", host)
|
||||
|
||||
Reference in New Issue
Block a user