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

Unload taskQueueManager by instance, not queue ID #1917

Merged
merged 1 commit into from
Sep 13, 2021
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
15 changes: 8 additions & 7 deletions service/matching/matchingEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,16 +702,17 @@ func (e *matchingEngineImpl) getTask(
return tlMgr.GetTask(ctx, maxDispatchPerSecond)
}

func (e *matchingEngineImpl) unloadTaskQueue(id *taskQueueID) {
func (e *matchingEngineImpl) unloadTaskQueue(unloadTQM taskQueueManager) {
queueID := unloadTQM.QueueID()
e.taskQueuesLock.Lock()
tlMgr, ok := e.taskQueues[*id]
if ok {
delete(e.taskQueues, *id)
foundTQM, ok := e.taskQueues[*queueID]
if !ok || foundTQM != unloadTQM {
e.taskQueuesLock.Unlock()
return
}
delete(e.taskQueues, *queueID)
e.taskQueuesLock.Unlock()
if ok {
tlMgr.Stop()
}
foundTQM.Stop()
}

// Populate the workflow task response based on context and scheduled/started events.
Expand Down
36 changes: 36 additions & 0 deletions service/matching/matchingEngine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,42 @@ func (s *matchingEngineSuite) TestPollWorkflowTaskQueuesEmptyResultWithShortCont
s.PollForTasksEmptyResultTest(callContext, enumspb.TASK_QUEUE_TYPE_WORKFLOW)
}

func (s *matchingEngineSuite) TestOnlyUnloadMatchingInstance() {
queueID := newTestTaskQueueID(
uuid.New(),
"makeToast",
enumspb.TASK_QUEUE_TYPE_ACTIVITY)
tqm, err := s.matchingEngine.getTaskQueueManager(
queueID,
enumspb.TASK_QUEUE_KIND_NORMAL)
s.Require().NoError(err)

tqm2, err := newTaskQueueManager(
s.matchingEngine,
queueID, // same queueID as above
enumspb.TASK_QUEUE_KIND_NORMAL,
s.matchingEngine.config)
s.Require().NoError(err)

// try to unload a different tqm instance with the same taskqueue ID
s.matchingEngine.unloadTaskQueue(tqm2)

got, err := s.matchingEngine.getTaskQueueManager(
queueID, enumspb.TASK_QUEUE_KIND_NORMAL)
s.Require().NoError(err)
s.Require().Same(tqm, got,
"Unload call with non-matching taskQueueManager should not cause unload")

// this time unload the right tqm
s.matchingEngine.unloadTaskQueue(tqm)

got, err = s.matchingEngine.getTaskQueueManager(
queueID, enumspb.TASK_QUEUE_KIND_NORMAL)
s.Require().NoError(err)
s.Require().NotSame(tqm, got,
"Unload call with matching incarnation should have caused unload")
}

func (s *matchingEngineSuite) TestPollWorkflowTaskQueues() {
namespaceID := uuid.NewRandom().String()
tl := "makeToast"
Expand Down
9 changes: 7 additions & 2 deletions service/matching/taskQueueManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type (
// DescribeTaskQueue returns information about the target task queue
DescribeTaskQueue(includeTaskQueueStatus bool) *matchingservice.DescribeTaskQueueResponse
String() string
QueueID() *taskQueueID
}

// Single task queue in memory state
Expand Down Expand Up @@ -139,7 +140,7 @@ type (
outstandingPollsLock sync.Mutex
outstandingPollsMap map[string]context.CancelFunc
shutdownCh chan struct{} // Delivers stop to the pump that populates taskBuffer
signalFatalProblem func(id *taskQueueID)
signalFatalProblem func(taskQueueManager)
}
)

Expand Down Expand Up @@ -471,7 +472,7 @@ func (c *taskQueueManagerImpl) completeTask(task *persistencespb.AllocatedTaskIn
tag.Error(err),
tag.WorkflowTaskQueueName(c.taskQueueID.name),
tag.WorkflowTaskQueueType(c.taskQueueID.taskType))
c.signalFatalProblem(c.taskQueueID)
c.signalFatalProblem(c)
return
}
c.taskReader.Signal()
Expand Down Expand Up @@ -600,3 +601,7 @@ func (c *taskQueueManagerImpl) tryInitNamespaceAndScope() {
c.metricScopeValue.Store(scope)
c.namespaceValue.Store(namespace)
}

func (c *taskQueueManagerImpl) QueueID() *taskQueueID {
return c.taskQueueID
}
6 changes: 3 additions & 3 deletions service/matching/taskWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (w *taskWriter) appendTasks(
return resp, nil

case *persistence.ConditionFailedError:
w.tlMgr.signalFatalProblem(w.tlMgr.taskQueueID)
w.tlMgr.signalFatalProblem(w.tlMgr)
Copy link
Member

Choose a reason for hiding this comment

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

BTW, if we were just call w.tlMgr.Unload() here we won't have to deal with this bug.

Copy link
Contributor Author

@mmcshane mmcshane Sep 13, 2021

Choose a reason for hiding this comment

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

Not sure what you mean - taskQueueManager doesn't have an Unload?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tlMgr.Stop maybe? that would work because it dedups on a per-taskQueueManager instance basis.

Copy link
Member

Choose a reason for hiding this comment

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

I meat tlm.Stop(), but yes we still need to remove it from the collection of matching engine, which is keyed on taskQueueID, and dedupe would still needed. So, maybe it does not matter.

return nil, err

default:
Expand All @@ -219,7 +219,7 @@ func (w *taskWriter) taskWriterLoop(ctx context.Context) error {
err := w.initReadWriteState(ctx)
if err != nil {
if w.tlMgr.errShouldUnload(err) {
w.tlMgr.signalFatalProblem(w.tlMgr.taskQueueID)
w.tlMgr.signalFatalProblem(w.tlMgr)
}
return err
}
Expand Down Expand Up @@ -318,7 +318,7 @@ func (w *taskWriter) allocTaskIDBlock(ctx context.Context, prevBlockEnd int64) (
state, err := w.renewLeaseWithRetry(ctx, persistenceOperationRetryPolicy, common.IsPersistenceTransientError)
if err != nil {
if w.tlMgr.errShouldUnload(err) {
w.tlMgr.signalFatalProblem(w.taskQueueID)
w.tlMgr.signalFatalProblem(w.tlMgr)
return taskIDBlock{}, errShutdown
}
return taskIDBlock{}, err
Expand Down