require ownership
This commit is contained in:
@@ -412,9 +412,8 @@ func (p *SyncedPool) AddRemote(host string) error {
|
||||
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]
|
||||
var err error
|
||||
if !ok {
|
||||
// check if remote grain exists
|
||||
p.mu.RLock()
|
||||
@@ -424,9 +423,13 @@ func (p *SyncedPool) getGrain(id CartId, requestOwnership bool) (Grain, error) {
|
||||
remoteLookupCount.Inc()
|
||||
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)
|
||||
if err != nil {
|
||||
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) {
|
||||
pool, err := p.getGrain(id, true)
|
||||
pool, err := p.getGrain(id)
|
||||
var res *CallResult
|
||||
if err != nil {
|
||||
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) {
|
||||
grain, err := p.getGrain(id, false)
|
||||
grain, err := p.getGrain(id)
|
||||
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