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

Remove InternalSearchResponse as well as most usage of SearchResponseSections #103583

Conversation

original-brownbear
Copy link
Member

This indirection isn't really necessary now that its use in the high level rest client went away. -> flattened the SearchResponse class to make ref counting easier -> removed InternalSearchResponse whose functionality was completely redundant now -> removed serialization and most of the usage of SearchResponseSections, only keeping this for the few search execution spots that currently use it and where removing it won't get us anything and will be a huge changeset.

enables the last steps in #102030

…Sections

This indirection isn't really necessary now that its use in the high level rest client went away.
-> flattened the `SearchResponse` class to make ref counting easier
-> removed `InternalSearchResponse` whose functionality was completely redundant now
-> removed serialization and most of the usage of `SearchResponseSections`, only keeping this for
the few search execution spots that currently use it and where removing it won't get us anything and
will be a huge changeset.
@original-brownbear original-brownbear added :Search/Search Search-related issues that do not fall into other categories >refactoring labels Dec 19, 2023
@elasticsearchmachine elasticsearchmachine added Team:Search Meta label for search team v8.13.0 labels Dec 19, 2023
@elasticsearchmachine
Copy link
Collaborator

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

@@ -212,7 +212,9 @@ public final void start() {
// total hits is null in the response if the tracking of total hits is disabled
boolean withTotalHits = trackTotalHitsUpTo != SearchContext.TRACK_TOTAL_HITS_DISABLED;
sendSearchResponse(
withTotalHits ? InternalSearchResponse.EMPTY_WITH_TOTAL_HITS : InternalSearchResponse.EMPTY_WITHOUT_TOTAL_HITS,
withTotalHits
? new SearchResponseSections(SearchHits.EMPTY_WITH_TOTAL_HITS, null, null, false, null, null, 1)
Copy link
Member Author

Choose a reason for hiding this comment

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

I inlined these, we don't really want constants for stuff that becomes ref-counted. We can make this nicer later one at some point IMO.

private final Supplier<SearchPhase> nextPhase;

ExpandSearchPhase(SearchPhaseContext context, InternalSearchResponse searchResponse, Supplier<SearchPhase> nextPhase) {
ExpandSearchPhase(SearchPhaseContext context, SearchHits searchHits, Supplier<SearchPhase> nextPhase) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We only use the hits, so lets only pass around the hits => only have to worry about ref-counting the hits :)

@@ -250,7 +248,7 @@ protected final void sendResponse(
ActionListener.respondAndRelease(
listener,
new SearchResponse(
internalResponse,
SearchPhaseController.merge(true, queryPhase, fetchResults),
Copy link
Member Author

Choose a reason for hiding this comment

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

Inlining this stuff so follow-up ref counting becomes easier.

import java.io.IOException;

/**
* {@link SearchResponseSections} subclass that can be serialized over the wire.
Copy link
Member Author

Choose a reason for hiding this comment

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

No need for that any longer

Copy link
Member

@carlosdelest carlosdelest left a comment

Choose a reason for hiding this comment

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

Now THIS is some refactoring 💪 . Thanks for doing this!

* The reason why this class exists is that the high level REST client uses its own classes
* to parse aggregations into, which are not serializable. This is the common part that can be
* shared between core and client.
* Holds some sections that a search response is composed of (hits, aggs, suggestions etc.) during some steps of the search response
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to mark this class as deprecated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe not, I was trying to remove it altogether but the few use cases where this is used response merging logic actually look nicer having a record style object like this rather than a bunch of parameters I think. I was gonna double check that point though, maybe not all of these fields are needed and that becomes not true anymore :) lets see 🤞

@original-brownbear
Copy link
Member Author

Thanks Carlos!

@original-brownbear original-brownbear added the auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Dec 20, 2023
@elasticsearchmachine elasticsearchmachine merged commit 7fc1fcb into elastic:main Dec 20, 2023
15 checks passed
@original-brownbear original-brownbear deleted the remove-indirection-search-response branch December 20, 2023 17:57
@javanna
Copy link
Member

javanna commented Dec 21, 2023

FWIW, SearchResponseSections was introduced when we added response parsing for the high level REST client. Given that HLRC no longer exists, it kind of make sense to clean that up.

navarone-feekery pushed a commit to navarone-feekery/elasticsearch that referenced this pull request Dec 22, 2023
…Sections (elastic#103583)

This indirection isn't really necessary now that its use in the high
level rest client went away. -> flattened the `SearchResponse` class to
make ref counting easier -> removed `InternalSearchResponse` whose
functionality was completely redundant now -> removed serialization and
most of the usage of `SearchResponseSections`, only keeping this for the
few search execution spots that currently use it and where removing it
won't get us anything and will be a huge changeset.

enables the last steps in elastic#102030
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >refactoring :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants