Skip to content

Commit fbe1c59

Browse files
authored
Remove ImmutableOpenIntMap from ClusterStateHealthTests (#86306)
These tests construct a map of shard to allocation ids. But they only do so get the pairs to put into the index metadata builder. This commit converts it to use HashMap. relates #86239
1 parent 01f65a6 commit fbe1c59

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

server/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.elasticsearch.cluster.routing.allocation.AllocationService;
3333
import org.elasticsearch.cluster.service.ClusterService;
3434
import org.elasticsearch.common.UUIDs;
35-
import org.elasticsearch.common.collect.ImmutableOpenIntMap;
3635
import org.elasticsearch.common.io.stream.BytesStreamOutput;
3736
import org.elasticsearch.common.io.stream.StreamInput;
3837
import org.elasticsearch.common.settings.Settings;
@@ -52,6 +51,7 @@
5251
import java.io.IOException;
5352
import java.util.ArrayList;
5453
import java.util.Collections;
54+
import java.util.HashMap;
5555
import java.util.HashSet;
5656
import java.util.List;
5757
import java.util.Map;
@@ -403,25 +403,23 @@ private List<ClusterState> generateClusterStates(
403403
// some primaries started
404404
indexRoutingTable = routingTable.index(indexName);
405405
newIndexRoutingTable = IndexRoutingTable.builder(indexRoutingTable.getIndex());
406-
ImmutableOpenIntMap.Builder<Set<String>> allocationIds = ImmutableOpenIntMap.<Set<String>>builder();
406+
Map<Integer, Set<String>> allocationIds = new HashMap<>();
407407
for (int shardId = 0; shardId < indexRoutingTable.size(); shardId++) {
408408
IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId);
409409
for (int copy = 0; copy < shardRoutingTable.size(); copy++) {
410410
ShardRouting shardRouting = shardRoutingTable.shard(copy);
411411
if (shardRouting.primary() && randomBoolean()) {
412412
final ShardRouting newShardRouting = shardRouting.moveToStarted();
413-
allocationIds.fPut(newShardRouting.getId(), Sets.newHashSet(newShardRouting.allocationId().getId()));
413+
allocationIds.put(newShardRouting.getId(), Set.of(newShardRouting.allocationId().getId()));
414414
newIndexRoutingTable.addShard(newShardRouting);
415415
} else {
416416
newIndexRoutingTable.addShard(shardRouting);
417417
}
418418
}
419419
}
420420
routingTable = RoutingTable.builder(routingTable).add(newIndexRoutingTable).build();
421-
IndexMetadata.Builder idxMetaBuilder = IndexMetadata.builder(clusterState.metadata().index(indexName));
422-
for (final Map.Entry<Integer, Set<String>> entry : allocationIds.build().entrySet()) {
423-
idxMetaBuilder.putInSyncAllocationIds(entry.getKey(), entry.getValue());
424-
}
421+
final IndexMetadata.Builder idxMetaBuilder = IndexMetadata.builder(clusterState.metadata().index(indexName));
422+
allocationIds.forEach(idxMetaBuilder::putInSyncAllocationIds);
425423
Metadata.Builder metadataBuilder = Metadata.builder(clusterState.metadata()).put(idxMetaBuilder);
426424
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).metadata(metadataBuilder).build();
427425
clusterStates.add(clusterState);
@@ -453,26 +451,24 @@ private List<ClusterState> generateClusterStates(
453451
// all primaries started
454452
indexRoutingTable = routingTable.index(indexName);
455453
newIndexRoutingTable = IndexRoutingTable.builder(indexRoutingTable.getIndex());
456-
allocationIds = ImmutableOpenIntMap.<Set<String>>builder();
454+
allocationIds = new HashMap<>();
457455
for (int shardId = 0; shardId < indexRoutingTable.size(); shardId++) {
458456
IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId);
459457
for (int copy = 0; copy < shardRoutingTable.size(); copy++) {
460458
ShardRouting shardRouting = shardRoutingTable.shard(copy);
461459
if (shardRouting.primary() && shardRouting.started() == false) {
462460
final ShardRouting newShardRouting = shardRouting.moveToStarted();
463-
allocationIds.fPut(newShardRouting.getId(), Sets.newHashSet(newShardRouting.allocationId().getId()));
461+
allocationIds.put(newShardRouting.getId(), Set.of(newShardRouting.allocationId().getId()));
464462
newIndexRoutingTable.addShard(newShardRouting);
465463
} else {
466464
newIndexRoutingTable.addShard(shardRouting);
467465
}
468466
}
469467
}
470468
routingTable = RoutingTable.builder(routingTable).add(newIndexRoutingTable).build();
471-
idxMetaBuilder = IndexMetadata.builder(clusterState.metadata().index(indexName));
472-
for (final Map.Entry<Integer, Set<String>> entry : allocationIds.build().entrySet()) {
473-
idxMetaBuilder.putInSyncAllocationIds(entry.getKey(), entry.getValue());
474-
}
475-
metadataBuilder = Metadata.builder(clusterState.metadata()).put(idxMetaBuilder);
469+
final IndexMetadata.Builder idxMetaBuilder2 = IndexMetadata.builder(clusterState.metadata().index(indexName));
470+
allocationIds.forEach(idxMetaBuilder2::putInSyncAllocationIds);
471+
metadataBuilder = Metadata.builder(clusterState.metadata()).put(idxMetaBuilder2);
476472
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).metadata(metadataBuilder).build();
477473
clusterStates.add(clusterState);
478474

0 commit comments

Comments
 (0)