Skip to content

Commit

Permalink
Remove use of ImmutableOpenIntMap in IndexRoutingTable (#86368)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rjernst authored May 3, 2022
1 parent 1c8c80d commit 3e02748
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource;
import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.collect.ImmutableOpenIntMap;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.util.CollectionUtils;
Expand All @@ -29,6 +28,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -66,7 +66,7 @@ public class IndexRoutingTable implements SimpleDiffable<IndexRoutingTable> {

private final List<ShardRouting> allActiveShards;

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

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

public Builder(Index index) {
this.index = index;
Expand Down Expand Up @@ -487,7 +487,7 @@ private Builder initializeEmpty(IndexMetadata indexMetadata, UnassignedInfo unas
}

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

public Builder removeReplica() {
for (var shardId : shards.keys()) {
for (var shardId : shards.keySet()) {
IndexShardRoutingTable indexShard = shards.get(shardId);
if (indexShard.replicaShards().isEmpty()) {
// nothing to do here!
Expand Down Expand Up @@ -557,7 +557,7 @@ public Builder addShard(ShardRouting shard) {
}

public IndexRoutingTable build() {
return new IndexRoutingTable(index, shards.build());
return new IndexRoutingTable(index, shards);
}
}

Expand Down

0 comments on commit 3e02748

Please sign in to comment.