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

Track mutable side effect calls #1051

Conversation

Quinn-With-Two-Ns
Copy link
Contributor

Track how many times a mutable side effect is called to distinguish multiple MutableSIdeEffect calls in the same WFT.

I'll note this PR wont help existing histories that executed multiple MutableSIdeEffect in the same WFT. If we also use the CommandID to help distinguish multiple calls. The could help certain histories replay correctly. The trade off is an even more complex implementation. There will always be some histories that we cannot save because the SDK did not write enough information to history

Resolves: #1014

@Quinn-With-Two-Ns Quinn-With-Two-Ns force-pushed the mutable-side-effect-counter branch from 83c74ff to f242d79 Compare February 22, 2023 17:55
@Quinn-With-Two-Ns
Copy link
Contributor Author

Marking as a draft because I manly want feedback on the counting approach

@Quinn-With-Two-Ns
Copy link
Contributor Author

Quinn-With-Two-Ns commented Feb 24, 2023

Discussed offline and agreed to leave old broken workflow behavior as is. I will need to add some tests for this.

@cretz
Copy link
Member

cretz commented Feb 27, 2023

👍 Will wait for ready-to-review before reviewing in earnest

@Quinn-With-Two-Ns Quinn-With-Two-Ns force-pushed the mutable-side-effect-counter branch 2 times, most recently from 49785de to d8c78af Compare February 27, 2023 23:08
worker/worker.go Outdated
// WorkflowID is optional and defaults to ReplayId.
//
// Note: For all replay functions if no WorkflowID is given for replay the default is ReplayId.
GetWorkflowResult(workflowID string, valuePtr interface{}) error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should have added something like this when we stopped checking the workflow execution result and we need it to test we didn't break old behaviour.

if ok {
err = weh.dataConverter.FromPayloads(counterHintPayload, &counterHint)
} else {
// An old version of the SDK did not write the counter hint so we have to assume.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe if we detect this scenario we should not write counterHints to maintain behaviour in a given workflow?

Copy link
Member

Choose a reason for hiding this comment

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

I struggle to follow this code well enough to know, but so long as old behavior remains, any approach is fine by me

@Quinn-With-Two-Ns Quinn-With-Two-Ns force-pushed the mutable-side-effect-counter branch from d8c78af to 43d30ee Compare February 27, 2023 23:20
@Quinn-With-Two-Ns Quinn-With-Two-Ns marked this pull request as ready for review February 27, 2023 23:35
@Quinn-With-Two-Ns Quinn-With-Two-Ns requested a review from a team as a code owner February 27, 2023 23:35
@@ -782,15 +788,51 @@ func (wc *workflowEnvironmentImpl) SideEffect(f func() (*commonpb.Payloads, erro
wc.logger.Debug("SideEffect Marker added", tagSideEffectID, sideEffectID)
}

func (wc *workflowEnvironmentImpl) lookupMutableSideEffect(id string) (*commonpb.Payloads, bool) {
Copy link
Member

Choose a reason for hiding this comment

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

May need a comment. I am confused what this is doing at first glance. It's a mutable lookup?

internal/internal_event_handlers.go Outdated Show resolved Hide resolved
internal/internal_event_handlers.go Show resolved Hide resolved
if ok {
err = weh.dataConverter.FromPayloads(counterHintPayload, &counterHint)
} else {
// An old version of the SDK did not write the counter hint so we have to assume.
Copy link
Member

Choose a reason for hiding this comment

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

I struggle to follow this code well enough to know, but so long as old behavior remains, any approach is fine by me

worker/worker.go Outdated Show resolved Hide resolved
internal/internal_event_handlers.go Show resolved Hide resolved
@@ -217,3 +217,39 @@ func SideEffectWorkflow(ctx workflow.Context, field string) error {
func EmptyWorkflow(ctx workflow.Context, _ string) error {
return nil
}

func MutableSideEffectWorkflow(ctx workflow.Context) ([]int, error) {
Copy link
Member

@cretz cretz Feb 28, 2023

Choose a reason for hiding this comment

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

Is it possible, maybe in addition to these replay tests, to replicate the error that caused this issue in the first place? Maybe this workflow will, haven't tested, but want to make sure we can verify new behavior is for new workflow run against server. Or is that what that small assertion addition in workflow_test.go already does?

Also I wonder if we want to have an integration test proving non-deterministic mutable side effect order change. That may be asking too much though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or is that what that small assertion addition in workflow_test.go already does?

Yes exactly

Also I wonder if we want to have an integration test proving non-deterministic mutable side effect order change. That may be asking too much though.

not sure I understand, do you mean a test that shows changing the order of mutable side effects is not deterministic?

Copy link
Member

Choose a reason for hiding this comment

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

do you mean a test that shows changing the order of mutable side effects is not deterministic?

I do. Basically if I add a mutable side effect for the ID if it's non-deterministic. But I think this is a bit much, no need.

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

LGTM. I admit I didn't do any manual confirmation with workflows on older versions to confirm this change is safe. I am counting on tests here.

@Quinn-With-Two-Ns Quinn-With-Two-Ns merged commit 07c8c7e into temporalio:master Mar 1, 2023
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.

workflow.MutableSideEffect not deterministic if called multiple times with the same ID in the same WFT
2 participants