only require ownership if mutating or is not empty
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m3s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 2m3s
This commit is contained in:
@@ -422,8 +422,9 @@ func (p *SyncedPool) AddRemote(host string) error {
|
||||
return p.addRemoteHost(host, &remote)
|
||||
}
|
||||
|
||||
func (p *SyncedPool) getGrain(id CartId) (Grain, error) {
|
||||
func (p *SyncedPool) getGrain(id CartId, requestOwnership bool) (Grain, error) {
|
||||
localGrain, ok := p.local.grains[id]
|
||||
var err error
|
||||
if !ok {
|
||||
// check if remote grain exists
|
||||
p.mu.RLock()
|
||||
@@ -433,10 +434,11 @@ func (p *SyncedPool) getGrain(id CartId) (Grain, error) {
|
||||
remoteLookupCount.Inc()
|
||||
return remoteGrain, nil
|
||||
}
|
||||
|
||||
err := p.RequestOwnership(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if requestOwnership {
|
||||
err = p.RequestOwnership(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
localGrain, err = p.local.GetGrain(id)
|
||||
if err != nil {
|
||||
@@ -448,7 +450,7 @@ func (p *SyncedPool) getGrain(id CartId) (Grain, error) {
|
||||
}
|
||||
|
||||
func (p *SyncedPool) Process(id CartId, messages ...Message) (*CallResult, error) {
|
||||
pool, err := p.getGrain(id)
|
||||
pool, err := p.getGrain(id, true)
|
||||
var res *CallResult
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -463,13 +465,17 @@ func (p *SyncedPool) Process(id CartId, messages ...Message) (*CallResult, error
|
||||
}
|
||||
|
||||
func (p *SyncedPool) Get(id CartId) (*CallResult, error) {
|
||||
grain, err := p.getGrain(id)
|
||||
grain, err := p.getGrain(id, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if remoteGrain, ok := grain.(*RemoteGrain); ok {
|
||||
return remoteGrain.GetCurrentState()
|
||||
}
|
||||
|
||||
if localGrain, ok := grain.(*CartGrain); ok {
|
||||
if len(localGrain.storageMessages) > 0 {
|
||||
go p.RequestOwnership(id)
|
||||
}
|
||||
}
|
||||
return grain.GetCurrentState()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user