-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Unblock pending poll when passive cluster becomes active #8506
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"time" | ||
|
||
"github.com/nexus-rpc/sdk-go/nexus" | ||
"github.com/pborman/uuid" | ||
"go.temporal.io/api/serviceerror" | ||
taskqueuepb "go.temporal.io/api/taskqueue/v1" | ||
"go.temporal.io/api/workflowservice/v1" | ||
|
@@ -356,7 +357,20 @@ func (c *physicalTaskQueueManagerImpl) PollTask( | |
} | ||
|
||
if !namespaceEntry.ActiveInCluster(c.clusterMeta.GetCurrentClusterName()) { | ||
return c.matcher.PollForQuery(ctx, pollMetadata) | ||
ctx, cancel := context.WithCancel(ctx) | ||
key := uuid.New() | ||
// Listening to registry changes in case the cluster becomes active while the poll is waiting | ||
c.namespaceRegistry.RegisterStateChangeCallback(key, func(ns *namespace.Namespace, deletedFromDb bool) { | ||
if ns.ID() == namespaceEntry.ID() && namespaceEntry.ActiveInCluster(c.clusterMeta.GetCurrentClusterName()) { | ||
cancel() | ||
} | ||
}) | ||
defer c.namespaceRegistry.UnregisterStateChangeCallback(key) | ||
|
||
t, err := c.matcher.PollForQuery(ctx, pollMetadata) | ||
if !errors.Is(err, context.Canceled) { | ||
return t, err | ||
} // else the cluster has become active so continue regular poll path | ||
Comment on lines
+372
to
+373
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not necessarily true, the caller could have canceled. |
||
} | ||
|
||
for { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of doing it here, I think we should register the namespace state change listener at task queue level, when it sees the state change, it would unload the task queue and reload it.
this is hot path that the overhead here could be too heavy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... yeah if we normally expect polls on the passive side what you're suggesting makes more sense. I was not sure if polls on passive cluster is typical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not register/unregister callbacks here, but we shouldn't do it at task queue level either, we we should register a single callback at the engine level:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction: two more things do look at active namespace state:
I don't think there's any reason to unload/reload because of those two.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, it might simplify a few other things if we did reload the partition on ns state change (metrics, query-only state in new matcher). So I'm leaning towards reloading the partition. But I still think the listener itself should be at the engine level and it can just iterate over loaded partitions and unload the ones that belong to ns that changed (which will automatically interrupt polls, of course). Or keep a map to be more efficient.