fix: wait for ongoing queries to finish at close #3030
Merged
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.
This change forces block querier to wait until all outgoing queries to finish at
Close
call. Resolves #2845The solution does not completely address the issue of block ownership. Since our queries involve stateful processes (block iteration + series iteration + deduplication + merge), and our replicas (ingesters and store gateways) lack awareness of the query context, there is a possibility that a block may be closed while the query is still running. This occurs because replicas may not retain any references to the block in-between query stages.
For instance, if a block is evicted immediately after the list of replica blocks has been returned to the querier, attempting to retrieve profiling data from the block will result in an empty response. This is to be solved in a separate PR. I plan to introduce a graceful period for block eviction. Instead of immediate eviction, the plan is to mark the block and initiate eviction only after a reasonable grace period, such as 5 minutes, has expired.