better abstraction
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m49s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m49s
This commit is contained in:
@@ -454,44 +454,37 @@ func (p *SyncedPool) AddRemote(address string) error {
|
|||||||
return p.addRemoteHost(address, &remote)
|
return p.addRemoteHost(address, &remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SyncedPool) Process(id CartId, messages ...Message) ([]byte, error) {
|
func (p *SyncedPool) getGrainPool(id CartId) (GrainPool, error) {
|
||||||
// check if local grain exists
|
|
||||||
_, ok := p.local.grains[id]
|
_, ok := p.local.grains[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
// check if remote grain exists
|
// check if remote grain exists
|
||||||
p.mu.RLock()
|
p.mu.RLock()
|
||||||
remoteGrain, ok := p.remoteIndex[id]
|
remotePool, ok := p.remoteIndex[id]
|
||||||
p.mu.RUnlock()
|
p.mu.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
remoteLookupCount.Inc()
|
remoteLookupCount.Inc()
|
||||||
return remoteGrain.Process(id, messages...)
|
return remotePool, nil
|
||||||
}
|
}
|
||||||
err := p.OwnerChanged(id, p.Hostname)
|
err := p.OwnerChanged(id, p.Hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return p.local, nil
|
||||||
|
}
|
||||||
|
|
||||||
return p.local.Process(id, messages...)
|
func (p *SyncedPool) Process(id CartId, messages ...Message) ([]byte, error) {
|
||||||
|
pool, err := p.getGrainPool(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return pool.Process(id, messages...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SyncedPool) Get(id CartId) ([]byte, error) {
|
func (p *SyncedPool) Get(id CartId) ([]byte, error) {
|
||||||
// check if local grain exists
|
pool, err := p.getGrainPool(id)
|
||||||
_, ok := p.local.grains[id]
|
|
||||||
if !ok {
|
|
||||||
// check if remote grain exists
|
|
||||||
p.mu.RLock()
|
|
||||||
remoteGrain, ok := p.remoteIndex[id]
|
|
||||||
p.mu.RUnlock()
|
|
||||||
if ok {
|
|
||||||
remoteLookupCount.Inc()
|
|
||||||
return remoteGrain.Get(id)
|
|
||||||
}
|
|
||||||
err := p.OwnerChanged(id, p.Hostname)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
return pool.Get(id)
|
||||||
|
|
||||||
return p.local.Get(id)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user