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.
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
Make
PostingsForMatchersCache.PostingsForMatchers
respect context cancellation #551Make
PostingsForMatchersCache.PostingsForMatchers
respect context cancellation #551Changes from all commits
0ecca4a
b8d6f1e
ebf9cdd
9ac9d68
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Check failure on line 56 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 56 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 57 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 57 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 58 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 58 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 82 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 82 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 84 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 84 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 85 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 85 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
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.
Should we move this to its own method on
postingsForMatchersPromise
perhaps? This method is starting to get quite big.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.
I don't think this is quite right - calling
delete
here will remove the promise from the cache if a subsequent call's context is cancelled, even if the promise succeeded. Imagine this sequence of events:waiting
is incremented to 1 and thenwaitOnPromise
is called.waitOnPromise
observes cancelled context, decrementswaiting
to 0 and removes cached promise from cache.Instead, we only want to cancel and remove the call from
c.calls
if there's nothing waiting and the call is still in progress.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.
what's the reason for waiting here?
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.
Maybe it's not necessary any longer, have to review it.
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.
Yeah, it shouldn't be necessary any longer (it was in a previous revision).
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.
Actually, after removing this line I get a data race in tests. Not sure why yet.
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.
One reason to read from
promise.done
here is that otherwise the background goroutine will block on sending to the channel.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.
I see. Then we're holding the whole request until the PostingsForMatchers finishes. Can we have a
select
withdefault
or withcase <-ctx.Done()
when sending topromise.done
? Then we can immediately return the cancelled request and let the background goroutine clean up when it's readyThere 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.
I think we can solve the blocking on
promise.done
by moving the call toc.created
to the goroutine, andpromise.done
is used only to indicate completion (see comment below) - thenpromise.done
is only ever closed, and never sent to.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.
Couldn't the call to
c.created
be made in the goroutine spawned byPostingsForMatchers
? Thendone
can simply be closed to signal that the promise has completedCheck failure on line 279 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 279 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 279 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 279 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 280 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint
Check failure on line 280 in tsdb/postings_for_matchers_cache.go
GitHub Actions / lint