Skip to content

Commit 9505212

Browse files
committed
Increase timeout in testFollowIndexWithConcurrentMappingChanges (#60534)
The test failed because the leader was taking a lot of CPUs to process many mapping updates. This commit reduces the mapping updates, increases timeout, and adds more debug info. Closes #59832
1 parent e61c66c commit 9505212

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/CcrIntegTestCase.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.action.ActionListener;
1111
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
1212
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
13+
import org.elasticsearch.action.admin.cluster.node.hotthreads.NodeHotThreads;
1314
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksAction;
1415
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
1516
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
@@ -331,7 +332,7 @@ protected final ClusterHealthStatus ensureFollowerGreen(String... indices) {
331332

332333
protected final ClusterHealthStatus ensureFollowerGreen(boolean waitForNoInitializingShards, String... indices) {
333334
logger.info("ensure green follower indices {}", Arrays.toString(indices));
334-
return ensureColor(clusterGroup.followerCluster, ClusterHealthStatus.GREEN, TimeValue.timeValueSeconds(30),
335+
return ensureColor(clusterGroup.followerCluster, ClusterHealthStatus.GREEN, TimeValue.timeValueSeconds(60),
335336
waitForNoInitializingShards, indices);
336337
}
337338

@@ -353,10 +354,21 @@ private ClusterHealthStatus ensureColor(TestCluster testCluster,
353354

354355
ClusterHealthResponse actionGet = testCluster.client().admin().cluster().health(healthRequest).actionGet();
355356
if (actionGet.isTimedOut()) {
356-
logger.info("{} timed out, cluster state:\n{}\n{}",
357+
logger.info("{} timed out: " +
358+
"\nleader cluster state:\n{}" +
359+
"\nleader cluster hot threads:\n{}" +
360+
"\nleader cluster tasks:\n{}" +
361+
"\nfollower cluster state:\n{}" +
362+
"\nfollower cluster hot threads:\n{}" +
363+
"\nfollower cluster tasks:\n{}",
357364
method,
358-
testCluster.client().admin().cluster().prepareState().get().getState(),
359-
testCluster.client().admin().cluster().preparePendingClusterTasks().get());
365+
leaderClient().admin().cluster().prepareState().get().getState(),
366+
getHotThreads(leaderClient()),
367+
leaderClient().admin().cluster().preparePendingClusterTasks().get(),
368+
followerClient().admin().cluster().prepareState().get().getState(),
369+
getHotThreads(followerClient()),
370+
followerClient().admin().cluster().preparePendingClusterTasks().get()
371+
);
360372
fail("timed out waiting for " + color + " state");
361373
}
362374
assertThat("Expected at least " + clusterHealthStatus + " but got " + actionGet.getStatus(),
@@ -365,6 +377,11 @@ private ClusterHealthStatus ensureColor(TestCluster testCluster,
365377
return actionGet.getStatus();
366378
}
367379

380+
static String getHotThreads(Client client) {
381+
return client.admin().cluster().prepareNodesHotThreads().setThreads(99999).setIgnoreIdleThreads(false)
382+
.get().getNodes().stream().map(NodeHotThreads::getHotThreads).collect(Collectors.joining("\n"));
383+
}
384+
368385
protected final Index resolveLeaderIndex(String index) {
369386
GetIndexResponse getIndexResponse = leaderClient().admin().indices().prepareGetIndex().setIndices(index).get();
370387
assertTrue("index " + index + " not found", getIndexResponse.getSettings().containsKey(index));

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -242,38 +242,23 @@ public void testFollowIndexWithConcurrentMappingChanges() throws Exception {
242242
final int firstBatchNumDocs = randomIntBetween(2, 64);
243243
logger.info("Indexing [{}] docs as first batch", firstBatchNumDocs);
244244
for (int i = 0; i < firstBatchNumDocs; i++) {
245-
final String source = String.format(Locale.ROOT, "{\"f\":%d}", i);
246-
leaderClient().prepareIndex("index1", "doc", Integer.toString(i)).setSource(source, XContentType.JSON).get();
245+
leaderClient().prepareIndex("index1", "_doc").setId(Integer.toString(i)).setSource("f", i).get();
247246
}
248247

249248
AtomicBoolean isRunning = new AtomicBoolean(true);
250249

251250
// Concurrently index new docs with mapping changes
251+
int numFields = between(10, 20);
252252
Thread thread = new Thread(() -> {
253-
int docID = 10000;
254-
char[] chars = "abcdeghijklmnopqrstuvwxyz".toCharArray();
255-
for (char c : chars) {
253+
int numDocs = between(10, 200);
254+
for (int i = 0; i < numDocs; i++) {
256255
if (isRunning.get() == false) {
257256
break;
258257
}
259-
final String source;
260-
long valueToPutInDoc = randomLongBetween(0, 50000);
261-
if (randomBoolean()) {
262-
source = String.format(Locale.ROOT, "{\"%c\":%d}", c, valueToPutInDoc);
263-
} else {
264-
source = String.format(Locale.ROOT, "{\"%c\":\"%d\"}", c, valueToPutInDoc);
265-
}
266-
for (int i = 1; i < 10; i++) {
267-
if (isRunning.get() == false) {
268-
break;
269-
}
270-
leaderClient().prepareIndex("index1", "doc", Long.toString(docID++)).setSource(source, XContentType.JSON).get();
271-
if (rarely()) {
272-
leaderClient().admin().indices().prepareFlush("index1").setForce(true).get();
273-
}
274-
}
275-
if (between(0, 100) < 20) {
276-
leaderClient().admin().indices().prepareFlush("index1").setForce(false).setWaitIfOngoing(false).get();
258+
final String field = "f-" + between(1, numFields);
259+
leaderClient().prepareIndex("index1", "_doc").setSource(field, between(0, 1000)).get();
260+
if (rarely()) {
261+
leaderClient().admin().indices().prepareFlush("index1").setWaitIfOngoing(false).setForce(false).get();
277262
}
278263
}
279264
});
@@ -291,16 +276,14 @@ public void testFollowIndexWithConcurrentMappingChanges() throws Exception {
291276
final int secondBatchNumDocs = randomIntBetween(2, 64);
292277
logger.info("Indexing [{}] docs as second batch", secondBatchNumDocs);
293278
for (int i = firstBatchNumDocs; i < firstBatchNumDocs + secondBatchNumDocs; i++) {
294-
final String source = String.format(Locale.ROOT, "{\"f\":%d}", i);
295-
leaderClient().prepareIndex("index1", "doc", Integer.toString(i)).setSource(source, XContentType.JSON).get();
279+
leaderClient().prepareIndex("index1", "_doc").setId(Integer.toString(i)).setSource("f", i).get();
296280
}
297-
298-
for (int i = firstBatchNumDocs; i < firstBatchNumDocs + secondBatchNumDocs; i++) {
281+
for (int i = 0; i < firstBatchNumDocs + secondBatchNumDocs; i++) {
299282
assertBusy(assertExpectedDocumentRunnable(i), 1, TimeUnit.MINUTES);
300283
}
301-
302284
isRunning.set(false);
303285
thread.join();
286+
assertIndexFullyReplicatedToFollower("index1", "index2");
304287
}
305288

306289
public void testFollowIndexWithoutWaitForComplete() throws Exception {

0 commit comments

Comments
 (0)