Skip to content

Commit b85b32a

Browse files
authored
Fix FieldCapabilitiesIT#testRelocation (#125233)
We should not try to relocate initializing shards. This change disables rebalancing and ensures all shards to be relocated are ready. Closes #124227
1 parent 582fcaf commit b85b32a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

muted-tests.yml

-3
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,6 @@ tests:
285285
- class: org.elasticsearch.smoketest.MlWithSecurityIT
286286
method: test {yaml=ml/start_data_frame_analytics/Test start classification analysis when the dependent variable is missing}
287287
issue: https://github.com/elastic/elasticsearch/issues/124168
288-
- class: org.elasticsearch.search.fieldcaps.FieldCapabilitiesIT
289-
method: testRelocation
290-
issue: https://github.com/elastic/elasticsearch/issues/124227
291288
- class: org.elasticsearch.smoketest.MlWithSecurityIT
292289
method: test {yaml=ml/3rd_party_deployment/Test start and stop multiple deployments}
293290
issue: https://github.com/elastic/elasticsearch/issues/124315

server/src/internalClusterTest/java/org/elasticsearch/search/fieldcaps/FieldCapabilitiesIT.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import java.util.concurrent.atomic.AtomicBoolean;
8585
import java.util.function.Consumer;
8686
import java.util.function.Function;
87+
import java.util.function.Predicate;
8788
import java.util.stream.IntStream;
8889

8990
import static java.util.Collections.singletonList;
@@ -557,11 +558,14 @@ public void testNoActiveCopy() throws Exception {
557558
}
558559
}
559560

560-
private void moveOrCloseShardsOnNodes(String nodeName) throws Exception {
561+
private void moveOrCloseShardsOnNodes(String nodeName, Predicate<String> indexName) throws Exception {
561562
final IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName);
562563
final ClusterState clusterState = clusterService().state();
563564
for (IndexService indexService : indicesService) {
564565
for (IndexShard indexShard : indexService) {
566+
if (indexName.test(indexShard.shardId().getIndexName()) == false) {
567+
continue;
568+
}
565569
if (randomBoolean()) {
566570
closeShardNoCheck(indexShard, randomBoolean());
567571
} else if (randomBoolean()) {
@@ -603,13 +607,21 @@ private void moveOrCloseShardsOnNodes(String nodeName) throws Exception {
603607

604608
public void testRelocation() throws Exception {
605609
populateTimeRangeIndices();
610+
assertAcked(
611+
client().admin()
612+
.indices()
613+
.prepareUpdateSettings("log-index-*")
614+
.setSettings(Settings.builder().put("index.routing.rebalance.enable", "none").build())
615+
.get()
616+
);
617+
ensureGreen("log-index-*");
606618
try {
607619
final AtomicBoolean relocated = new AtomicBoolean();
608620
for (String node : internalCluster().getNodeNames()) {
609621
MockTransportService.getInstance(node)
610622
.addRequestHandlingBehavior(TransportFieldCapabilitiesAction.ACTION_NODE_NAME, (handler, request, channel, task) -> {
611623
if (relocated.compareAndSet(false, true)) {
612-
moveOrCloseShardsOnNodes(node);
624+
moveOrCloseShardsOnNodes(node, indexName -> indexName.startsWith("log-index-"));
613625
}
614626
handler.messageReceived(request, channel, task);
615627
});

0 commit comments

Comments
 (0)