Workflow Task stamp - #8103
Conversation
| @@ -60,7 +60,3 @@ func (r *ActivityRetryTimerTask) GetType() enumsspb.TaskType { | |||
| func (r *ActivityRetryTimerTask) GetStamp() int32 { | |||
| return r.Stamp | |||
| } | |||
|
|
|||
| func (r *ActivityRetryTimerTask) SetStamp(stamp int32) { | |||
There was a problem hiding this comment.
SetStamp functions aren't used anywhere.
5f2fc0c to
057109e
Compare
| @@ -5117,8 +5121,6 @@ func (s *mutableStateSuite) TestHasRequestID() { | |||
| } | |||
|
|
|||
| func (s *mutableStateSuite) TestHasRequestID_StateConsistency() { | |||
| s.SetupTest() | |||
d317e6f to
23504cf
Compare
| if ms.HasPendingWorkflowTask() && !ms.HasStartedWorkflowTask() && | ||
| // Speculative WFT is directly (without transfer task) added to matching when scheduled. | ||
| // It is protected by timeout on both normal and sticky task queues. | ||
| // If there is no poller for previous deployment, it will time out, | ||
| // and will be rescheduled as normal WFT. | ||
| ms.GetPendingWorkflowTask().Type != enumsspb.WORKFLOW_TASK_TYPE_SPECULATIVE { | ||
| // Sticky queue was just cleared, so the following call only generates a WorkflowTask, not a WorkflowTaskTimeoutTask. | ||
| err := ms.taskGenerator.GenerateScheduleWorkflowTaskTasks(ms.GetPendingWorkflowTask().ScheduledEventID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } |
There was a problem hiding this comment.
Migrated into reschedulePendingWorkflowTask.
23504cf to
8a6f0dd
Compare
| @@ -17,6 +17,7 @@ type ( | |||
| TaskQueue string | |||
| ScheduledEventID int64 | |||
| Version int64 | |||
| Stamp int32 | |||
There was a problem hiding this comment.
Is my thinking right that only the workflow transfer and timeout task need the stamp?
There was a problem hiding this comment.
For workflow pause workstream we might need it in UserTimerTask & StartChildExecutionTask as well. But we are not ready for it yet. So we can add it in the future if needed.
| @@ -1056,7 +1059,6 @@ func (s *mutableStateSuite) TestOverride_RedirectFails() { | |||
| } | |||
|
|
|||
| func (s *mutableStateSuite) TestOverride_BaseDeploymentUpdatedOnCompletion() { | |||
| s.T().Skip("TODO (Shahab)") | |||
There was a problem hiding this comment.
This test works fine AFAICT.
878355d to
ddbe4ca
Compare
| @@ -74,6 +73,10 @@ func Invoke( | |||
| // - Speculative WFT is lost (ScheduleToStart timeout for speculative WFT will recreate it). | |||
| return nil, serviceerror.NewNotFound("Workflow task not found.") | |||
| } | |||
| if workflowTask.Stamp != mutableState.GetExecutionInfo().GetWorkflowTaskStamp() { | |||
| // This happens when the workflow task was rescheduled. | |||
| return nil, serviceerrors.NewObsoleteMatchingTask("Workflow task stamp mismatch") | |||
There was a problem hiding this comment.
Only place outside of task processing internals where we invalidate a workflow task with an outdated stamp now.
My thinking here is that when deploying a new version, all in-flight tasks and running workflows will have the default stamp, ie zero, and match. Only when the tasks are re-scheduled would they not match.
1a5d6bf to
f5b73ab
Compare
5b6dc75 to
0bec537
Compare
| // Stamp value from when the workflow task was scheduled. Used to validate the task is still relevant. | ||
| int32 stamp = 11; |
There was a problem hiding this comment.
ideally should have attempt wherever there's stamp. But we can save that for later :)
| EventID: workflowTask.ScheduledEventID, | ||
| ScheduleAttempt: workflowTask.Attempt, | ||
| Version: workflowTask.Version, | ||
| Stamp: r.mutableState.GetExecutionInfo().GetWorkflowTaskStamp(), // must use current stamp! |
There was a problem hiding this comment.
oh maybe provide some more context here. Guess I am still confused on why workflow.Stamp would be wrong here?
There was a problem hiding this comment.
Alright; I took another look and when I wrote this I didn't realize that GetWorkflowTaskByID is actually just returning a struct with the current workflow task's info. I thought it returned the currently scheduled workflow task (I didn't know we don't store that). So I've removed the special case here now!
| // Reset the attempt; forcing a non-transient workflow task to be scheduled. | ||
| ms.executionInfo.Attempt = 1 |
There was a problem hiding this comment.
we should only do this when Stamp is incremented?
There was a problem hiding this comment.
We need to make sure the stamp field is replicated properly in state-based replication as well. Please update the syncExecutionInfo() method in this file and have the Stamp field updated.
There was a problem hiding this comment.
Oh; that's easy to miss if you don't know where to look! Have we considered some kind of test that verifies a field is either replicated or explicitly ignored?
There was a problem hiding this comment.
I'm not sure if I got the test right.
There was a problem hiding this comment.
yeah, I think CGS team is working on some general testing strategy to assert the states are the same on both sides.
| ) error { | ||
| previousEffectiveDeployment := ms.GetEffectiveDeployment() | ||
| previousEffectiveVersioningBehavior := ms.GetEffectiveVersioningBehavior() | ||
| ) (requestReschedulePendingWorkflowTask bool, err error) { |
There was a problem hiding this comment.
nit: Prefer avoiding named return values in large and complex functions. It hurts readability since return statements are naked and hard to know what values are being returned.
There was a problem hiding this comment.
Hm, I 100% agree with that except here because without it, it just says bool and you'll have to scan the whole body to find out what the bool is. Alternatives I can think of are (1) add comment (can get out of date more easily) or (2) adding a var requestReschedulePendingWorkflowTask bool in the body right at the top. WDYT?
There was a problem hiding this comment.
Using var now, looks fine 👍
| return err | ||
| } | ||
| // Re-scheduling pending workflow and activity tasks. | ||
| err = ms.reschedulePendingWorkflowTask(false) |
There was a problem hiding this comment.
This seems like a case where we want to invalidate existing tasks? i.e ms.reschedulePendingWorkflowTask(true)?
There was a problem hiding this comment.
So the reason I don't is I cut scope from this PR. The previous code didn't invalidate pending workflow tasks, so there's no behavior change. The recordworkflowtaskstarted API has a dedicated check for buildId.
Why did I declare it out of scope? Yichao asked me how this works with replication and I couldn't tell you since I don't understand the versioning API well enough. So in order to get this merged, I declared it out of scope.
1ec84ce to
fc967bf
Compare
There was a problem hiding this comment.
yeah, I think CGS team is working on some general testing strategy to assert the states are the same on both sides.
826b806 to
741f109
Compare
## What changed? Allow updating priority of Workflow and Activity. Based on - temporalio/api#610 - #8103 ## Why? Users want to change the priority after starting the workflow/activity. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [ ] covered by existing tests - [x] added new unit test(s) - [x] added new functional test(s)
What changed?
Why?
Activity tasks already have the "stamp" mechanism. This is the same idea for workflow tasks.
It essentially provides a unified approach to invalidate activity and workflow tasks when rescheduling them.
How did you test it?
I intend to write more tests for when I'm implementing the update priority feature. It's much easier to setup and test than versioning overrides (which are the only way right now to trigger a stamp increase).