Skip to content

Commit b54eb5f

Browse files
Fixes testSnapshotShutdownProgressTracker (elastic#135415)
Reorders the test to avoid a race condition due to one snapshot thread becoming blocked Relates: 134620
1 parent f4bba36 commit b54eb5f

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

server/src/internalClusterTest/java/org/elasticsearch/snapshots/SnapshotShutdownIT.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ public void testSnapshotShutdownProgressTracker() throws Exception {
488488
final var otherNode = internalCluster().startDataOnlyNode();
489489
final var otherIndex = randomIdentifier();
490490
createIndexWithContent(otherIndex, indexSettings(numShards, 0).put(REQUIRE_NODE_NAME_SETTING, otherNode).build());
491+
indexAllShardsToAnEqualOrGreaterMinimumSize(otherIndex, ByteSizeValue.of(2, ByteSizeUnit.KB).getBytes());
491492
blockDataNode(repoName, otherNode);
492493

493494
final var nodeForRemoval = internalCluster().startDataOnlyNode(
@@ -498,6 +499,7 @@ public void testSnapshotShutdownProgressTracker() throws Exception {
498499
final var indexName = randomIdentifier();
499500
createIndexWithContent(indexName, indexSettings(numShards, 0).put(REQUIRE_NODE_NAME_SETTING, nodeForRemoval).build());
500501
indexAllShardsToAnEqualOrGreaterMinimumSize(indexName, ByteSizeValue.of(2, ByteSizeUnit.KB).getBytes());
502+
logger.info("---> nodeForRemovalId: " + nodeForRemovalId + ", numShards: " + numShards);
501503

502504
// Start the snapshot with blocking in place on the data node not to allow shard snapshots to finish yet.
503505
final var clusterService = internalCluster().getCurrentMasterNodeInstance(ClusterService.class);
@@ -507,7 +509,21 @@ public void testSnapshotShutdownProgressTracker() throws Exception {
507509

508510
waitForBlock(otherNode, repoName);
509511

510-
logger.info("---> nodeForRemovalId: " + nodeForRemovalId + ", numShards: " + numShards);
512+
// Block on the master when a shard snapshot request comes in, until we can verify that the Tracker saw the outgoing request.
513+
final CountDownLatch snapshotStatusUpdateLatch = new CountDownLatch(1);
514+
final var masterTransportService = MockTransportService.getInstance(internalCluster().getMasterName());
515+
masterTransportService.addRequestHandlingBehavior(
516+
SnapshotsService.UPDATE_SNAPSHOT_STATUS_ACTION_NAME,
517+
(handler, request, channel, task) -> masterTransportService.getThreadPool().generic().execute(() -> {
518+
safeAwait(snapshotStatusUpdateLatch);
519+
try {
520+
handler.messageReceived(request, channel, task);
521+
} catch (Exception e) {
522+
fail(e);
523+
}
524+
})
525+
);
526+
511527
mockLog.addExpectation(
512528
new MockLog.SeenEventExpectation(
513529
"SnapshotShutdownProgressTracker start log message",
@@ -553,21 +569,6 @@ public void testSnapshotShutdownProgressTracker() throws Exception {
553569
mockLog.awaitAllExpectationsMatched();
554570
resetMockLog();
555571

556-
// Block on the master when a shard snapshot request comes in, until we can verify that the Tracker saw the outgoing request.
557-
final CountDownLatch snapshotStatusUpdateLatch = new CountDownLatch(1);
558-
final var masterTransportService = MockTransportService.getInstance(internalCluster().getMasterName());
559-
masterTransportService.addRequestHandlingBehavior(
560-
SnapshotsService.UPDATE_SNAPSHOT_STATUS_ACTION_NAME,
561-
(handler, request, channel, task) -> masterTransportService.getThreadPool().generic().execute(() -> {
562-
safeAwait(snapshotStatusUpdateLatch);
563-
try {
564-
handler.messageReceived(request, channel, task);
565-
} catch (Exception e) {
566-
fail(e);
567-
}
568-
})
569-
);
570-
571572
mockLog.addExpectation(
572573
new MockLog.SeenEventExpectation(
573574
"SnapshotShutdownProgressTracker shard snapshot has paused log message",

0 commit comments

Comments
 (0)