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

Fix SearchResponse leaks in searchable snapshot test and production code #103118

Conversation

original-brownbear
Copy link
Member

It's in the title. Fix all the tests like we have everywhere else. Fix the production use of SearchResponse in
BlobStoreCacheMaintenanceService by properly ref-counting the response it holds on to.

For #102030

It's in the title. Fix all the tests like we have everywhere else.
Fix the production use of SearchResponse in
BlobStoreCacheMaintenanceService by properly ref-counting the response
it holds on to.
@original-brownbear original-brownbear added >non-issue :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs labels Dec 7, 2023
@elasticsearchmachine elasticsearchmachine added the Team:Distributed Meta label for distributed team label Dec 7, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@original-brownbear
Copy link
Member Author

@elasticmachine update branch

@@ -679,6 +689,16 @@ public void onFailure(Exception e) {
}
}
}

private void setCurrentResponse(SearchResponse response) {
Copy link
Member Author

Choose a reason for hiding this comment

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

  1. There's no massive changes in this method, I just extracted 2 methods to keep the indent level under control now that we need a loop to have correct thread-safety around the response reference.
  2. I'm not sure this is the solution we want long-term. It might be better to just copy this kind of retained response to heap if it lives for an extended period of time compared to burdening the Netty buffer pool. Since it doesn't matter too much here, I decided to just handle this the straight forward way for now and not add a new API for that just yet.

@@ -417,7 +417,7 @@ private class PeriodicMaintenanceTask implements Runnable, Releasable {

private volatile Map<String, Set<String>> existingSnapshots;
private volatile Set<String> existingRepositories;
private volatile SearchResponse searchResponse;
private final AtomicReference<SearchResponse> searchResponse = new AtomicReference<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICT this is all effectively single-threaded, so I'm not sure we need the extra protection that using getAndSet() gives us.

Also I'm pretty sure we don't need to retain the search response at all, we're really converting it directly into a bulk delete request as soon as we receive it. This run() method is doing too much.

Anyway nbd for now but would you open an issue to track this tech debt?

Copy link
Member Author

Choose a reason for hiding this comment

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

#103245 there we go

…arch/xpack/searchablesnapshots/cache/blob/BlobStoreCacheMaintenanceService.java

Co-authored-by: David Turner <david.turner@elastic.co>
Copy link
Contributor

@DaveCTurner DaveCTurner 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 David!

@original-brownbear original-brownbear merged commit 64818df into elastic:main Dec 10, 2023
15 checks passed
@original-brownbear original-brownbear deleted the fix-leaks-searchable-snapshots branch December 10, 2023 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >non-issue Team:Distributed Meta label for distributed team v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants