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

Move LeakTracker to production code and use it in assertions around QuerySearchContext #102179

Conversation

original-brownbear
Copy link
Member

Part of the ref counted search hits effort requires us to correctly ref count FetchSearchPhase. This doesn't commit moves us one step in the direction of doing so by adding testing that ensure that QuerySearchContext is ref counted correctly and fixes one production code spot where it wasn't (albeit that spot worked out for other reasons anyways). This is done by moving the leak tracker to production code and making use of it selectively in case assertions are enabled.

Mostly test changes here, review with ?w=1 for easier readability :)

…uerySearchContext

Part of the ref counted search hits effort requires us to correctly ref
count `FetchSearchPhase`. This doesn't commit moves us one step in the
direction of doing so by adding testing that ensure that `QuerySearchContext`
is ref counted correctly and fixes one production code spot where it
wasn't (albeit that spot worked out for other reasons anyways).
This is done by moving the leak tracker to production code and making
use of it selectively in case assertions are enabled.
@original-brownbear original-brownbear added >test Issues or PRs that are addressing/adding tests :Search/Search Search-related issues that do not fall into other categories labels Nov 14, 2023
@elasticsearchmachine elasticsearchmachine added v8.12.0 Team:Search Meta label for search team labels Nov 14, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@@ -26,14 +27,8 @@ public final class QueryFetchSearchResult extends SearchPhaseResult {
private final RefCounted refCounted;

public QueryFetchSearchResult(StreamInput in) throws IOException {
super(in);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a super call is a noop, just fixing the duplication below.

serviceTimeEWMA += rrfQuerySearchResult.serviceTimeEWMA();
nodeQueueSize = Math.max(nodeQueueSize, rrfQuerySearchResult.nodeQueueSize());
searchTimedOut = rrfQuerySearchResult.searchTimedOut();
try (RankSearchContext rankSearchContext = new RankSearchContext(searchContext, rankQuery, rankShardContext.windowSize())) {
Copy link
Member Author

@original-brownbear original-brownbear Nov 14, 2023

Choose a reason for hiding this comment

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

This was broken because the QuerySearchResult in RankSearchContext was leaked. Not really a bug in practice it seems but it makes sense to clean this up I think, if only to cleanly enable this kind of test.

Copy link
Contributor

@jdconrad jdconrad Nov 14, 2023

Choose a reason for hiding this comment

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

My understanding is the only releasable is for aggs, and these results should in theory never have aggs in them. However, I do think this is probably a bug even if we would never hit it, so thanks for fixing it :).

@@ -245,10 +246,6 @@ public void releaseAggs() {
}
}

private void close() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a weird redundant method, I mainly figured this was easier to reason about GC wise when doing it inline in a lambda, but also no point in having this method when javac generates it for us :)

Copy link
Contributor

@jdconrad jdconrad left a comment

Choose a reason for hiding this comment

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

LGTM!

@original-brownbear
Copy link
Member Author

Thanks Jack!

@original-brownbear original-brownbear merged commit aaa6e78 into elastic:main Nov 14, 2023
14 checks passed
@original-brownbear original-brownbear deleted the leak-track-query-search-result branch November 14, 2023 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team >test Issues or PRs that are addressing/adding tests v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants