Skip to content

Conversation

@original-brownbear
Copy link
Contributor

@original-brownbear original-brownbear commented Nov 16, 2024

There is no point in having GroupShardsIterator, it's mostly an unnecessary layer of indirection as it has no state and a single field only. It's only value could be seen in it hiding the ability to mutate the list it wraps, but that hardly justifies the overhead on the search path and extra code complexity. Moreover, the list it references is not copied/immutable in any way, so the value of hiding is limited also.

There is no point in having `GroupShardsIterator`, it's mostly an
unnecessary layer of indirection as it has no state and a single field
only. It's only value could be seen in it hiding the ability to mutate
the list it wraps, but that hardly justifies the overhead on the search
path and extra code complexity. Moreover, the list it references is not
copied/immutable in any way, so the value of hiding is limited also.

Unwrapping all its use to list and moving its methods (mostly single use
or test-only) elsewhere/inline saves a lot of code, makes the logic
easier to follow by removing a step, and sets up further optimizations
(we currently copy lists unnecessarily to map one
`GroupShardsIterator` to another in a few spots, we could just mutate
lists in place here mostly).
@original-brownbear original-brownbear added >non-issue :Search Foundations/Search Catch all for Search Foundations labels Nov 16, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.0.0 labels Nov 16, 2024

import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;

public class GroupShardsIteratorTests extends ESTestCase {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Outside of the two test utilities in this class, I don't believe there is any value in the tests for the methods we had. totalSize was test-only, the count 1 for empty method only had a single well-covered callsite in production and testing iteration and sorting is unnecessary for lists and covered by existing tests anyway.

@original-brownbear
Copy link
Contributor Author

@elasticmachine update branch

@elasticmachine
Copy link
Collaborator

There are no new commits on the base branch.

@original-brownbear
Copy link
Contributor Author

@elasticmachine update branch

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

left a couple of minors, LGTM otherwise

}
return GroupShardsIterator.sortAndCreate(new ArrayList<>(set));
var res = new ArrayList<>(set);
CollectionUtil.timSort(res);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@javanna see my other comment this one in particular seems unnecesssary. We already sort the iterators in the search action, we shouldn't need to sort them here as well?

@original-brownbear original-brownbear added auto-backport Automatically create backport pull requests when merged v9.0.0 v8.18.0 labels Feb 5, 2025
@original-brownbear
Copy link
Contributor Author

Thanks Luca!

@original-brownbear original-brownbear merged commit 229d89d into elastic:main Feb 5, 2025
16 of 17 checks passed
@original-brownbear original-brownbear deleted the drop-group-shard-iter branch February 5, 2025 20:08
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.0 Commit could not be cherrypicked due to conflicts
8.18 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 116891

@javanna
Copy link
Member

javanna commented Feb 6, 2025

Would you mind pinging me once you backported to 8.x? I have one that depends on it.

@javanna javanna removed the v9.0.0 label Feb 6, 2025
@javanna
Copy link
Member

javanna commented Feb 6, 2025

Heads up: I removed the 9.0 label, I don't think this should be backported to 9.0.

original-brownbear added a commit that referenced this pull request Feb 11, 2025
…122253)

There is no point in having `GroupShardsIterator`, it's mostly an
unnecessary layer of indirection as it has no state and a single field
only. It's only value could be seen in it hiding the ability to mutate
the list it wraps, but that hardly justifies the overhead on the search
path and extra code complexity. Moreover, the list it references is not
copied/immutable in any way, so the value of hiding is limited also.
@javanna javanna added v8.19.0 and removed v8.18.0 labels Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >non-issue :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants