From 21fa7f6fc5c6aaff36eb3bfdd3ba6f111d32b3ba Mon Sep 17 00:00:00 2001 From: gmarouli Date: Fri, 4 Jul 2025 09:14:56 +0300 Subject: [PATCH 1/2] Use `isSearchable` instead of checking if a shard can be promoted. --- .../downsample/DownsampleShardPersistentTaskExecutor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/DownsampleShardPersistentTaskExecutor.java b/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/DownsampleShardPersistentTaskExecutor.java index ed9b34cf69421..5f91fb18fd58e 100644 --- a/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/DownsampleShardPersistentTaskExecutor.java +++ b/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/DownsampleShardPersistentTaskExecutor.java @@ -161,11 +161,10 @@ public PersistentTasksCustomMetadata.Assignment getAssignment( /** * Only shards that can be searched can be used as the source of a downsampling task. - * In stateless deployment, this means that shards that CANNOT be promoted to primary can be used. * For simplicity, in non-stateless deployments we use the primary shard. */ private boolean isEligible(ShardRouting shardRouting) { - return shardRouting.started() && (isStateless ? shardRouting.isPromotableToPrimary() == false : shardRouting.primary()); + return shardRouting.started() && (isStateless ? shardRouting.isSearchable() : shardRouting.primary()); } private boolean isCandidateNode(Collection candidateNodes, String nodeId) { From 5cb72c4a38f80c7a5717077bb8689e5ef043efe4 Mon Sep 17 00:00:00 2001 From: gmarouli Date: Fri, 4 Jul 2025 09:51:19 +0300 Subject: [PATCH 2/2] Update the test for the stateless scenario --- .../DownsampleShardPersistentTaskExecutorTests.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/DownsampleShardPersistentTaskExecutorTests.java b/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/DownsampleShardPersistentTaskExecutorTests.java index 3ef575efc4a8c..39e92f06ada16 100644 --- a/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/DownsampleShardPersistentTaskExecutorTests.java +++ b/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/DownsampleShardPersistentTaskExecutorTests.java @@ -144,16 +144,14 @@ public void testGetStatelessAssignment() { var searchNode = newNode(Set.of(DiscoveryNodeRole.SEARCH_ROLE)); var indexNode = newNode(Set.of(DiscoveryNodeRole.INDEX_ROLE)); var shardId = new ShardId(backingIndex, 0); + ShardRouting indexOnlyShard = shardRoutingBuilder(shardId, indexNode.getId(), true, STARTED).withRecoverySource(null) + .withRole(ShardRouting.Role.INDEX_ONLY) + .build(); var clusterState = ClusterState.builder(initialClusterState) .nodes(new DiscoveryNodes.Builder().add(indexNode).add(searchNode).build()) .putRoutingTable( projectId, - RoutingTable.builder() - .add( - IndexRoutingTable.builder(backingIndex) - .addShard(shardRoutingBuilder(shardId, indexNode.getId(), true, STARTED).withRecoverySource(null).build()) - ) - .build() + RoutingTable.builder().add(IndexRoutingTable.builder(backingIndex).addShard(indexOnlyShard)).build() ) .build(); @@ -177,7 +175,7 @@ public void testGetStatelessAssignment() { RoutingTable.builder() .add( IndexRoutingTable.builder(backingIndex) - .addShard(shardRoutingBuilder(shardId, indexNode.getId(), true, STARTED).withRecoverySource(null).build()) + .addShard(indexOnlyShard) .addShard( shardRoutingBuilder(shardId, searchNode.getId(), false, STARTED).withRecoverySource(null) .withRole(ShardRouting.Role.SEARCH_ONLY)