Skip to content

Fix flaky test SegmentReplicationIT.testReplicaAlreadyAtCheckpoint #17216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1892,26 +1892,38 @@ public void testReplicaAlreadyAtCheckpoint() throws Exception {
// index a doc.
client().prepareIndex(INDEX_NAME).setId("1").setSource("foo", randomInt()).get();
refresh(INDEX_NAME);
waitForSearchableDocs(1, primaryNode, replicaNode, replicaNode2);

internalCluster().stopRandomNode(InternalTestCluster.nameFilter(primaryNode));
ensureYellowAndNoInitializingShards(INDEX_NAME);
IndexShard replica_1 = getIndexShard(replicaNode, INDEX_NAME);
IndexShard replica_2 = getIndexShard(replicaNode2, INDEX_NAME);
AtomicReference<IndexShard> replica_1 = new AtomicReference<>();
AtomicReference<IndexShard> replica_2 = new AtomicReference<>();
// wait until a replica is promoted & finishes engine flip, we don't care which one
AtomicReference<IndexShard> primary = new AtomicReference<>();
assertBusy(() -> {
assertTrue("replica should be promoted as a primary", replica_1.routingEntry().primary() || replica_2.routingEntry().primary());
primary.set(replica_1.routingEntry().primary() ? replica_1 : replica_2);
});
IndexShard replicaShard1 = getIndexShard(replicaNode, INDEX_NAME);
IndexShard replicaShard2 = getIndexShard(replicaNode2, INDEX_NAME);

assertNotNull("Replica shard 1 should not be null", replicaShard1);
assertNotNull("Replica shard 2 should not be null", replicaShard2);

replica_1.set(replicaShard1);
replica_2.set(replicaShard2);
assertTrue(
"replica should be promoted as a primary",
replica_1.get().routingEntry().primary() || replica_2.get().routingEntry().primary()
);
primary.set(replica_1.get().routingEntry().primary() ? replica_1.get() : replica_2.get());
}, 60, TimeUnit.SECONDS);

FlushRequest request = new FlushRequest(INDEX_NAME);
request.force(true);
primary.get().flush(request);

assertBusy(() -> {
assertEquals(
replica_1.getLatestReplicationCheckpoint().getSegmentInfosVersion(),
replica_2.getLatestReplicationCheckpoint().getSegmentInfosVersion()
replica_1.get().getLatestReplicationCheckpoint().getSegmentInfosVersion(),
replica_2.get().getLatestReplicationCheckpoint().getSegmentInfosVersion()
);
});

Expand Down
Loading