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

Detach SearchPhases from AbstractSearchAsyncAction #23118

Merged
merged 8 commits into from
Feb 14, 2017

Conversation

s1monw
Copy link
Contributor

@s1monw s1monw commented Feb 10, 2017

Today all search phases are inner classes of AbstractSearchAsyncAction or one of it's
subclasses. This makes unittesting of these classes practically impossible. This commit
Extracts DfsQueryPhase and FetchSearchPhase or of the code that composes the actual
query execution types and moves most of the fan-out and collect code into an InitialSearchPhase
class that can be used to build initial search phases (phases that retry on shards). This will
make modification to these classes simpler and allows to easily compose or add new search phases
down the road if additional roundtrips are required.

Today all search phases are inner classes of AbstractSearchAsyncAction or one of it's
subclasses. This makes unittesting of these classes practically impossible. This commit
Extracts `DfsQueryPhase` and `FetchSearchPhase` or of the code that composes the actual
query execution types and moves most of the fan-out and collect code into an `InitialSearchPhase`
class that can be used to build initial search phases (phases that retry on shards). This will
make modification to these classes simpler and allows to easily compose or add new search phases
down the road if additional roundtrips are required.
@s1monw s1monw added :Search/Search Search-related issues that do not fall into other categories >enhancement review v5.4.0 v6.0.0-alpha1 labels Feb 10, 2017
@s1monw
Copy link
Contributor Author

s1monw commented Feb 10, 2017

@elasticmachine would you bother to test this

Copy link
Contributor

@colings86 colings86 left a comment

Choose a reason for hiding this comment

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

LGTM, but I think a second pair of eyes form @jpountz or @jimczi would be good here too

private final SearchPhaseContext context;
private final SearchTransportService searchTransportService;

DfsQueryPhase(AtomicArray<DfsSearchResult> firstResults,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we call this dfsResults instead of firstResults so its clear what the results contain?

this.request = request;
this.shardsIts = shardsIts;
this.logger = logger;
// we need to add 1 for non active partition, since we count it in the total!
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by the non-active partition here?

@s1monw
Copy link
Contributor Author

s1monw commented Feb 13, 2017

@colings86 I pushed new commits to address your comments.

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

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

This is a great change that introduces unit tests for each phase and simplifies things in a complicated way ;) !
The abstraction for search phase and the chaining are just great and you preserved small optims like query and fetch for single shard query.
Looks fantastic to me.

});
}
}
protected SearchPhase getNextPhase(AtomicArray<DfsSearchResult> results, SearchPhaseContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

beautiful !

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

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

LGTM. It is hard to do thorough reviews for such changes, but I like where this is going. I left some nitpicks about moving assertions in non performance-sensitive code to hard exceptions.

if (hadOne) {
sb.append(",");
} else {
hadOne = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

minor suggestion, feel free to ignore, but maybe StringJoiner would make it easier to read

this.counter = new CountDown(expectedOps);
this.onFinish = onFinish;
this.context = context;
assert expectedOps <= resultArray.length() :
Copy link
Contributor

Choose a reason for hiding this comment

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

let's make it a hard exception?

this.context = context;
this.logger = context.getLogger();
assert context.getNumShards() == queryResults.length() : "number of shards must match the length of the query results but doesn't:"
+ context.getNumShards() + "!=" + queryResults.length();
Copy link
Contributor

Choose a reason for hiding this comment

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

let's make it a hard exception too?

@s1monw
Copy link
Contributor Author

s1monw commented Feb 13, 2017

@jpountz @jimczi thanks for the feedback I pushed fixes for the last suggestions and will merge this once it's build.

@s1monw
Copy link
Contributor Author

s1monw commented Feb 13, 2017

@elasticmachine would you bother to test this

1 similar comment
@s1monw
Copy link
Contributor Author

s1monw commented Feb 14, 2017

@elasticmachine would you bother to test this

@s1monw s1monw merged commit aef0665 into elastic:master Feb 14, 2017
@s1monw s1monw deleted the break_out_initial_search_phase branch February 14, 2017 11:34
s1monw added a commit that referenced this pull request Feb 14, 2017
Today all search phases are inner classes of AbstractSearchAsyncAction or one of it's
subclasses. This makes unit testing of these classes practically impossible. This commit
Extracts `DfsQueryPhase` and `FetchSearchPhase` or of the code that composes the actual
query execution types and moves most of the fan-out and collect code into an `InitialSearchPhase`
class that can be used to build initial search phases (phases that retry on shards). This will
make modification to these classes simpler and allows to easily compose or add new search phases
down the road if additional roundtrips are required.
s1monw added a commit that referenced this pull request Feb 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories v5.4.0 v6.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants