better abstraction
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m49s

This commit is contained in:
matst80
2024-11-10 12:57:44 +01:00
parent fd9a66d193
commit c7a5e22471

View File

@@ -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)
}