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

Refactor task queue related methods of mutable state #4325

Merged
merged 2 commits into from May 12, 2023

Conversation

alexshtin
Copy link
Member

@alexshtin alexshtin commented May 12, 2023

What changed?
Refactor task queue related methods of mutable state:

  1. Renamed
    • ClearStickyness() -> ClearStickyTaskQueue(),
    • IsStickyTaskQueueEnabled() -> IsStickyTaskQueueSet(),
    • TaskQueue() -> CurrentTaskQueue().
  2. Added:
    • SetStickyTaskQueue(),
    • TaskQueueScheduleToStartTimeout().

Improved comments.

Why?
To concolidate logic related to timeout calulation.
Cleaner contract between mutable state and its consumers.

How did you test it?
Existing tests.

Potential risks
No risks.

Is hotfix candidate?
No.

@alexshtin alexshtin requested a review from a team as a code owner May 12, 2023 01:19
@alexshtin alexshtin force-pushed the feature/refactor-task-queue branch from c68729b to 8106261 Compare May 12, 2023 01:23
@@ -209,7 +209,7 @@ func MutableStateToGetResponse(
CurrentBranchToken: currentBranchToken,
WorkflowState: workflowState,
WorkflowStatus: workflowStatus,
IsStickyTaskQueueEnabled: mutableState.IsStickyTaskQueueEnabled(),
IsStickyTaskQueueEnabled: mutableState.TaskQueue().Kind == enumspb.TASK_QUEUE_KIND_STICKY,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is slightly longer but also more verbose.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is slightly longer but also more verbose.

Wait those both mean the same thing? Also, this seems like we're doing the same thing but in a more invasive way that violates the Law of Demeter.

Copy link
Contributor

@mmcshane mmcshane May 12, 2023

Choose a reason for hiding this comment

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

I think the intent behind "more verbose" is actually "more intention revealing," which is true. MutableState.IsStickyTaskQueueEnabled could mean a number of different things. If we want to be intention-revealing and also encapsulate this comparison, I'd suggest a free function: workflow.IsSticky(*taskqueuepb.TaskQueue). Or if you're feeling fancy, workflow.IsSticky(interface { GetKind() taskqueuepb.TaskQueueKind })

Copy link
Member Author

Choose a reason for hiding this comment

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

I am bringing it back under different name: IsStickyTaskQueueSet().

workflowRunTimeout := executionInfo.WorkflowRunTimeout
taskScheduleToStartTimeout = workflowRunTimeout
}
normalTaskQueue := mutableState.GetExecutionInfo().TaskQueue
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you might use normalTaskQueueName here since it's not actually an instance of TaskQueue

// TaskQueueScheduleToStartTimeout returns TaskQueue struct and corresponding StartToClose timeout.
// Task queue kind (sticky or normal) and timeout are set based on comparison of normal task queue name
// in mutable state and provided name.
func (ms *MutableStateImpl) TaskQueueScheduleToStartTimeout(name string) (*taskqueuepb.TaskQueue, *time.Duration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would return by value here rather than pointers but I understand that's not the common pattern.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's because of proto. Both return values goes to proto and there will be & operator anyway. Doing it right away simplifies caller code.

@@ -209,7 +209,7 @@ func MutableStateToGetResponse(
CurrentBranchToken: currentBranchToken,
WorkflowState: workflowState,
WorkflowStatus: workflowStatus,
IsStickyTaskQueueEnabled: mutableState.IsStickyTaskQueueEnabled(),
IsStickyTaskQueueEnabled: mutableState.TaskQueue().Kind == enumspb.TASK_QUEUE_KIND_STICKY,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is slightly longer but also more verbose.

Wait those both mean the same thing? Also, this seems like we're doing the same thing but in a more invasive way that violates the Law of Demeter.

@@ -171,7 +171,7 @@ func addWorkflowTaskToMatching(
) error {
// TODO (alex): Timeout calculation is copied from somewhere else. Extract func instead?
var taskScheduleToStartTimeout *time.Duration
if ms.IsStickyTaskQueueEnabled() {
if ms.TaskQueue().Kind == enumspb.TASK_QUEUE_KIND_STICKY {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm really not sure why we're inlining this

// If current task queue becomes sticky in between when this transfer task is created and processed,
// it can't be used at process time, because timeout timer was not created for it,
// because it used to be non-sticky when this transfer task was created here.
// In short, task queue that was "current" when transfer task was created must be used when task is processed.
Copy link
Contributor

Choose a reason for hiding this comment

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

To keep things DRY, I'd recommend just using a godoc doc link to a canonical source on this non-sticky->sticky timeout issue i.e.. [package.Struct.Method]. It's here under "Doc links"

Copy link
Member Author

Choose a reason for hiding this comment

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

It is slightly different here. And I don't think that doc links work inside functions.

@alexshtin alexshtin merged commit 62611e2 into temporalio:master May 12, 2023
10 checks passed
@alexshtin alexshtin deleted the feature/refactor-task-queue branch May 12, 2023 21:13
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.

None yet

3 participants