- Notifications
You must be signed in to change notification settings - Fork929
feat(coderd/database): support exact tags match in AcquireProvisionerJob query#12244
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -748,6 +748,22 @@ var deletedUserLinkError = &pq.Error{ | ||
Routine: "exec_stmt_raise", | ||
} | ||
// m1 and m2 are equal iff |m1| = |m2| ^ m2 ⊆ m1 | ||
func tagsEqual(m1, m2 map[string]string) bool { | ||
return len(m1) == len(m2) && tagsSubset(m1, m2) | ||
} | ||
// m2 is a subset of m1 if each key in m1 exists in m2 | ||
// with the same value | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
func tagsSubset(m1, m2 map[string]string) bool { | ||
for k, v1 := range m1 { | ||
if v2, found := m2[k]; !found || v1 != v2 { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
func (*FakeQuerier) AcquireLock(_ context.Context, _ int64) error { | ||
return xerrors.New("AcquireLock must only be called within a transaction") | ||
} | ||
@@ -783,19 +799,11 @@ func (q *FakeQuerier) AcquireProvisionerJob(_ context.Context, arg database.Acqu | ||
} | ||
} | ||
matchFunc := tagsSubset | ||
if arg.ExactTagMatch { | ||
matchFunc = tagsEqual | ||
} | ||
if!matchFunc(provisionerJob.Tags, tags) { | ||
continue | ||
} | ||
provisionerJob.StartedAt = arg.StartedAt | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -21,8 +21,13 @@ WHERE | ||
nested.started_at IS NULL | ||
-- Ensure the caller has the correct provisioner. | ||
AND nested.provisioner = ANY(@types :: provisioner_type [ ]) | ||
-- Ensure the caller satisfies all job tags if requested, | ||
AND CASE | ||
WHEN @exact_tag_match :: boolean THEN nested.tags = @tags :: jsonb | ||
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. Are both guaranteed to be sorted arrays? Might be a good idea to allow unsorted equality. 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. I think they're 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. Ah right, then a | ||
-- Otherwise, ensure caller satisfies a subset of tags. | ||
ELSE | ||
nested.tags <@ @tags :: jsonb | ||
END | ||
ORDER BY | ||
nested.created_at | ||
FOR UPDATE | ||