From 17e9d82c8de461813023fe520fc8ebdf5f17e836 Mon Sep 17 00:00:00 2001 From: Pete Gillin Date: Fri, 24 Jul 2026 20:38:16 +0100 Subject: [PATCH 1/3] set correct unassigned priorities --- ...sAvailabilityHealthIndicatorBenchmark.java | 6 +- .../datastreams/DataStreamAutoshardingIT.java | 3 +- .../geoip/DatabaseNodeServiceTests.java | 3 +- .../decider/WriteLoadConstraintDeciderIT.java | 3 +- server/src/main/java/module-info.java | 1 + .../cluster/routing/IndexRoutingTable.java | 50 ++++++++++--- .../cluster/routing/ShardRouting.java | 7 +- .../cluster/node/stats/NodeStatsTests.java | 3 +- .../cluster/stats/VersionStatsTests.java | 3 +- .../recovery/RecoveryResponseTests.java | 3 +- .../TransportRolloverActionTests.java | 3 +- .../BulkPrimaryExecutionContextTests.java | 9 ++- .../bulk/TransportShardBulkActionTests.java | 9 ++- .../action/search/SearchAsyncActionTests.java | 6 +- .../action/support/ActiveShardCountTests.java | 3 +- .../replication/PostWriteRefreshTests.java | 9 ++- .../ReplicationSplitHelperTests.java | 9 ++- .../elasticsearch/cluster/DiskUsageTests.java | 6 +- .../metadata/IndexMetadataStatsTests.java | 3 +- .../cluster/routing/AllocationIdTests.java | 12 ++- .../AllocationFailuresResetTests.java | 3 +- .../ResizeAllocationDeciderTests.java | 6 +- .../allocation/ThrottlingAllocationTests.java | 3 +- .../allocator/ClusterInfoSimulatorTests.java | 3 +- .../DesiredBalanceShardsAllocatorTests.java | 6 +- .../UndesiredAllocationsTrackerTests.java | 3 +- .../decider/AllocationDecidersTests.java | 3 +- .../DiskThresholdDeciderUnitTests.java | 73 ++++++++++--------- .../decider/FilterAllocationDeciderTests.java | 6 +- ...NodeReplacementAllocationDeciderTests.java | 9 ++- .../NodeShutdownAllocationDeciderTests.java | 3 +- ...ailabilityHealthIndicatorServiceTests.java | 3 +- .../gateway/ReplicaShardAllocatorTests.java | 32 ++++++-- .../elasticsearch/index/IndexModuleTests.java | 6 +- .../SystemIndexMappingUpdateServiceTests.java | 6 +- .../TransportCancelRecoveriesActionTests.java | 6 +- .../repositories/fs/FsRepositoryTests.java | 3 +- .../snapshots/SnapshotsServiceTests.java | 3 +- .../DataTierAllocationDeciderTests.java | 3 +- ...StreamingLookupFromIndexOperatorTests.java | 10 ++- ...lConfigMigrationEligibilityCheckTests.java | 3 +- .../xpack/ml/MlIndexRolloverTests.java | 3 +- .../DatafeedConfigAutoUpdaterTests.java | 6 +- .../datafeed/DatafeedNodeSelectorTests.java | 3 +- .../TrainedModelStatsServiceTests.java | 6 +- .../OpenJobPersistentTasksExecutorTests.java | 3 +- ...stractJobPersistentTasksExecutorTests.java | 6 +- .../ClusterStatsMonitoringDocTests.java | 3 +- .../indices/IndexRecoveryCollectorTests.java | 10 ++- .../IndexRecoveryMonitoringDocTests.java | 3 +- .../action/IndexAllocationTests.java | 3 +- .../ProfilingDataStreamManagerTests.java | 3 +- .../ProfilingIndexManagerTests.java | 3 +- .../SearchableSnapshotDirectoryFactory.java | 3 +- .../authz/store/NativeRolesStoreTests.java | 3 +- .../support/SecurityIndexManagerTests.java | 15 ++-- .../security/test/SecurityTestUtils.java | 3 +- ...ailabilityHealthIndicatorServiceTests.java | 15 +++- .../reshard/ReshardIndexService.java | 3 +- ...imatedHeapUsageAllocationDeciderTests.java | 3 +- ...rchShardInformationIndexListenerTests.java | 3 +- ...etchSearchShardInformationActionTests.java | 13 +++- ...elessSnapshotShardContextFactoryTests.java | 3 +- .../TransformsCheckpointServiceTests.java | 3 +- ...TransformPersistentTasksExecutorTests.java | 6 +- .../ShardAllocationConfigurationTests.java | 3 +- .../ClusterInfoWriteLoadForecasterIT.java | 3 +- 67 files changed, 325 insertions(+), 150 deletions(-) diff --git a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/ShardsAvailabilityHealthIndicatorBenchmark.java b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/ShardsAvailabilityHealthIndicatorBenchmark.java index 4d31921d9adc3..d081fa9bb3622 100644 --- a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/ShardsAvailabilityHealthIndicatorBenchmark.java +++ b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/ShardsAvailabilityHealthIndicatorBenchmark.java @@ -144,7 +144,8 @@ public void setUp() throws Exception { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, decidersNoUnassignedInfo, - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING ); shardBuilder.addShard(shardRouting); if (shardIdNumber < numReplicas) { @@ -154,7 +155,8 @@ public void setUp() throws Exception { false, RecoverySource.EmptyStoreRecoverySource.INSTANCE, decidersNoUnassignedInfo, - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING ) ); } diff --git a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamAutoshardingIT.java b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamAutoshardingIT.java index a93e1d7ea9fb1..cb5b1dac37041 100644 --- a/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamAutoshardingIT.java +++ b/modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamAutoshardingIT.java @@ -520,7 +520,8 @@ private static ShardStats getShardStats(IndexMetadata indexMeta, int shardIndex, true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize(assignedShardNodeId, null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/modules/ip-location/src/test/java/org/elasticsearch/ingest/geoip/DatabaseNodeServiceTests.java b/modules/ip-location/src/test/java/org/elasticsearch/ingest/geoip/DatabaseNodeServiceTests.java index 2370eaae57b69..ec77922d26d7e 100644 --- a/modules/ip-location/src/test/java/org/elasticsearch/ingest/geoip/DatabaseNodeServiceTests.java +++ b/modules/ip-location/src/test/java/org/elasticsearch/ingest/geoip/DatabaseNodeServiceTests.java @@ -1017,7 +1017,8 @@ private static ClusterState createClusterState( true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); String nodeId = ESTestCase.randomAlphaOfLength(8); shardRouting = shardRouting.initialize(nodeId, null, shardRouting.getExpectedShardSize()); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/decider/WriteLoadConstraintDeciderIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/decider/WriteLoadConstraintDeciderIT.java index bacd45541cf35..7aa956b47209e 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/decider/WriteLoadConstraintDeciderIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/routing/allocation/decider/WriteLoadConstraintDeciderIT.java @@ -927,7 +927,8 @@ private static ShardStats createShardStats( true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize(assignedShardNodeId, null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/server/src/main/java/module-info.java b/server/src/main/java/module-info.java index 6b792bbcc73e6..0004440a9d6ab 100644 --- a/server/src/main/java/module-info.java +++ b/server/src/main/java/module-info.java @@ -57,6 +57,7 @@ requires org.apache.lucene.queryparser; requires org.apache.lucene.sandbox; requires org.apache.lucene.suggest; + requires org.jspecify; exports org.elasticsearch; exports org.elasticsearch.action; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java b/server/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java index 3d7f267dc8d0c..258e29ea984cb 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java @@ -387,35 +387,60 @@ public Builder(ShardRoutingRoleStrategy shardRoutingRoleStrategy, Index index) { * Initializes a new empty index, as if it was created from an API. */ public Builder initializeAsNew(IndexMetadata indexMetadata) { - return initializeEmpty(indexMetadata, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), null); + return initializeEmpty( + indexMetadata, + new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), + ShardRouting.RecoveryPriority.UNASSIGNED_NEW, + null + ); } /** * Initializes an existing index. */ public Builder initializeAsRecovery(IndexMetadata indexMetadata) { - return initializeEmpty(indexMetadata, new UnassignedInfo(UnassignedInfo.Reason.CLUSTER_RECOVERED, null), null); + return initializeEmpty( + indexMetadata, + new UnassignedInfo(UnassignedInfo.Reason.CLUSTER_RECOVERED, null), + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING, + null + ); } /** * Initializes a new index caused by dangling index imported. */ public Builder initializeAsFromDangling(IndexMetadata indexMetadata) { - return initializeEmpty(indexMetadata, new UnassignedInfo(UnassignedInfo.Reason.DANGLING_INDEX_IMPORTED, null), null); + return initializeEmpty( + indexMetadata, + new UnassignedInfo(UnassignedInfo.Reason.DANGLING_INDEX_IMPORTED, null), + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING, + null + ); } /** * Initializes a new empty index, as a result of opening a closed index. */ public Builder initializeAsFromCloseToOpen(IndexMetadata indexMetadata, IndexRoutingTable indexRoutingTable) { - return initializeEmpty(indexMetadata, new UnassignedInfo(UnassignedInfo.Reason.INDEX_REOPENED, null), indexRoutingTable); + return initializeEmpty( + indexMetadata, + new UnassignedInfo(UnassignedInfo.Reason.INDEX_REOPENED, null), + ShardRouting.RecoveryPriority.UNASSIGNED_NEW, + indexRoutingTable + ); } /** * Initializes a new empty index, as a result of closing an opened index. */ public Builder initializeAsFromOpenToClose(IndexMetadata indexMetadata, IndexRoutingTable indexRoutingTable) { - return initializeEmpty(indexMetadata, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CLOSED, null), indexRoutingTable); + return initializeEmpty( + indexMetadata, + new UnassignedInfo(UnassignedInfo.Reason.INDEX_CLOSED, null), + ShardRouting.RecoveryPriority.UNASSIGNED_NEW, + indexRoutingTable + ); } /** @@ -486,7 +511,8 @@ private Builder initializeAsRestore( primary, primary ? EmptyStoreRecoverySource.INSTANCE : PeerRecoverySource.INSTANCE, unassignedInfo, - shardRoutingRoleStrategy.newRestoredRole(i) + shardRoutingRoleStrategy.newRestoredRole(i), + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ) ); } else { @@ -496,7 +522,8 @@ private Builder initializeAsRestore( primary, primary ? recoverySource : PeerRecoverySource.INSTANCE, withLastAllocatedNodeId(unassignedInfo, previousNodes, i), - shardRoutingRoleStrategy.newRestoredRole(i) + shardRoutingRoleStrategy.newRestoredRole(i), + asNew ? ShardRouting.RecoveryPriority.UNASSIGNED_NEW : ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING ) ); } @@ -512,7 +539,8 @@ private Builder initializeAsRestore( private Builder initializeEmpty( IndexMetadata indexMetadata, UnassignedInfo unassignedInfo, - @Nullable IndexRoutingTable previousIndexRoutingTable + ShardRouting.RecoveryPriority recoveryPriority, + IndexRoutingTable previousIndexRoutingTable ) { assert indexMetadata.getIndex().equals(index); assert previousIndexRoutingTable == null || previousIndexRoutingTable.size() == indexMetadata.getNumberOfShards(); @@ -550,7 +578,8 @@ private Builder initializeEmpty( primary, primary ? primaryRecoverySource : PeerRecoverySource.INSTANCE, withLastAllocatedNodeId(shardUnassignedInfo, previousNodes, i), - shardRoutingRoleStrategy.newEmptyRole(i) + shardRoutingRoleStrategy.newEmptyRole(i), + recoveryPriority ) ); } @@ -614,7 +643,8 @@ public Builder addReplica(ShardRouting.Role role) { false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.REPLICA_ADDED, null), - role + role, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ) ); } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java b/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java index 13e1a6e176dba..b96e862951b6e 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java @@ -220,7 +220,8 @@ public static ShardRouting newUnassigned( boolean primary, RecoverySource recoverySource, UnassignedInfo unassignedInfo, - Role role + Role role, + RecoveryPriority recoveryPriority ) { return new ShardRouting( shardId, @@ -229,9 +230,7 @@ public static ShardRouting newUnassigned( primary, ShardRoutingState.UNASSIGNED, recoverySource, - // TODO: Populate this with the correct priority. For now, we use the higher of the two choices for a recovery from unassigned. - // As long as master-side recovery throttling is in effect, the priority is not that important. - RecoveryPriority.UNASSIGNED_EXISTING, + recoveryPriority, unassignedInfo, RelocationFailureInfo.NO_FAILURES, null, diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStatsTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStatsTests.java index d607575ce83b6..673a8a72f075c 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStatsTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStatsTests.java @@ -681,7 +681,8 @@ private static ShardStats createShardStats(ShardId shardId) { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "message"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); Path path = createTempDir().resolve("indices") .resolve(shardRouting.shardId().getIndex().getUUID()) diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/VersionStatsTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/VersionStatsTests.java index 990ed39ca1e4e..2870b9d774647 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/VersionStatsTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/VersionStatsTests.java @@ -104,7 +104,8 @@ public void testCreation() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "message"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); Path path = createTempDir().resolve("indices") .resolve(shardRouting.shardId().getIndex().getUUID()) diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/recovery/RecoveryResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/recovery/RecoveryResponseTests.java index 1e255e3f973f5..463d019771924 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/recovery/RecoveryResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/recovery/RecoveryResponseTests.java @@ -50,7 +50,8 @@ public void testChunkedToXContent() { false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize(sourceNode.getId(), null, randomNonNegativeLong()), sourceNode, targetNode diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java index 27e39bd748e2d..f728826cbdf8f 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverActionTests.java @@ -931,7 +931,8 @@ public static IndicesStatsResponse randomIndicesStatsResponse(final IndexMetadat primary, primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/server/src/test/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContextTests.java b/server/src/test/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContextTests.java index 36af66d11c2f4..4fbde5486e365 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContextTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContextTests.java @@ -182,6 +182,13 @@ public Translog.Location getTranslogLocation() { private ShardRouting newShardRouting(ShardId shardId, ShardRouting.Role role) { final UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "_message"); - return ShardRouting.newUnassigned(shardId, true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, unassignedInfo, role); + return ShardRouting.newUnassigned( + shardId, + true, + RecoverySource.ExistingStoreRecoverySource.INSTANCE, + unassignedInfo, + role, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW + ); } } diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java index f23513734b2c8..13ebf5a3c677b 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java @@ -804,7 +804,14 @@ public void testUpdateRequestWithSuccess() throws Exception { private ShardRouting newShardRouting(ShardRouting.Role role) { final UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "_message"); - return ShardRouting.newUnassigned(shardId, true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, unassignedInfo, role); + return ShardRouting.newUnassigned( + shardId, + true, + RecoverySource.ExistingStoreRecoverySource.INSTANCE, + unassignedInfo, + role, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW + ); } public void testRequestItemAreNotReplacedByPreparedRequestWhenRunningInServerless() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java index 4f206e4de0234..f427fd501bb53 100644 --- a/server/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java @@ -797,7 +797,8 @@ static List getShardsIter( true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foobar"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); if (primaryNode != null) { routing = routing.initialize(primaryNode.getId(), i + "p", 0); @@ -810,7 +811,8 @@ static List getShardsIter( false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foobar"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); if (replicaNode != null) { routing = routing.initialize(replicaNode.getId(), i + "r", 0); diff --git a/server/src/test/java/org/elasticsearch/action/support/ActiveShardCountTests.java b/server/src/test/java/org/elasticsearch/action/support/ActiveShardCountTests.java index 1096f92e4c605..c2fa3225378a7 100644 --- a/server/src/test/java/org/elasticsearch/action/support/ActiveShardCountTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/ActiveShardCountTests.java @@ -70,7 +70,8 @@ public void testEnoughShardsWhenProjectIsGone() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/server/src/test/java/org/elasticsearch/action/support/replication/PostWriteRefreshTests.java b/server/src/test/java/org/elasticsearch/action/support/replication/PostWriteRefreshTests.java index 7266996ef3c6d..a690955056ee9 100644 --- a/server/src/test/java/org/elasticsearch/action/support/replication/PostWriteRefreshTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/replication/PostWriteRefreshTests.java @@ -148,7 +148,8 @@ public void testPrimaryWithUnpromotables() throws IOException { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.INDEX_ONLY + ShardRouting.Role.INDEX_ONLY, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); when(primary.routingEntry()).thenReturn(routing); when(primary.getReplicationGroup()).thenReturn(replicationGroup).thenReturn(realReplicationGroup); @@ -158,7 +159,8 @@ public void testPrimaryWithUnpromotables() throws IOException { false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "message"), - ShardRouting.Role.SEARCH_ONLY + ShardRouting.Role.SEARCH_ONLY, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); when(routingTable.unpromotableShards()).thenReturn(List.of(shardRouting)); when(routingTable.shardId()).thenReturn(shardId); @@ -232,7 +234,8 @@ public void testWaitForWithNullLocationCompletedImmediately() throws IOException false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "message"), - ShardRouting.Role.SEARCH_ONLY + ShardRouting.Role.SEARCH_ONLY, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); // Randomly test scenarios with and without unpromotables if (randomBoolean()) { diff --git a/server/src/test/java/org/elasticsearch/action/support/replication/ReplicationSplitHelperTests.java b/server/src/test/java/org/elasticsearch/action/support/replication/ReplicationSplitHelperTests.java index be94316696f51..a6ab5f2d8d8b6 100644 --- a/server/src/test/java/org/elasticsearch/action/support/replication/ReplicationSplitHelperTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/replication/ReplicationSplitHelperTests.java @@ -262,7 +262,8 @@ protected Map splitRequestOnPrimary(TestReplica true, recoverySource, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize("node-1", allocationId.getId(), 0).moveToStarted(0); when(shardRoutingTable.primaryShard()).thenReturn(targetShardRouting); @@ -386,7 +387,8 @@ protected Tuple combineSplitResponses( true, recoverySource, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize("node-1", allocationId.getId(), 0).moveToStarted(0); when(shardRoutingTable.primaryShard()).thenReturn(targetShardRouting); @@ -517,7 +519,8 @@ protected Tuple combineSplitResponses( true, recoverySource, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize("node-1", allocationId.getId(), 0).moveToStarted(0); when(shardRoutingTable.primaryShard()).thenReturn(targetShardRouting); diff --git a/server/src/test/java/org/elasticsearch/cluster/DiskUsageTests.java b/server/src/test/java/org/elasticsearch/cluster/DiskUsageTests.java index 2f798e6e49ef1..05119a7512ea1 100644 --- a/server/src/test/java/org/elasticsearch/cluster/DiskUsageTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/DiskUsageTests.java @@ -102,7 +102,8 @@ public void testFillShardLevelInfo() { false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_0 = ShardRoutingHelper.initialize(test_0, "node1"); test_0 = ShardRoutingHelper.moveToStarted(test_0); @@ -115,7 +116,8 @@ public void testFillShardLevelInfo() { false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_1 = ShardRoutingHelper.initialize(test_1, "node2"); test_1 = ShardRoutingHelper.moveToStarted(test_1); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataStatsTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataStatsTests.java index f07e4c844310a..9289bd2918594 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataStatsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataStatsTests.java @@ -103,7 +103,8 @@ private ShardStats createShardStats( primary, recoverySource, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = ShardRoutingHelper.initialize(shardRouting, UUIDs.randomBase64UUID()); shardRouting = ShardRoutingHelper.moveToStarted(shardRouting); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/AllocationIdTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/AllocationIdTests.java index e3227d81258a8..cf11a4376a935 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/AllocationIdTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/AllocationIdTests.java @@ -33,7 +33,8 @@ public void testShardToStarted() { true, ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); assertThat(shard.allocationId(), nullValue()); @@ -59,7 +60,8 @@ public void testSuccessfulRelocation() { true, ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shard = shard.initialize("node1", null, -1); shard = shard.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); @@ -88,7 +90,8 @@ public void testCancelRelocation() { true, ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shard = shard.initialize("node1", null, -1); shard = shard.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); @@ -114,7 +117,8 @@ public void testMoveToUnassigned() { true, ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shard = shard.initialize("node1", null, -1); shard = shard.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationFailuresResetTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationFailuresResetTests.java index a0e10878c3992..4d9dc2b1d54f8 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationFailuresResetTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationFailuresResetTests.java @@ -88,7 +88,8 @@ private static ClusterState addShardWithFailures(ClusterState state) { true, new RecoverySource.EmptyStoreRecoverySource(), unassignedInfo, - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); var routingTable = new RoutingTable.Builder().add( diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ResizeAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ResizeAllocationDeciderTests.java index ca8965ea73967..646b9986358df 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ResizeAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ResizeAllocationDeciderTests.java @@ -385,7 +385,8 @@ public void testGetForcedInitialShardAllocationToNodes() { true, RecoverySource.LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); assertThat(decider.getForcedInitialShardAllocationToNodes(localRecoveryShard, allocation), equalTo(Optional.of(Set.of("node-1")))); @@ -394,7 +395,8 @@ public void testGetForcedInitialShardAllocationToNodes() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); assertThat(decider.getForcedInitialShardAllocationToNodes(newShard, allocation), equalTo(Optional.empty())); } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java index 3aeff0009f1be..6647b39e2a3dd 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java @@ -458,7 +458,8 @@ private void addInSyncAllocationIds( primary, primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); ShardRouting started = ShardRoutingHelper.moveToStarted(ShardRoutingHelper.initialize(unassigned, node1.getId())); indexMetadata.putInSyncAllocationIds(shard, Collections.singleton(started.allocationId().getId())); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterInfoSimulatorTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterInfoSimulatorTests.java index c366bf372afc8..a48c8677fe861 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterInfoSimulatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterInfoSimulatorTests.java @@ -753,7 +753,8 @@ public void testSimulateAlreadyStartedShard() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(REINITIALIZED, "simulation"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING ).initialize(randomIdentifier(), null, randomLongBetween(100, 999)).moveToStarted(randomLongBetween(100, 999)); // New shard without relocation diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocatorTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocatorTests.java index 13e023c24fade..2fa27feb4f870 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocatorTests.java @@ -854,7 +854,8 @@ public void testSimulateStartedShardsWithinASingleClusterInfoPolling() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "new index"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ), firstNode.getId() ) @@ -867,7 +868,8 @@ public void testSimulateStartedShardsWithinASingleClusterInfoPolling() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "new index"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ), thirdNode.getId() ); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/UndesiredAllocationsTrackerTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/UndesiredAllocationsTrackerTests.java index 737ddac952b99..ea331410df048 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/UndesiredAllocationsTrackerTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/UndesiredAllocationsTrackerTests.java @@ -479,7 +479,8 @@ private ShardRouting createAssignedRouting( primary, primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, randomIdentifier()), - role + role, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize(nodeId, null, randomNonNegativeLong()); } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java index bbe77dc82bde8..dccde8530c26f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java @@ -259,7 +259,8 @@ private static ShardRouting createUnassignedShard(Index index) { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "_message"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java index 2e0a92a112974..ea4f5830f1661 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java @@ -85,7 +85,8 @@ public void testCanAllocateUsesMaxAvailableSpace() { true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); DiscoveryNode node_0 = DiscoveryNodeUtils.builder("node_0").roles(new HashSet<>(DiscoveryNodeRole.roles())).build(); DiscoveryNode node_1 = DiscoveryNodeUtils.builder("node_1").roles(new HashSet<>(DiscoveryNodeRole.roles())).build(); @@ -155,7 +156,8 @@ private void doTestCannotAllocateDueToLackOfDiskResources(boolean testMaxHeadroo true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); DiscoveryNode node_0 = DiscoveryNodeUtils.builder("node_0").roles(new HashSet<>(DiscoveryNodeRole.roles())).build(); DiscoveryNode node_1 = DiscoveryNodeUtils.builder("node_1").roles(new HashSet<>(DiscoveryNodeRole.roles())).build(); @@ -257,7 +259,8 @@ private void doTestCanRemainUsesLeastAvailableSpace(boolean testMaxHeadroom) { true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_0 = ShardRoutingHelper.initialize(test_0, node_0.getId()); test_0 = ShardRoutingHelper.moveToStarted(test_0); @@ -268,7 +271,8 @@ private void doTestCanRemainUsesLeastAvailableSpace(boolean testMaxHeadroom) { true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_1 = ShardRoutingHelper.initialize(test_1, node_1.getId()); test_1 = ShardRoutingHelper.moveToStarted(test_1); @@ -279,7 +283,8 @@ private void doTestCanRemainUsesLeastAvailableSpace(boolean testMaxHeadroom) { true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_2 = ShardRoutingHelper.initialize(test_2, node_1.getId()); test_2 = ShardRoutingHelper.moveToStarted(test_2); @@ -290,7 +295,8 @@ private void doTestCanRemainUsesLeastAvailableSpace(boolean testMaxHeadroom) { true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_3 = ShardRoutingHelper.initialize(test_3, node_1.getId()); test_3 = ShardRoutingHelper.moveToStarted(test_3); @@ -445,7 +451,8 @@ public void testShardSizeAndRelocatingSize() { false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_0 = ShardRoutingHelper.initialize(test_0, "node1"); test_0 = ShardRoutingHelper.moveToStarted(test_0); @@ -456,7 +463,8 @@ public void testShardSizeAndRelocatingSize() { false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_1 = ShardRoutingHelper.initialize(test_1, "node2"); test_1 = ShardRoutingHelper.moveToStarted(test_1); @@ -467,7 +475,8 @@ public void testShardSizeAndRelocatingSize() { false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_2 = ShardRoutingHelper.initialize(test_2, "node1"); test_2 = ShardRoutingHelper.moveToStarted(test_2); @@ -493,7 +502,8 @@ public void testShardSizeAndRelocatingSize() { false, PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_3 = ShardRoutingHelper.initialize(test_3, "node1"); test_3 = ShardRoutingHelper.moveToStarted(test_3); @@ -505,7 +515,8 @@ public void testShardSizeAndRelocatingSize() { primary, primary ? EmptyStoreRecoverySource.INSTANCE : PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); other_0 = ShardRoutingHelper.initialize(other_0, "node2"); other_0 = ShardRoutingHelper.moveToStarted(other_0); @@ -586,19 +597,6 @@ public void testTakesIntoAccountExpectedSizeForInitializingSearchableSnapshots() ); } - private ShardRouting createShard(Index index, String nodeId, int i, int expectedSize) { - var unassigned = ShardRouting.newUnassigned( - new ShardId(index, i), - true, - EmptyStoreRecoverySource.INSTANCE, - new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT - ); - var initialized = ShardRoutingHelper.initialize(unassigned, nodeId, expectedSize); - var started = ShardRoutingHelper.moveToStarted(initialized, expectedSize); - return started; - } - public long sizeOfUnaccountedShards(RoutingAllocation allocation, RoutingNode node, boolean subtractShardsMovingAway, String dataPath) { return DiskThresholdDecider.sizeOfUnaccountedShards( node, @@ -679,7 +677,8 @@ public void testSizeShrinkIndex() { true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_0 = ShardRoutingHelper.initialize(test_0, "node1"); test_0 = ShardRoutingHelper.moveToStarted(test_0); @@ -689,7 +688,8 @@ public void testSizeShrinkIndex() { true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_1 = ShardRoutingHelper.initialize(test_1, "node2"); test_1 = ShardRoutingHelper.moveToStarted(test_1); @@ -699,7 +699,8 @@ public void testSizeShrinkIndex() { true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_2 = ShardRoutingHelper.initialize(test_2, "node1"); @@ -708,7 +709,8 @@ public void testSizeShrinkIndex() { true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); test_3 = ShardRoutingHelper.initialize(test_3, "node1"); assertEquals(500L, getExpectedShardSize(test_3, 0L, allocation)); @@ -721,7 +723,8 @@ public void testSizeShrinkIndex() { true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); assertEquals(1110L, getExpectedShardSize(target, 0L, allocation)); @@ -730,7 +733,8 @@ public void testSizeShrinkIndex() { true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); assertEquals(510L, getExpectedShardSize(target2, 0L, allocation)); @@ -739,7 +743,8 @@ public void testSizeShrinkIndex() { true, LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); assertEquals(600L, getExpectedShardSize(target2, 0L, allocation)); @@ -853,7 +858,8 @@ public void testDecidesYesIfWatermarksIgnored() { true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); DiscoveryNode node_0 = DiscoveryNodeUtils.builder("node_0").roles(new HashSet<>(DiscoveryNodeRole.roles())).build(); DiscoveryNode node_1 = DiscoveryNodeUtils.builder("node_1").roles(new HashSet<>(DiscoveryNodeRole.roles())).build(); @@ -918,7 +924,8 @@ public void testCannotForceAllocateOver100PercentUsage() { true, EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); DiscoveryNode node_0 = DiscoveryNodeUtils.builder("node_0").roles(new HashSet<>(DiscoveryNodeRole.roles())).build(); DiscoveryNode node_1 = DiscoveryNodeUtils.builder("node_1").roles(new HashSet<>(DiscoveryNodeRole.roles())).build(); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java index 60898d6a4aee6..62cdba51f3883 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java @@ -325,7 +325,8 @@ public void testGetForcedInitialShardAllocationToNodes() { true, RecoverySource.LocalShardsRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); assertThat(decider.getForcedInitialShardAllocationToNodes(localRecoveryShard, allocation), equalTo(Optional.of(Set.of("node-1")))); @@ -334,7 +335,8 @@ public void testGetForcedInitialShardAllocationToNodes() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); assertThat(decider.getForcedInitialShardAllocationToNodes(newShard, allocation), equalTo(Optional.empty())); } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java index 9ff63b1fe7661..2c3da95bceb04 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java @@ -56,7 +56,8 @@ public class NodeReplacementAllocationDeciderTests extends ESAllocationTestCase true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); private final ClusterSettings clusterSettings = createBuiltInClusterSettings(); private final NodeReplacementAllocationDecider decider = new NodeReplacementAllocationDecider(); @@ -98,7 +99,8 @@ public void testCanForceAllocate() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); assignedShard = assignedShard.initialize(NODE_A.getId(), null, 1); assignedShard = assignedShard.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); @@ -283,7 +285,8 @@ public void testCanAllocateToTargetWhenSourceLeftBeforeFinishVacate() { Set.of(), NODE_A.getId() ), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING ); state = ClusterState.builder(state) .nodes(DiscoveryNodes.builder(state.nodes()).remove(NODE_A.getId()).build()) diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java index 40502d175254b..8ad60cebbaade 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java @@ -46,7 +46,8 @@ public class NodeShutdownAllocationDeciderTests extends ESAllocationTestCase { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); private final ClusterSettings clusterSettings = createBuiltInClusterSettings(); private final NodeShutdownAllocationDecider decider = new NodeShutdownAllocationDecider(); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/shards/StatefulShardsAvailabilityHealthIndicatorServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/shards/StatefulShardsAvailabilityHealthIndicatorServiceTests.java index 91841868345ef..a98343b79dc2d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/shards/StatefulShardsAvailabilityHealthIndicatorServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/shards/StatefulShardsAvailabilityHealthIndicatorServiceTests.java @@ -2827,7 +2827,8 @@ private static ShardRouting createShardRouting(ShardId shardId, boolean primary, primary, getSource(primary, allocation.state), initialUnassignedInfo, - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); if (allocation.state == CREATING) { return routing; diff --git a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java index cac20286ded6e..0c21dc0fea4cb 100644 --- a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java @@ -107,7 +107,8 @@ public void testNoAsyncFetchOnIndexCreation() { RoutingAllocation allocation = onePrimaryOnNode1And1Replica( yesAllocationDeciders(), Settings.EMPTY, - UnassignedInfo.Reason.INDEX_CREATED + UnassignedInfo.Reason.INDEX_CREATED, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); testAllocator.clean(); allocateAllUnassigned(allocation); @@ -125,7 +126,11 @@ public void testAsyncFetchOnAnythingButIndexCreation() { random(), EnumSet.complementOf(EnumSet.of(UnassignedInfo.Reason.INDEX_CREATED)) ); - RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders(), Settings.EMPTY, reason); + ShardRouting.RecoveryPriority recoveryPriority = randomFrom( + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW + ); // this priority may or may not make sense for the chosen reason, but it shouldn't affect the test anyway + RoutingAllocation allocation = onePrimaryOnNode1And1Replica(yesAllocationDeciders(), Settings.EMPTY, reason, recoveryPriority); testAllocator.clean(); allocateAllUnassigned(allocation); assertThat("failed with reason " + reason, testAllocator.getFetchDataCalledAndClean(), equalTo(true)); @@ -394,7 +399,8 @@ public void testDelayedAllocation() { RoutingAllocation allocation = onePrimaryOnNode1And1Replica( yesAllocationDeciders(), Settings.builder().put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueHours(1)).build(), - UnassignedInfo.Reason.NODE_LEFT + UnassignedInfo.Reason.NODE_LEFT, + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING ); testAllocator.addData(node1, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION)); if (randomBoolean()) { @@ -409,7 +415,8 @@ public void testDelayedAllocation() { allocation = onePrimaryOnNode1And1Replica( yesAllocationDeciders(), Settings.builder().put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueHours(1)).build(), - UnassignedInfo.Reason.NODE_LEFT + UnassignedInfo.Reason.NODE_LEFT, + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING ); testAllocator.addData(node2, "MATCH", new StoreFileMetadata("file1", 10, "MATCH_CHECKSUM", MIN_SUPPORTED_LUCENE_VERSION)); allocateAllUnassigned(allocation); @@ -587,10 +594,20 @@ private static AllocationDeciders notPreferredAllocationDeciders() { } private RoutingAllocation onePrimaryOnNode1And1Replica(AllocationDeciders deciders) { - return onePrimaryOnNode1And1Replica(deciders, Settings.EMPTY, UnassignedInfo.Reason.CLUSTER_RECOVERED); + return onePrimaryOnNode1And1Replica( + deciders, + Settings.EMPTY, + UnassignedInfo.Reason.CLUSTER_RECOVERED, + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING + ); } - private RoutingAllocation onePrimaryOnNode1And1Replica(AllocationDeciders deciders, Settings settings, UnassignedInfo.Reason reason) { + private RoutingAllocation onePrimaryOnNode1And1Replica( + AllocationDeciders deciders, + Settings settings, + UnassignedInfo.Reason reason, + ShardRouting.RecoveryPriority recoveryPriority + ) { ShardRouting primaryShard = TestShardRouting.newShardRouting(shardId, node1.getId(), true, ShardRoutingState.STARTED); IndexMetadata.Builder indexMetadata = IndexMetadata.builder(shardId.getIndexName()) .settings(settings(IndexVersion.current()).put(settings)) @@ -627,7 +644,8 @@ private RoutingAllocation onePrimaryOnNode1And1Replica(AllocationDeciders decide Collections.emptySet(), lastAllocatedNodeId ), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + recoveryPriority ) ) ) diff --git a/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java b/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java index cb9e72aac8b28..c4bb366b051f3 100644 --- a/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java +++ b/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java @@ -774,7 +774,8 @@ public void onIndexCommitDelete(ShardId shardId, IndexCommit deletedCommit) { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize("_node_id", null, -1); IndexService indexService = newIndexService(module); @@ -822,7 +823,8 @@ private ShardRouting createInitializedShardRouting() { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shard = shard.initialize("node1", null, -1); return shard; diff --git a/server/src/test/java/org/elasticsearch/indices/SystemIndexMappingUpdateServiceTests.java b/server/src/test/java/org/elasticsearch/indices/SystemIndexMappingUpdateServiceTests.java index 8cfad213e5aba..3b4c25dbc3638 100644 --- a/server/src/test/java/org/elasticsearch/indices/SystemIndexMappingUpdateServiceTests.java +++ b/server/src/test/java/org/elasticsearch/indices/SystemIndexMappingUpdateServiceTests.java @@ -391,7 +391,8 @@ private ProjectState markShardsUnavailable(ProjectState projectState) { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ) .initialize(UUIDs.randomBase64UUID(random()), null, 0L) .moveToUnassigned(new UnassignedInfo(UnassignedInfo.Reason.ALLOCATION_FAILED, "")) @@ -442,7 +443,8 @@ private static RoutingTable buildIndexRoutingTable(Index index) { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); String nodeId = ESTestCase.randomAlphaOfLength(8); return RoutingTable.builder() diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/TransportCancelRecoveriesActionTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/TransportCancelRecoveriesActionTests.java index 75a50a9756412..6fc421e853e9c 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/TransportCancelRecoveriesActionTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/TransportCancelRecoveriesActionTests.java @@ -424,7 +424,8 @@ public void testCancellationOfStartedReshardSplitRecoveriesIsNotSupported() thro true, new RecoverySource.ReshardSplitRecoverySource(shardId), new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize(randomIdentifier(), allocationId, 0L); when(indicesService.indexServiceSafe(shardId.getIndex())).thenReturn(indexService); @@ -528,7 +529,8 @@ private static IndexShard mockIndexShard(ShardId shardId, String allocationId) t true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize(randomIdentifier(), allocationId, 0L); when(indexShard.shardId()).thenReturn(shardId); when(indexShard.routingEntry()).thenReturn(routing); diff --git a/server/src/test/java/org/elasticsearch/repositories/fs/FsRepositoryTests.java b/server/src/test/java/org/elasticsearch/repositories/fs/FsRepositoryTests.java index 2eec4b7493c8a..e830836420b5b 100644 --- a/server/src/test/java/org/elasticsearch/repositories/fs/FsRepositoryTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/fs/FsRepositoryTests.java @@ -149,7 +149,8 @@ public void testSnapshotAndRestore() throws IOException { true, new RecoverySource.SnapshotRecoverySource("test", new Snapshot("foo", snapshotId), IndexVersion.current(), indexId), new UnassignedInfo(UnassignedInfo.Reason.EXISTING_INDEX_RESTORED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_EXISTING ); routing = ShardRoutingHelper.initialize(routing, localNode.getId(), 0); RecoveryState state = new RecoveryState(routing, localNode, null); diff --git a/server/src/test/java/org/elasticsearch/snapshots/SnapshotsServiceTests.java b/server/src/test/java/org/elasticsearch/snapshots/SnapshotsServiceTests.java index 7181cda1b5e0b..acf518ae85163 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SnapshotsServiceTests.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SnapshotsServiceTests.java @@ -700,7 +700,8 @@ private static ClusterState stateWithUnassignedIndices(String... indexNames) { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ) ) ) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java index 64aec80c16420..eabb2adc217c4 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java @@ -112,7 +112,8 @@ public class DataTierAllocationDeciderTests extends ESAllocationTestCase { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "index created"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); public void testIndexPrefer() { diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/enrich/StreamingLookupFromIndexOperatorTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/enrich/StreamingLookupFromIndexOperatorTests.java index 374c2af4b5748..3c941d3c7436f 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/enrich/StreamingLookupFromIndexOperatorTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/enrich/StreamingLookupFromIndexOperatorTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.cluster.routing.GlobalRoutingTable; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; +import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; @@ -515,7 +516,8 @@ private ClusterState buildClusterStateWithNodes( true, // primary org.elasticsearch.cluster.routing.RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize(serverNodes.get(0).getId(), null, 0).moveToStarted(0); shardRoutingBuilder.addShard(primaryRouting); @@ -526,7 +528,8 @@ private ClusterState buildClusterStateWithNodes( false, // replica org.elasticsearch.cluster.routing.RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize(serverNodes.get(i).getId(), null, 0).moveToStarted(0); shardRoutingBuilder.addShard(replicaRouting); } @@ -581,7 +584,8 @@ private ClusterState buildClusterStateForSingleNode(ProjectId projectId, String true, // primary org.elasticsearch.cluster.routing.RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize(localNode.getId(), null, 0).moveToStarted(0); shardRoutingBuilder.addShard(primaryRouting); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlConfigMigrationEligibilityCheckTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlConfigMigrationEligibilityCheckTests.java index 57acdf62d9b41..db0d9ec346d7d 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlConfigMigrationEligibilityCheckTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlConfigMigrationEligibilityCheckTests.java @@ -131,7 +131,8 @@ private void addMlConfigIndex(String indexName, String aliasName, Metadata.Build true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlIndexRolloverTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlIndexRolloverTests.java index 6a88148d2f70f..2402f43a347a0 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlIndexRolloverTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlIndexRolloverTests.java @@ -111,7 +111,8 @@ public void testIsAbleToRun_IndicesHaveNoActiveShards() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); var routingTable = RoutingTable.builder() diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfigAutoUpdaterTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfigAutoUpdaterTests.java index 337de5ae7d7a4..e7e91a606c584 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfigAutoUpdaterTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfigAutoUpdaterTests.java @@ -179,7 +179,8 @@ public void testIsAbleToRun() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); @@ -205,7 +206,8 @@ public void testIsAbleToRun() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); routingTable.add( diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java index 5b7e7dcf2dc67..711efa1263c6a 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java @@ -816,7 +816,8 @@ private static RoutingTable generateRoutingTable(IndexMetadata indexMetadata, Li true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/TrainedModelStatsServiceTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/TrainedModelStatsServiceTests.java index a95c8a92d93ee..685c1f506c2ff 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/TrainedModelStatsServiceTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/TrainedModelStatsServiceTests.java @@ -127,7 +127,8 @@ public void testVerifyIndicesExistAndPrimaryShardsAreActive() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); routingTable.add( @@ -354,7 +355,8 @@ private static void addToRoutingTable(String concreteIndex, RoutingTable.Builder true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutorTests.java index 28ebfc14e62ae..06c94b58cdb4b 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutorTests.java @@ -356,7 +356,8 @@ private void addIndices(Metadata.Builder metadata, RoutingTable.Builder routingT true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java index b5160ec69545e..cadb1e652fd2d 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java @@ -87,7 +87,8 @@ public void testVerifyIndicesPrimaryShardsAreActive() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); routingTable.add( @@ -139,7 +140,8 @@ private void addIndices(Metadata.Builder metadata, RoutingTable.Builder routingT true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index b9365ddcaef94..874c00da04e6f 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -408,7 +408,8 @@ public void testToXContent() throws IOException { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, unassignedInfo, - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); final ShardStats mockShardStats = mock(ShardStats.class); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java index 98370b847cc82..cbee66dd7b2e9 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java @@ -101,8 +101,14 @@ public void testDoCollect() throws Exception { ShardId shardId = new ShardId("_index_" + i, "_uuid_" + i, i); RecoverySource source = RecoverySource.PeerRecoverySource.INSTANCE; final UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "_index_info_" + i); - final ShardRouting shardRouting = ShardRouting.newUnassigned(shardId, false, source, unassignedInfo, ShardRouting.Role.DEFAULT) - .initialize(localNode.getId(), "_allocation_id", 10 * i); + final ShardRouting shardRouting = ShardRouting.newUnassigned( + shardId, + false, + source, + unassignedInfo, + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW + ).initialize(localNode.getId(), "_allocation_id", 10 * i); final RecoveryState recoveryState = new RecoveryState(shardRouting, localNode, localNode); recoveryStates.put("_index_" + i, singletonList(recoveryState)); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java index 35b5578602621..5f778abd9ce66 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java @@ -114,7 +114,8 @@ public void testToXContent() throws IOException { false, RecoverySource.PeerRecoverySource.INSTANCE, unassignedInfo, - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize("_node_id", "_allocation_id", 123L); final Map> shardRecoveryStates = new HashMap<>(); diff --git a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/action/IndexAllocationTests.java b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/action/IndexAllocationTests.java index 756636ef84f78..98171c8666520 100644 --- a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/action/IndexAllocationTests.java +++ b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/action/IndexAllocationTests.java @@ -108,7 +108,8 @@ private ClusterState clusterState() { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("n-" + index.getName(), null, 0).moveToStarted(0); diff --git a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/persistence/ProfilingDataStreamManagerTests.java b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/persistence/ProfilingDataStreamManagerTests.java index f06abdaca670e..b4650e55d110d 100644 --- a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/persistence/ProfilingDataStreamManagerTests.java +++ b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/persistence/ProfilingDataStreamManagerTests.java @@ -510,7 +510,8 @@ private ClusterState createClusterState( true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); if (allShardsAssigned) { shardRouting = shardRouting.initialize("node0", null, 0).moveToStarted(0); diff --git a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/persistence/ProfilingIndexManagerTests.java b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/persistence/ProfilingIndexManagerTests.java index ddde97d338da7..aca7dcb5d791a 100644 --- a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/persistence/ProfilingIndexManagerTests.java +++ b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/persistence/ProfilingIndexManagerTests.java @@ -522,7 +522,8 @@ private ClusterState createClusterState( true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); if (allShardsAssigned) { shardRouting = shardRouting.initialize("node0", null, 0).moveToStarted(0); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryFactory.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryFactory.java index e13ac1639f2b1..69bbb6a79cffd 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryFactory.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryFactory.java @@ -650,7 +650,8 @@ private static SearchableSnapshotRecoveryState createRecoveryState(boolean final Set.of(), "" ), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize("node1", "existingAllocationId", ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); DiscoveryNode targetNode = new DiscoveryNode( diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStoreTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStoreTests.java index cef727159ea30..9eb8c9990fd97 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStoreTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/store/NativeRolesStoreTests.java @@ -852,7 +852,8 @@ private ClusterState getClusterStateWithSecurityIndex(ProjectId projectId) { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); RoutingTable routingTable = RoutingTable.builder() .add( diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java index d34984ecbf862..adae2b731f988 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java @@ -190,7 +190,8 @@ public void testIndexWithoutPrimaryShards() { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); String nodeId = ESTestCase.randomAlphaOfLength(8); clusterStateBuilder.routingTable( @@ -225,14 +226,16 @@ public void testIndexAvailability() { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.INDEX_ONLY + ShardRouting.Role.INDEX_ONLY, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); ShardRouting replica = ShardRouting.newUnassigned( shardId, false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.REPLICA_ADDED, null), - ShardRouting.Role.SEARCH_ONLY + ShardRouting.Role.SEARCH_ONLY, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); String nodeId = ESTestCase.randomAlphaOfLength(8); String nodeId2 = ESTestCase.randomAlphaOfLength(8); @@ -423,7 +426,8 @@ public void testIndexHealthChangeListeners() { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ) .initialize(UUIDs.randomBase64UUID(random()), null, 0L) .moveToUnassigned(new UnassignedInfo(UnassignedInfo.Reason.ALLOCATION_FAILED, "")) @@ -1036,7 +1040,8 @@ private void markShardsUnavailable() { true, RecoverySource.ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); final String nodeId = ESTestCase.randomAlphaOfLength(8); final ClusterState.Builder clusterStateBuilder = ClusterState.builder(cs) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/test/SecurityTestUtils.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/test/SecurityTestUtils.java index fe07369e0b89a..08fc5a355312c 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/test/SecurityTestUtils.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/test/SecurityTestUtils.java @@ -73,7 +73,8 @@ public static RoutingTable buildIndexRoutingTable(Index index) { true, ExistingStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); String nodeId = ESTestCase.randomAlphaOfLength(8); return RoutingTable.builder() diff --git a/x-pack/plugin/stateless-health-shards-availability/src/test/java/org/elasticsearch/xpack/stateless/health/StatelessShardsAvailabilityHealthIndicatorServiceTests.java b/x-pack/plugin/stateless-health-shards-availability/src/test/java/org/elasticsearch/xpack/stateless/health/StatelessShardsAvailabilityHealthIndicatorServiceTests.java index 49619aecb54ca..203a39f3c8f59 100644 --- a/x-pack/plugin/stateless-health-shards-availability/src/test/java/org/elasticsearch/xpack/stateless/health/StatelessShardsAvailabilityHealthIndicatorServiceTests.java +++ b/x-pack/plugin/stateless-health-shards-availability/src/test/java/org/elasticsearch/xpack/stateless/health/StatelessShardsAvailabilityHealthIndicatorServiceTests.java @@ -288,14 +288,16 @@ public void testHealthWhileReshardSplitTargetShardsInactive() { true, new RecoverySource.ReshardSplitRecoverySource(sourceShardId), unassignedInfo(UnassignedInfo.Reason.RESHARD_ADDED, unassignedAt), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); var targetShardReplica = newUnassigned( targetShardId, false, RecoverySource.PeerRecoverySource.INSTANCE, unassignedInfo(UnassignedInfo.Reason.RESHARD_ADDED, unassignedAt), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); if (randomBoolean()) { targetShardPrimary = targetShardPrimary.initialize(nodeB, null, 0); @@ -464,7 +466,14 @@ private static ShardRouting shardRouting( ? (unassignedInfo != null ? recoverySourceFrom(unassignedInfo) : RecoverySource.ExistingStoreRecoverySource.INSTANCE) : RecoverySource.PeerRecoverySource.INSTANCE; - var routing = newUnassigned(shardId, primary, recoverySource, info, ShardRouting.Role.DEFAULT); + var routing = newUnassigned( + shardId, + primary, + recoverySource, + info, + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW // may not correspond to the reason in unassignedInfo, but that shouldn't matter + ); if (state == ShardRoutingState.UNASSIGNED) { return routing; } diff --git a/x-pack/plugin/stateless/src/main/java/org/elasticsearch/xpack/stateless/reshard/ReshardIndexService.java b/x-pack/plugin/stateless/src/main/java/org/elasticsearch/xpack/stateless/reshard/ReshardIndexService.java index 3955d0ad20019..f96c26d082ba8 100644 --- a/x-pack/plugin/stateless/src/main/java/org/elasticsearch/xpack/stateless/reshard/ReshardIndexService.java +++ b/x-pack/plugin/stateless/src/main/java/org/elasticsearch/xpack/stateless/reshard/ReshardIndexService.java @@ -518,7 +518,8 @@ static RoutingTable.Builder addShardsToRoutingTable( primary, recoverySource, new UnassignedInfo(UnassignedInfo.Reason.RESHARD_ADDED, null), - routingTableBuilder.getShardRoutingRoleStrategy().newEmptyRole(j) + routingTableBuilder.getShardRoutingRoleStrategy().newEmptyRole(j), + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); indexShardRoutingBuilder.addShard(shardRouting); } diff --git a/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/allocation/EstimatedHeapUsageAllocationDeciderTests.java b/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/allocation/EstimatedHeapUsageAllocationDeciderTests.java index 0a97a7ab43945..db7e4e6bd7b3d 100644 --- a/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/allocation/EstimatedHeapUsageAllocationDeciderTests.java +++ b/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/allocation/EstimatedHeapUsageAllocationDeciderTests.java @@ -639,7 +639,8 @@ private static ShardRouting createShardRouting() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, TestShardRouting.buildUnassignedInfo("auto generated for test"), - ShardRouting.Role.INDEX_ONLY + ShardRouting.Role.INDEX_ONLY, + TestShardRouting.buildRecoveryPriority(ShardRoutingState.UNASSIGNED, false) ); } diff --git a/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/recovery/shardinfo/SearchShardInformationIndexListenerTests.java b/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/recovery/shardinfo/SearchShardInformationIndexListenerTests.java index 152c42c0b58aa..8b26f270c90d5 100644 --- a/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/recovery/shardinfo/SearchShardInformationIndexListenerTests.java +++ b/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/recovery/shardinfo/SearchShardInformationIndexListenerTests.java @@ -479,7 +479,8 @@ private ShardRouting createSearchOnlyShard(ShardId shardId, String nodeId) { false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.SEARCH_ONLY + ShardRouting.Role.SEARCH_ONLY, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ).initialize(nodeId, null, randomNonNegativeLong()); } diff --git a/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/recovery/shardinfo/TransportFetchSearchShardInformationActionTests.java b/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/recovery/shardinfo/TransportFetchSearchShardInformationActionTests.java index cbfad8dd61b23..80b3363f8b5a7 100644 --- a/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/recovery/shardinfo/TransportFetchSearchShardInformationActionTests.java +++ b/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/recovery/shardinfo/TransportFetchSearchShardInformationActionTests.java @@ -71,12 +71,14 @@ public class TransportFetchSearchShardInformationActionTests extends ESTestCase private final Index index = new Index("my_index", "uuid"); private final ShardId shardId = new ShardId(index, 0); private final UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""); + private final ShardRouting.RecoveryPriority recoveryPriority = ShardRouting.RecoveryPriority.UNASSIGNED_NEW; private final ShardRouting newUnassignedPrimaryIndexOnly = ShardRouting.newUnassigned( shardId, true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, unassignedInfo, - ShardRouting.Role.INDEX_ONLY + ShardRouting.Role.INDEX_ONLY, + recoveryPriority ); private final ThreadPool threadPool = mock(ThreadPool.class); @@ -170,7 +172,8 @@ public void testDifferentShardIdReturnsNoResults() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, unassignedInfo, - ShardRouting.Role.INDEX_ONLY + ShardRouting.Role.INDEX_ONLY, + recoveryPriority ).initialize("index_node", null, randomNonNegativeLong()).moveToStarted(1); ShardRouting searchShard = createSearchOnlyShard(otherShardId, "search_node_1").moveToStarted(1); @@ -476,7 +479,8 @@ private ShardRouting createSearchOnlyShard(ShardId shardId, String nodeId) { false, RecoverySource.PeerRecoverySource.INSTANCE, unassignedInfo, - ShardRouting.Role.SEARCH_ONLY + ShardRouting.Role.SEARCH_ONLY, + recoveryPriority ).initialize(nodeId, null, randomNonNegativeLong()); } @@ -486,7 +490,8 @@ private ShardRouting createPrimaryShard(ShardId shardId) { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, unassignedInfo, - ShardRouting.Role.INDEX_ONLY + ShardRouting.Role.INDEX_ONLY, + recoveryPriority ).initialize("index_node", null, randomNonNegativeLong()).moveToStarted(1); } } diff --git a/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/snapshots/StatelessSnapshotShardContextFactoryTests.java b/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/snapshots/StatelessSnapshotShardContextFactoryTests.java index adfa593f71493..b286594ce8020 100644 --- a/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/snapshots/StatelessSnapshotShardContextFactoryTests.java +++ b/x-pack/plugin/stateless/src/test/java/org/elasticsearch/xpack/stateless/snapshots/StatelessSnapshotShardContextFactoryTests.java @@ -299,7 +299,8 @@ private static TestHarness createTestHarness(Settings settings) throws IOExcepti true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foobar"), - ShardRouting.Role.INDEX_ONLY + ShardRouting.Role.INDEX_ONLY, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ), nodeId ) diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/checkpoint/TransformsCheckpointServiceTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/checkpoint/TransformsCheckpointServiceTests.java index fb40cc0f6b49f..26f6fc8e3b722 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/checkpoint/TransformsCheckpointServiceTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/checkpoint/TransformsCheckpointServiceTests.java @@ -176,7 +176,8 @@ private static ShardStats[] createRandomShardStats( primary, primary ? RecoverySource.EmptyStoreRecoverySource.INSTANCE : PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node-0", null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java index 88f114d854657..740ff842211b2 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java @@ -371,7 +371,8 @@ public void testVerifyIndicesPrimaryShardsAreActive() { true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); routingTable.add( @@ -970,7 +971,8 @@ private void addIndices(Metadata.Builder metadata, RoutingTable.Builder routingT true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, ""), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize("node_id", null, 0L); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/ShardAllocationConfigurationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/ShardAllocationConfigurationTests.java index 9ff3551311f47..6449ee07aa788 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/ShardAllocationConfigurationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/ShardAllocationConfigurationTests.java @@ -211,7 +211,8 @@ public void testForLocalShardsIgnoresInactiveCopies() { false, RecoverySource.PeerRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "test"), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); final IndexRoutingTable indexRoutingTable = IndexRoutingTable.builder(index).addShard(primary).addShard(unassignedReplica).build(); diff --git a/x-pack/plugin/write-load-forecaster/src/internalClusterTest/java/org/elasticsearch/xpack/writeloadforecaster/ClusterInfoWriteLoadForecasterIT.java b/x-pack/plugin/write-load-forecaster/src/internalClusterTest/java/org/elasticsearch/xpack/writeloadforecaster/ClusterInfoWriteLoadForecasterIT.java index a1b170f9874f5..b1c276430d336 100644 --- a/x-pack/plugin/write-load-forecaster/src/internalClusterTest/java/org/elasticsearch/xpack/writeloadforecaster/ClusterInfoWriteLoadForecasterIT.java +++ b/x-pack/plugin/write-load-forecaster/src/internalClusterTest/java/org/elasticsearch/xpack/writeloadforecaster/ClusterInfoWriteLoadForecasterIT.java @@ -221,7 +221,8 @@ public static ShardStats createShardStats( true, RecoverySource.EmptyStoreRecoverySource.INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null), - ShardRouting.Role.DEFAULT + ShardRouting.Role.DEFAULT, + ShardRouting.RecoveryPriority.UNASSIGNED_NEW ); shardRouting = shardRouting.initialize(assignedShardNodeId, null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); shardRouting = shardRouting.moveToStarted(ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); From dd14a7f6238501b65dfc03a123b2e17e1fe6d8e2 Mon Sep 17 00:00:00 2001 From: Pete Gillin Date: Fri, 24 Jul 2026 21:24:19 +0100 Subject: [PATCH 2/3] partially do relocations --- .../cluster/ClusterInfoSimulator.java | 4 +++- .../cluster/routing/ShardRouting.java | 14 +++++++++++--- .../allocator/BalancedShardsAllocator.java | 2 +- .../decider/ThrottlingAllocationDecider.java | 17 ++++++++++------- .../cluster/routing/ShardRoutingTests.java | 2 +- .../cluster/routing/ShardRoutingHelper.java | 13 ++++++++++--- ...ngConcurrentRecoveriesAllocationDecider.java | 4 ++-- 7 files changed, 38 insertions(+), 18 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterInfoSimulator.java b/server/src/main/java/org/elasticsearch/cluster/ClusterInfoSimulator.java index ea6ed7b69386f..2cb80685016f9 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterInfoSimulator.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterInfoSimulator.java @@ -173,10 +173,12 @@ public void simulateAlreadyStartedShard(ShardRouting startedShard, @Nullable Str } final long expectedShardSize = startedShard.getExpectedShardSize(); if (sourceNodeId != null) { + // Use an arbitrary recovery priority, it does not affect the simulation: + ShardRouting.RecoveryPriority recoveryPriority = ShardRouting.RecoveryPriority.RELOCATE_REBALANCING; final var relocatingShard = startedShard.moveToUnassigned(new UnassignedInfo(REINITIALIZED, "simulation")) .initialize(sourceNodeId, null, expectedShardSize) .moveToStarted(expectedShardSize) - .relocate(startedShard.currentNodeId(), expectedShardSize) + .relocate(startedShard.currentNodeId(), expectedShardSize, recoveryPriority) .getTargetRelocatingShard(); simulateShardStarted(relocatingShard, false); } else { diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java b/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java index b96e862951b6e..11a7a47bf5f00 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java @@ -591,7 +591,17 @@ public ShardRouting initialize(String nodeId, @Nullable String existingAllocatio * * @param relocatingNodeId id of the node to relocate the shard */ + @Deprecated public ShardRouting relocate(String relocatingNodeId, long expectedShardSize) { + return relocate(relocatingNodeId, expectedShardSize, RecoveryPriority.RELOCATION_CAN_REMAIN_NO); + } + + /** + * Relocate the shard to another node. + * + * @param relocatingNodeId id of the node to relocate the shard + */ + public ShardRouting relocate(String relocatingNodeId, long expectedShardSize, RecoveryPriority recoveryPriority) { assert state == ShardRoutingState.STARTED : "current shard has to be started in order to be relocated " + this; return new ShardRouting( shardId, @@ -600,9 +610,7 @@ public ShardRouting relocate(String relocatingNodeId, long expectedShardSize) { primary, ShardRoutingState.RELOCATING, recoverySource, - // TODO: Populate this with the correct priority. For now, we use the highest of the three choices for a relocation. - // As long as master-side recovery throttling is in effect, the priority is not that important. - RecoveryPriority.RELOCATION_CAN_REMAIN_NO, + recoveryPriority, null, relocationFailureInfo, AllocationId.newRelocation(allocationId), diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java index 1dd90a777b116..897ae24256c2d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java @@ -1667,7 +1667,7 @@ private boolean tryRelocateShard(ModelNode minNode, ModelNode maxNode, ProjectIn canAllocateOrRebalance == Type.YES /* only allocate on the cluster if we are not throttled */ ? routingNodes.relocateShard(shard, minNode.getNodeId(), shardSize, REBALANCE_REASON, allocation.changes()).v1() - : shard.relocate(minNode.getNodeId(), shardSize) + : shard.relocate(minNode.getNodeId(), shardSize, ShardRouting.RecoveryPriority.RELOCATE_REBALANCING) ); return true; } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java index 6774234c6c6bd..1f99c530513eb 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java @@ -130,7 +130,7 @@ private void setPrimariesInitialRecoveries(int primariesInitialRecoveries) { public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (shardRouting.primary() && shardRouting.unassigned()) { // Primary is unassigned, means we are going to do recovery from store, snapshot or local shards - assert initializingShard(shardRouting, node.nodeId()).recoverySource().getType() != RecoverySource.Type.PEER; + assert initializingShardRecoverySourceType(shardRouting, node.nodeId()) != RecoverySource.Type.PEER; if (allocation.isSimulating()) { return allocation.decision(Decision.YES, NAME, "primary allocation is not throttled when simulating"); @@ -170,7 +170,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing return allocation.decision(Decision.YES, NAME, "replica allocation is not throttled when simulating"); } else { // Peer recovery - assert initializingShard(shardRouting, node.nodeId()).recoverySource().getType() == RecoverySource.Type.PEER; + assert initializingShardRecoverySourceType(shardRouting, node.nodeId()) == RecoverySource.Type.PEER; // Allocating a shard to this node will increase the incoming recoveries int currentInRecoveries = allocation.routingNodes().getIncomingRecoveries(node.nodeId()); @@ -231,9 +231,9 @@ public Decision canForceAllocateDuringReplace(ShardRouting shardRouting, Routing * - the started shard routing in case if we want to check if we can relocate to this node. * - the relocating shard routing if we want to relocate to this node now instead. * - * This method returns the corresponding initializing shard that would be allocated to this node. + * This method returns the recovery source type of the corresponding initializing shard that would be allocated to this node. */ - public static ShardRouting initializingShard(ShardRouting shardRouting, String currentNodeId) { + public static RecoverySource.Type initializingShardRecoverySourceType(ShardRouting shardRouting, String currentNodeId) { final ShardRouting initializingShard; if (shardRouting.unassigned()) { initializingShard = shardRouting.initialize(currentNodeId, null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); @@ -247,14 +247,17 @@ public static ShardRouting initializingShard(ShardRouting shardRouting, String c .initialize(currentNodeId, null, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); } else if (shardRouting.relocating()) { initializingShard = shardRouting.cancelRelocation() - .relocate(currentNodeId, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE) + .relocate(currentNodeId, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE, shardRouting.recoveryPriority()) .getTargetRelocatingShard(); } else { assert shardRouting.started(); - initializingShard = shardRouting.relocate(currentNodeId, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE) + // Use an arbitrary recovery priority, it makes no difference to teh recovery source type: + ShardRouting.RecoveryPriority recoveryPriority = ShardRouting.RecoveryPriority.RELOCATION_CAN_REMAIN_NO; + initializingShard = shardRouting.relocate(currentNodeId, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE, recoveryPriority) .getTargetRelocatingShard(); } assert initializingShard.initializing(); - return initializingShard; + assert initializingShard.recoverySource() != null; + return initializingShard.recoverySource().getType(); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/ShardRoutingTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/ShardRoutingTests.java index 22d9ac426ed3e..213f441186ff7 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/ShardRoutingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/ShardRoutingTests.java @@ -475,7 +475,7 @@ public void testExpectedSize() throws IOException { if (routing.unassigned()) { routing = ShardRoutingHelper.initialize(routing, "foo", byteSize); } else if (routing.started()) { - routing = ShardRoutingHelper.relocate(routing, "foo", byteSize); + routing = ShardRoutingHelper.relocate(routing, "foo", byteSize, ShardRouting.RecoveryPriority.RELOCATE_REBALANCING); } else { byteSize = -1; } diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/routing/ShardRoutingHelper.java b/test/framework/src/main/java/org/elasticsearch/cluster/routing/ShardRoutingHelper.java index ad0516d20e2bf..bbb800e921e25 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/routing/ShardRoutingHelper.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/routing/ShardRoutingHelper.java @@ -16,12 +16,19 @@ */ public class ShardRoutingHelper { + /// Shorthand for [#relocate(ShardRouting, String, long, ShardRouting.RecoveryPriority)] using a shard size of + /// [ShardRouting#UNAVAILABLE_EXPECTED_SHARD_SIZE] and a recovery priority of [ShardRouting.RecoveryPriority#RELOCATE_REBALANCING]. public static ShardRouting relocate(ShardRouting routing, String nodeId) { - return relocate(routing, nodeId, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE); + return routing.relocate(nodeId, ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE, ShardRouting.RecoveryPriority.RELOCATE_REBALANCING); } - public static ShardRouting relocate(ShardRouting routing, String nodeId, long expectedByteSize) { - return routing.relocate(nodeId, expectedByteSize); + public static ShardRouting relocate( + ShardRouting routing, + String nodeId, + long expectedByteSize, + ShardRouting.RecoveryPriority recoveryPriority + ) { + return routing.relocate(nodeId, expectedByteSize, recoveryPriority); } public static ShardRouting moveToStarted(ShardRouting routing) { diff --git a/x-pack/plugin/stateless/src/main/java/org/elasticsearch/xpack/stateless/allocation/StatelessThrottlingConcurrentRecoveriesAllocationDecider.java b/x-pack/plugin/stateless/src/main/java/org/elasticsearch/xpack/stateless/allocation/StatelessThrottlingConcurrentRecoveriesAllocationDecider.java index d8221ddde76c3..17b5b96a51013 100644 --- a/x-pack/plugin/stateless/src/main/java/org/elasticsearch/xpack/stateless/allocation/StatelessThrottlingConcurrentRecoveriesAllocationDecider.java +++ b/x-pack/plugin/stateless/src/main/java/org/elasticsearch/xpack/stateless/allocation/StatelessThrottlingConcurrentRecoveriesAllocationDecider.java @@ -20,7 +20,7 @@ import static java.lang.Math.max; import static java.lang.Math.round; import static org.elasticsearch.cluster.routing.allocation.decider.Decision.THROTTLE; -import static org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider.initializingShard; +import static org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider.initializingShardRecoverySourceType; /** * This allocation decider limits the number of concurrent relocation of indexing shards depending on the node's heap size. On small @@ -60,7 +60,7 @@ public StatelessThrottlingConcurrentRecoveriesAllocationDecider(ClusterSettings public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { if (shardRouting.isPromotableToPrimary() && shardRouting.unassigned() == false) { // Peer recovery - assert initializingShard(shardRouting, node.nodeId()).recoverySource().getType() == RecoverySource.Type.PEER; + assert initializingShardRecoverySourceType(shardRouting, node.nodeId()) == RecoverySource.Type.PEER; int currentInRecoveries = allocation.routingNodes().getIncomingRecoveries(node.nodeId()); ByteSizeValue heapSize = allocation.clusterInfo().getMaxHeapSizePerNode().get(node.nodeId()); if (currentInRecoveries > 0) { From 20e03057d0092c0fcbd53afd373ddd658c118002 Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Fri, 24 Jul 2026 20:36:02 +0000 Subject: [PATCH 3/3] [CI] Auto commit changes from spotless --- .../xpack/esql/enrich/StreamingLookupFromIndexOperatorTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/enrich/StreamingLookupFromIndexOperatorTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/enrich/StreamingLookupFromIndexOperatorTests.java index 3c941d3c7436f..8d2c025599883 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/enrich/StreamingLookupFromIndexOperatorTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/enrich/StreamingLookupFromIndexOperatorTests.java @@ -26,7 +26,6 @@ import org.elasticsearch.cluster.routing.GlobalRoutingTable; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; -import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo;