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)
|
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]
|
localGrain, ok := p.local.grains[id]
|
||||||
|
var err error
|
||||||
if !ok {
|
if !ok {
|
||||||
// check if remote grain exists
|
// check if remote grain exists
|
||||||
p.mu.RLock()
|
p.mu.RLock()
|
||||||
@@ -433,11 +434,12 @@ func (p *SyncedPool) getGrain(id CartId) (Grain, error) {
|
|||||||
remoteLookupCount.Inc()
|
remoteLookupCount.Inc()
|
||||||
return remoteGrain, nil
|
return remoteGrain, nil
|
||||||
}
|
}
|
||||||
|
if requestOwnership {
|
||||||
err := p.RequestOwnership(id)
|
err = p.RequestOwnership(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
localGrain, err = p.local.GetGrain(id)
|
localGrain, err = p.local.GetGrain(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -448,7 +450,7 @@ func (p *SyncedPool) getGrain(id CartId) (Grain, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *SyncedPool) Process(id CartId, messages ...Message) (*CallResult, 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
|
var res *CallResult
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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) {
|
func (p *SyncedPool) Get(id CartId) (*CallResult, error) {
|
||||||
grain, err := p.getGrain(id)
|
grain, err := p.getGrain(id, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if remoteGrain, ok := grain.(*RemoteGrain); ok {
|
if remoteGrain, ok := grain.(*RemoteGrain); ok {
|
||||||
return remoteGrain.GetCurrentState()
|
return remoteGrain.GetCurrentState()
|
||||||
}
|
}
|
||||||
|
if localGrain, ok := grain.(*CartGrain); ok {
|
||||||
|
if len(localGrain.storageMessages) > 0 {
|
||||||
|
go p.RequestOwnership(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
return grain.GetCurrentState()
|
return grain.GetCurrentState()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user