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)
|
||||
}
|
||||
|
||||
func (p *SyncedPool) Process(id CartId, messages ...Message) ([]byte, error) {
|
||||
// check if local grain exists
|
||||
func (p *SyncedPool) getGrainPool(id CartId) (GrainPool, error) {
|
||||
_, ok := p.local.grains[id]
|
||||
if !ok {
|
||||
// check if remote grain exists
|
||||
p.mu.RLock()
|
||||
remoteGrain, ok := p.remoteIndex[id]
|
||||
remotePool, ok := p.remoteIndex[id]
|
||||
p.mu.RUnlock()
|
||||
if ok {
|
||||
remoteLookupCount.Inc()
|
||||
return remoteGrain.Process(id, messages...)
|
||||
return remotePool, nil
|
||||
}
|
||||
err := p.OwnerChanged(id, p.Hostname)
|
||||
if err != nil {
|
||||
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) {
|
||||
// check if local grain exists
|
||||
_, 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 {
|
||||
return nil, err
|
||||
}
|
||||
pool, err := p.getGrainPool(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p.local.Get(id)
|
||||
return pool.Get(id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user