require ownership
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 27s
Build and Publish / BuildAndDeploy (push) Successful in 2m27s

This commit is contained in:
matst80
2024-11-12 20:08:21 +01:00
parent 36b6cb7e8c
commit ebec6cb4a7

View File

@@ -412,9 +412,8 @@ func (p *SyncedPool) AddRemote(host string) error {
return p.addRemoteHost(host, &remote) return p.addRemoteHost(host, &remote)
} }
func (p *SyncedPool) getGrain(id CartId, requestOwnership bool) (Grain, error) { func (p *SyncedPool) getGrain(id CartId) (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()
@@ -424,9 +423,13 @@ func (p *SyncedPool) getGrain(id CartId, requestOwnership bool) (Grain, error) {
remoteLookupCount.Inc() remoteLookupCount.Inc()
return remoteGrain, nil return remoteGrain, nil
} }
if requestOwnership {
go p.RequestOwnership(id) err := p.RequestOwnership(id)
if err != nil {
log.Printf("Error requesting ownership: %v\n", 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
@@ -437,7 +440,7 @@ func (p *SyncedPool) getGrain(id CartId, requestOwnership bool) (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, true) pool, err := p.getGrain(id)
var res *CallResult var res *CallResult
if err != nil { if err != nil {
return nil, err return nil, err
@@ -452,17 +455,10 @@ 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, false) grain, err := p.getGrain(id)
if err != nil { if err != nil {
return nil, err 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() return grain.GetCurrentState()
} }