Skip to content

Commit b363183

Browse files
authored
Remove Countable interface and dry up ShardsIterator (elastic#121923) (elastic#122519)
The size method is needed only in SearchShardIterator and PlainIterator. An interface is not really needed, we can just rather add the size method where needed. Also, there's a couple of methods in the ShardsIterator interface that are not needed that this commit removes: size, reset and remaining.
1 parent a67d659 commit b363183

File tree

5 files changed

+11
-46
lines changed

5 files changed

+11
-46
lines changed

server/src/main/java/org/elasticsearch/action/search/SearchShardIterator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.action.OriginalIndices;
1313
import org.elasticsearch.cluster.routing.ShardRouting;
1414
import org.elasticsearch.cluster.routing.ShardsIterator;
15-
import org.elasticsearch.common.util.Countable;
1615
import org.elasticsearch.common.util.PlainIterator;
1716
import org.elasticsearch.core.Nullable;
1817
import org.elasticsearch.core.TimeValue;
@@ -29,7 +28,7 @@
2928
* the cluster alias.
3029
* @see OriginalIndices
3130
*/
32-
public final class SearchShardIterator implements Comparable<SearchShardIterator>, Countable {
31+
public final class SearchShardIterator implements Comparable<SearchShardIterator> {
3332

3433
private final OriginalIndices originalIndices;
3534
private final String clusterAlias;
@@ -171,7 +170,6 @@ boolean prefiltered() {
171170
*
172171
* @return number of shard routing instances in this iterator
173172
*/
174-
@Override
175173
public int size() {
176174
return targetNodesIterator.size();
177175
}

server/src/main/java/org/elasticsearch/cluster/routing/ShardsIterator.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,12 @@
88
*/
99
package org.elasticsearch.cluster.routing;
1010

11-
import org.elasticsearch.common.util.Countable;
12-
1311
import java.util.List;
1412

1513
/**
1614
* Allows to iterate over unrelated shards.
1715
*/
18-
public interface ShardsIterator extends Iterable<ShardRouting>, Countable {
19-
20-
/**
21-
* Resets the iterator to its initial state.
22-
*/
23-
void reset();
24-
25-
/**
26-
* The number of shard routing instances.
27-
*
28-
* @return number of shard routing instances in this iterator
29-
*/
30-
int size();
16+
public interface ShardsIterator extends Iterable<ShardRouting> {
3117

3218
/**
3319
* The number of active shard routing instances
@@ -41,13 +27,6 @@ public interface ShardsIterator extends Iterable<ShardRouting>, Countable {
4127
*/
4228
ShardRouting nextOrNull();
4329

44-
/**
45-
* Return the number of shards remaining in this {@link ShardsIterator}
46-
*
47-
* @return number of shard remaining
48-
*/
49-
int remaining();
50-
5130
@Override
5231
int hashCode();
5332

server/src/main/java/org/elasticsearch/common/util/Countable.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/common/util/PlainIterator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.util.Iterator;
1414
import java.util.List;
1515

16-
public class PlainIterator<T> implements Iterable<T>, Countable {
16+
public class PlainIterator<T> implements Iterable<T> {
1717
private final List<T> elements;
1818

1919
// Calls to nextOrNull might be performed on different threads in the transport actions so we need the volatile
@@ -43,7 +43,6 @@ public T nextOrNull() {
4343
}
4444
}
4545

46-
@Override
4746
public int size() {
4847
return elements.size();
4948
}

server/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,21 @@ public void testAllAssignedShardsGrouped() {
312312
}
313313

314314
public void testAllShardsForMultipleIndices() {
315-
assertThat(this.emptyRoutingTable.allShards(new String[0]).size(), is(0));
315+
assertThat(this.emptyRoutingTable.allShards(new String[0]).getShardRoutings().size(), is(0));
316316

317-
assertThat(clusterState.routingTable().allShards(new String[] { TEST_INDEX_1 }).size(), is(this.shardsPerIndex));
317+
assertThat(clusterState.routingTable().allShards(new String[] { TEST_INDEX_1 }).getShardRoutings().size(), is(this.shardsPerIndex));
318318

319319
initPrimaries();
320-
assertThat(clusterState.routingTable().allShards(new String[] { TEST_INDEX_1 }).size(), is(this.shardsPerIndex));
320+
assertThat(clusterState.routingTable().allShards(new String[] { TEST_INDEX_1 }).getShardRoutings().size(), is(this.shardsPerIndex));
321321

322322
startInitializingShards(TEST_INDEX_1);
323-
assertThat(clusterState.routingTable().allShards(new String[] { TEST_INDEX_1 }).size(), is(this.shardsPerIndex));
323+
assertThat(clusterState.routingTable().allShards(new String[] { TEST_INDEX_1 }).getShardRoutings().size(), is(this.shardsPerIndex));
324324

325325
startInitializingShards(TEST_INDEX_2);
326-
assertThat(clusterState.routingTable().allShards(new String[] { TEST_INDEX_1, TEST_INDEX_2 }).size(), is(this.totalNumberOfShards));
326+
assertThat(
327+
clusterState.routingTable().allShards(new String[] { TEST_INDEX_1, TEST_INDEX_2 }).getShardRoutings().size(),
328+
is(this.totalNumberOfShards)
329+
);
327330

328331
try {
329332
clusterState.routingTable().allShards(new String[] { TEST_INDEX_1, "not_exists" });

0 commit comments

Comments
 (0)