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

Add support for arbitrary predicates for multi cursor queues #5323

Merged
merged 3 commits into from
Jan 20, 2024

Conversation

bergundy
Copy link
Member

What changed?

  • Add support for arbitrary predicates for multi cursor queues, adds a Grouper abstraction for grouping tasks and constructing predicates
  • Add a DestinationPredicate (will be used later in multi-destination queues)
  • Add Grouper implementations for namespace ID and namespace ID + destination.

Why?

We need this flexibility for Nexus, this is some of the prep work.

How did you test it?

Add some unit tests, ran existing tests.

Potential risks

We should look closely at this as it may mess up task processing multi-cursor logic.

Is hotfix candidate?

No.

@bergundy bergundy requested a review from a team as a code owner January 19, 2024 15:10
@bergundy bergundy force-pushed the multi-cursor-predicate-cleanup branch from ff13872 to 9a95fa7 Compare January 19, 2024 16:01
Predicate(keys []any) tasks.Predicate
}

type GrouperNamespaceID struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: What about GroupByNamespaceID instead? It reads a bit better imo

@bergundy bergundy force-pushed the multi-cursor-predicate-cleanup branch from 9a95fa7 to 2e7183a Compare January 19, 2024 18:25
@@ -531,6 +531,14 @@ func (e *executableImpl) SetScheduledTime(t time.Time) {
e.scheduledTime = t
}

// GetDestination returns the embedded task's destination if it exists. Defaults to an empty string.
func (e *executableImpl) GetDestination() string {
Copy link
Member

Choose a reason for hiding this comment

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

nit: feels like it should be a method on tasks.Task, not executable. But I don't have strong opinion.

@@ -135,6 +135,7 @@ func NewScheduledQueue(
options,
hostRateLimiter,
readerCompletionFn,
GrouperNamespaceID{},
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be a parameter as well...

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's wait for a use case, so far I don't see one.

if len(s.executableTracker.pendingPerNamespace) > shrinkPredicateMaxPendingNamespaces {
// TODO: this should be generic enough to shrink any predicate type, probably doesn't belong here.
pendingPerKey := s.executableTracker.pendingPerKey
if len(pendingPerKey) > shrinkPredicateMaxPendingKeys {
// only shrink predicate if there're few namespaces left
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// only shrink predicate if there're few namespaces left
// only shrink predicate if there're few keys left

namespacePredicate := tasks.NewNamespacePredicate(pendingNamespaceIDs)
s.scope.Predicate = tasks.AndPredicates(s.scope.Predicate, namespacePredicate)
minimalPredicate := s.grouper.Predicate(maps.Keys(pendingPerKey))
s.scope.Predicate = tasks.AndPredicates(s.scope.Predicate, minimalPredicate)
Copy link
Member

Choose a reason for hiding this comment

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

now that I think about it, the tasks.AndPredicates looks unnecessary to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, good catch!

@bergundy bergundy enabled auto-merge (squash) January 20, 2024 04:48
@bergundy bergundy merged commit 6b6b0bf into temporalio:main Jan 20, 2024
11 checks passed
@bergundy bergundy deleted the multi-cursor-predicate-cleanup branch January 20, 2024 21:33
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.

3 participants