Skip to content

Commit 3e02748

Browse files
authored
Remove use of ImmutableOpenIntMap in IndexRoutingTable (#86368)
The routing table builder uses an hppc based immutable map to keep track of shard id to shard table. However, when building the final routing table, it is just converted to an array. This commit switches to a HashMap. relates #86239
1 parent 1c8c80d commit 3e02748

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
1919
import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
2020
import org.elasticsearch.common.Randomness;
21-
import org.elasticsearch.common.collect.ImmutableOpenIntMap;
2221
import org.elasticsearch.common.io.stream.StreamInput;
2322
import org.elasticsearch.common.io.stream.StreamOutput;
2423
import org.elasticsearch.common.util.CollectionUtils;
@@ -29,6 +28,7 @@
2928
import java.io.IOException;
3029
import java.util.ArrayList;
3130
import java.util.Arrays;
31+
import java.util.HashMap;
3232
import java.util.HashSet;
3333
import java.util.List;
3434
import java.util.Map;
@@ -66,7 +66,7 @@ public class IndexRoutingTable implements SimpleDiffable<IndexRoutingTable> {
6666

6767
private final List<ShardRouting> allActiveShards;
6868

69-
IndexRoutingTable(Index index, ImmutableOpenIntMap<IndexShardRoutingTable> shards) {
69+
IndexRoutingTable(Index index, Map<Integer, IndexShardRoutingTable> shards) {
7070
this.index = index;
7171
this.shuffler = new RotationShardShuffler(Randomness.get().nextInt());
7272
this.shards = new IndexShardRoutingTable[shards.size()];
@@ -328,7 +328,7 @@ public static Builder builder(Index index) {
328328
public static class Builder {
329329

330330
private final Index index;
331-
private final ImmutableOpenIntMap.Builder<IndexShardRoutingTable> shards = ImmutableOpenIntMap.builder();
331+
private final Map<Integer, IndexShardRoutingTable> shards = new HashMap<>();
332332

333333
public Builder(Index index) {
334334
this.index = index;
@@ -487,7 +487,7 @@ private Builder initializeEmpty(IndexMetadata indexMetadata, UnassignedInfo unas
487487
}
488488

489489
public Builder addReplica() {
490-
for (var shardNumber : shards.keys()) {
490+
for (var shardNumber : shards.keySet()) {
491491
ShardId shardId = new ShardId(index, shardNumber);
492492
// version 0, will get updated when reroute will happen
493493
ShardRouting shard = ShardRouting.newUnassigned(
@@ -502,7 +502,7 @@ public Builder addReplica() {
502502
}
503503

504504
public Builder removeReplica() {
505-
for (var shardId : shards.keys()) {
505+
for (var shardId : shards.keySet()) {
506506
IndexShardRoutingTable indexShard = shards.get(shardId);
507507
if (indexShard.replicaShards().isEmpty()) {
508508
// nothing to do here!
@@ -557,7 +557,7 @@ public Builder addShard(ShardRouting shard) {
557557
}
558558

559559
public IndexRoutingTable build() {
560-
return new IndexRoutingTable(index, shards.build());
560+
return new IndexRoutingTable(index, shards);
561561
}
562562
}
563563

0 commit comments

Comments
 (0)