|
32 | 32 | import org.elasticsearch.cluster.routing.allocation.AllocationService;
|
33 | 33 | import org.elasticsearch.cluster.service.ClusterService;
|
34 | 34 | import org.elasticsearch.common.UUIDs;
|
35 |
| -import org.elasticsearch.common.collect.ImmutableOpenIntMap; |
36 | 35 | import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
37 | 36 | import org.elasticsearch.common.io.stream.StreamInput;
|
38 | 37 | import org.elasticsearch.common.settings.Settings;
|
|
52 | 51 | import java.io.IOException;
|
53 | 52 | import java.util.ArrayList;
|
54 | 53 | import java.util.Collections;
|
| 54 | +import java.util.HashMap; |
55 | 55 | import java.util.HashSet;
|
56 | 56 | import java.util.List;
|
57 | 57 | import java.util.Map;
|
@@ -403,25 +403,23 @@ private List<ClusterState> generateClusterStates(
|
403 | 403 | // some primaries started
|
404 | 404 | indexRoutingTable = routingTable.index(indexName);
|
405 | 405 | newIndexRoutingTable = IndexRoutingTable.builder(indexRoutingTable.getIndex());
|
406 |
| - ImmutableOpenIntMap.Builder<Set<String>> allocationIds = ImmutableOpenIntMap.<Set<String>>builder(); |
| 406 | + Map<Integer, Set<String>> allocationIds = new HashMap<>(); |
407 | 407 | for (int shardId = 0; shardId < indexRoutingTable.size(); shardId++) {
|
408 | 408 | IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId);
|
409 | 409 | for (int copy = 0; copy < shardRoutingTable.size(); copy++) {
|
410 | 410 | ShardRouting shardRouting = shardRoutingTable.shard(copy);
|
411 | 411 | if (shardRouting.primary() && randomBoolean()) {
|
412 | 412 | 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())); |
414 | 414 | newIndexRoutingTable.addShard(newShardRouting);
|
415 | 415 | } else {
|
416 | 416 | newIndexRoutingTable.addShard(shardRouting);
|
417 | 417 | }
|
418 | 418 | }
|
419 | 419 | }
|
420 | 420 | 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); |
425 | 423 | Metadata.Builder metadataBuilder = Metadata.builder(clusterState.metadata()).put(idxMetaBuilder);
|
426 | 424 | clusterState = ClusterState.builder(clusterState).routingTable(routingTable).metadata(metadataBuilder).build();
|
427 | 425 | clusterStates.add(clusterState);
|
@@ -453,26 +451,24 @@ private List<ClusterState> generateClusterStates(
|
453 | 451 | // all primaries started
|
454 | 452 | indexRoutingTable = routingTable.index(indexName);
|
455 | 453 | newIndexRoutingTable = IndexRoutingTable.builder(indexRoutingTable.getIndex());
|
456 |
| - allocationIds = ImmutableOpenIntMap.<Set<String>>builder(); |
| 454 | + allocationIds = new HashMap<>(); |
457 | 455 | for (int shardId = 0; shardId < indexRoutingTable.size(); shardId++) {
|
458 | 456 | IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId);
|
459 | 457 | for (int copy = 0; copy < shardRoutingTable.size(); copy++) {
|
460 | 458 | ShardRouting shardRouting = shardRoutingTable.shard(copy);
|
461 | 459 | if (shardRouting.primary() && shardRouting.started() == false) {
|
462 | 460 | 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())); |
464 | 462 | newIndexRoutingTable.addShard(newShardRouting);
|
465 | 463 | } else {
|
466 | 464 | newIndexRoutingTable.addShard(shardRouting);
|
467 | 465 | }
|
468 | 466 | }
|
469 | 467 | }
|
470 | 468 | 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); |
476 | 472 | clusterState = ClusterState.builder(clusterState).routingTable(routingTable).metadata(metadataBuilder).build();
|
477 | 473 | clusterStates.add(clusterState);
|
478 | 474 |
|
|
0 commit comments