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

Enforce context timeout in matching AddTask #4048

Merged
merged 2 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 16 additions & 7 deletions service/matching/taskListManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ func (c *taskListManagerImpl) AddTask(ctx context.Context, params addTaskParams)
c.startWG.Wait()
var syncMatch bool
_, err := c.executeWithRetry(func() (interface{}, error) {
if err := ctx.Err(); err != nil {
return nil, err
}

domainEntry, err := c.domainCache.GetDomainByID(params.taskInfo.DomainID)
if err != nil {
Expand All @@ -252,9 +255,17 @@ func (c *taskListManagerImpl) AddTask(ctx context.Context, params addTaskParams)

return c.taskWriter.appendTask(params.execution, params.taskInfo)
})
if err == nil {

if err != nil {
c.logger.Error("Failed to add task",
tag.Error(err),
tag.WorkflowTaskListName(c.taskListID.name),
tag.WorkflowTaskListType(c.taskListID.taskType),
)
} else {
c.taskReader.Signal()
}

return syncMatch, err
}

Expand Down Expand Up @@ -419,8 +430,7 @@ func (c *taskListManagerImpl) completeTask(task *persistence.TaskInfo, err error
// OK, we also failed to write to persistence.
// This should only happen in very extreme cases where persistence is completely down.
// We still can't lose the old task so we just unload the entire task list
c.logger.Error("Persistent store operation failure",
tag.StoreOperationStopTaskList,
c.logger.Error("Failed to complete task",
tag.Error(err),
tag.WorkflowTaskListName(c.taskListID.name),
tag.WorkflowTaskListType(c.taskListID.taskType))
Expand Down Expand Up @@ -471,16 +481,15 @@ func (c *taskListManagerImpl) allocTaskIDBlock(prevBlockEnd int64) (taskIDBlock,

// Retry operation on transient error. On rangeID update by another process calls c.Stop().
func (c *taskListManagerImpl) executeWithRetry(
operation func() (interface{}, error)) (result interface{}, err error) {
operation func() (interface{}, error),
) (result interface{}, err error) {

op := func() error {
result, err = operation()
return err
}

var retryCount int64
err = backoff.Retry(op, persistenceOperationRetryPolicy, func(err error) bool {
c.logger.Debug(fmt.Sprintf("Retry executeWithRetry as task list range has changed. retryCount=%v, errType=%T", retryCount, err))
if _, ok := err.(*persistence.ConditionFailedError); ok {
return false
}
Expand All @@ -489,7 +498,7 @@ func (c *taskListManagerImpl) executeWithRetry(

if _, ok := err.(*persistence.ConditionFailedError); ok {
c.metricScope().IncCounter(metrics.ConditionFailedErrorPerTaskListCounter)
c.logger.Debug(fmt.Sprintf("Stopping task list due to persistence condition failure. Err: %v", err))
c.logger.Debug("Stopping task list due to persistence condition failure.", tag.Error(err))
c.Stop()
if c.taskListKind == types.TaskListKindSticky {
err = &types.InternalServiceError{Message: common.StickyTaskConditionFailedErrorMsg}
Expand Down
5 changes: 5 additions & 0 deletions service/matching/taskReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ func (tr *taskReader) getTaskBatchWithRange(readLevel int64, maxReadLevel int64)
return tr.tlMgr.db.GetTasks(readLevel, maxReadLevel, tr.tlMgr.config.GetTasksBatchSize())
})
if err != nil {
tr.logger().Error("Persistent store operation failure",
tag.StoreOperationGetTasks,
tag.Error(err),
tag.WorkflowTaskListName(tr.tlMgr.taskListID.name),
tag.WorkflowTaskListType(tr.tlMgr.taskListID.taskType))
return nil, err
}
return response.(*persistence.GetTasksResponse).Tasks, err
Expand Down