Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isWorker flag to actor startup #62

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

aratz-lasa
Copy link
Collaborator

This PR adds a flag to actor instantiations on the startup call so that apart from the payload user specifies, also an IsWorker flag is passed. This allows actors to know if they are being run as workers or not and consequently decide if they can use the transaction or not.

result, _, err := transaction.Get(ctx, []byte("shutdown"))
return result, err
}
return []byte(strconv.FormatBool(ta.shutdownWasCalled)), nil
case "getInstantiatePayload":
return ta.instantiatePayload, nil
return []byte(ta.instantiatePayload.Payload), nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no byte cast here needed

@@ -27,6 +27,17 @@ type CreateIfNotExist struct {
InstantiatePayload []byte
}

// InstantiatePayload provides the arguments for initialiazing actors on the STARTUP call.
type InstantiatePayload struct {
// IsWorker is a flag that is used to indicate whether the payload is intended for a worker or not
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: . at end

return nil, fmt.Errorf("error unmarshaling InstantiatePayload: %w", err)
}
fcp := &FileCacheInstantiatePayload{}
if err := json.Unmarshal([]byte(p.Payload), fcp); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont need this cast

)

// getInstantiatePayload returns the payload provided to the Startup invocation.
func getInstantiatePayload(payload []byte) ([]byte, error) {
return instantiatePayload, nil
return []byte(instantiatePayload.Payload), nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont need this cast

@@ -530,7 +531,13 @@ func (r *environment) InvokeActorDirectStream(
heartbeatResult.ServerVersion, serverVersion)
}

return r.activations.invoke(ctx, reference, operation, create.InstantiatePayload, payload, false)
// Wrap instantiation payload into a struct that provides metadata to the actor
b, err := json.Marshal(types.InstantiatePayload{Payload: create.InstantiatePayload, IsWorker: false})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should push these down into activations.go that way we can avoid the allocations/marshalling work except for the case where a new actor is actually being created which will make it ~free

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants