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

Fail workflow execution update fast if workflow task constantly fails #4376

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion service/history/api/queryworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
querypb "go.temporal.io/api/query/v1"
"go.temporal.io/api/serviceerror"
"go.temporal.io/api/workflowservice/v1"

"go.temporal.io/server/common/log/tag"

"go.temporal.io/server/api/historyservice/v1"
Expand Down Expand Up @@ -129,7 +130,7 @@ func Invoke(
tag.WorkflowNamespaceID(workflowKey.NamespaceID),
tag.WorkflowID(workflowKey.WorkflowID),
tag.WorkflowRunID(workflowKey.RunID))
return nil, serviceerror.NewWorkflowNotReady("Cannot query workflow due to Workflow Task in failed state.")
return nil, serviceerror.NewWorkflowNotReady("Unable to query workflow due to Workflow Task in failed state.")
}

// There are two ways in which queries get dispatched to workflow worker. First, queries can be dispatched on workflow tasks.
Expand Down
19 changes: 19 additions & 0 deletions service/history/api/updateworkflow/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"go.temporal.io/server/api/matchingservice/v1"
"go.temporal.io/server/common"
"go.temporal.io/server/common/definition"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/common/namespace"
serviceerrors "go.temporal.io/server/common/serviceerror"
"go.temporal.io/server/internal/effect"
Expand All @@ -52,6 +53,11 @@ import (
"go.temporal.io/server/service/history/workflow/update"
)

const (
// Fail update fast if workflow task keeps failing (attempt >= 3).
failUpdateWorkflowTaskAttemptCount = 3
)

func Invoke(
ctx context.Context,
req *historyservice.UpdateWorkflowExecutionRequest,
Expand Down Expand Up @@ -127,6 +133,19 @@ func Invoke(
return consts.ErrWorkflowExecutionNotFound
}

if ms.GetExecutionInfo().WorkflowTaskAttempt >= failUpdateWorkflowTaskAttemptCount {
// If workflow task is constantly failing, the update to that workflow will also fail.
// Additionally, workflow update can't "fix" workflow state because updates (delivered with messages)
// are applied after events.
// Failing API call fast here to prevent wasting resources for an update that will fail.
shardCtx.GetLogger().Info("Fail update fast due to WorkflowTask in failed state.",
tag.WorkflowNamespace(req.Request.Namespace),
tag.WorkflowNamespaceID(wfKey.NamespaceID),
tag.WorkflowID(wfKey.WorkflowID),
tag.WorkflowRunID(wfKey.RunID))
return serviceerror.NewWorkflowNotReady("Unable to perform workflow execution update due to Workflow Task in failed state.")
}

updateID := req.GetRequest().GetRequest().GetMeta().GetUpdateId()
updateReg := weCtx.GetUpdateRegistry(ctx)
var alreadyExisted bool
Expand Down