Skip to content

Commit 487d835

Browse files
cbuescherdnhatn
andauthored
Fix FieldCapabilitiesIT#testRelocation (#125233) (#136366)
We should not try to relocate initializing shards. This change disables rebalancing and ensures all shards to be relocated are ready. Closes #124227 Co-authored-by: Nhat Nguyen <[email protected]>
1 parent 6f62ae3 commit 487d835

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import java.util.concurrent.atomic.AtomicBoolean;
8686
import java.util.function.Consumer;
8787
import java.util.function.Function;
88+
import java.util.function.Predicate;
8889
import java.util.stream.IntStream;
8990

9091
import static org.elasticsearch.action.support.ActionTestUtils.wrapAsRestResponseListener;
@@ -598,11 +599,14 @@ public void testNoActiveCopy() throws Exception {
598599
}
599600
}
600601

601-
private void moveOrCloseShardsOnNodes(String nodeName) throws Exception {
602+
private void moveOrCloseShardsOnNodes(String nodeName, Predicate<String> indexName) throws Exception {
602603
final IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName);
603604
final ClusterState clusterState = clusterService().state();
604605
for (IndexService indexService : indicesService) {
605606
for (IndexShard indexShard : indexService) {
607+
if (indexName.test(indexShard.shardId().getIndexName()) == false) {
608+
continue;
609+
}
606610
if (randomBoolean()) {
607611
closeShardNoCheck(indexShard, randomBoolean());
608612
} else if (randomBoolean()) {
@@ -644,13 +648,21 @@ private void moveOrCloseShardsOnNodes(String nodeName) throws Exception {
644648

645649
public void testRelocation() throws Exception {
646650
populateTimeRangeIndices();
651+
assertAcked(
652+
client().admin()
653+
.indices()
654+
.prepareUpdateSettings("log-index-*")
655+
.setSettings(Settings.builder().put("index.routing.rebalance.enable", "none").build())
656+
.get()
657+
);
658+
ensureGreen("log-index-*");
647659
try {
648660
final AtomicBoolean relocated = new AtomicBoolean();
649661
for (String node : internalCluster().getNodeNames()) {
650662
MockTransportService.getInstance(node)
651663
.addRequestHandlingBehavior(TransportFieldCapabilitiesAction.ACTION_NODE_NAME, (handler, request, channel, task) -> {
652664
if (relocated.compareAndSet(false, true)) {
653-
moveOrCloseShardsOnNodes(node);
665+
moveOrCloseShardsOnNodes(node, indexName -> indexName.startsWith("log-index-"));
654666
}
655667
handler.messageReceived(request, channel, task);
656668
});

0 commit comments

Comments
 (0)