From 88c89f3729f1c57da2c815ec67c482daa66f1d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Fern=C3=A1ndez=20Casta=C3=B1o?= Date: Thu, 28 Oct 2021 13:03:44 +0200 Subject: [PATCH] Fix SnapshotBasedIndexRecoveryIT#testSeqNoBasedRecoveryIsUsedAfterPrimaryFailOver (#80002) Order RecoveryStates to ensure that we get the latest recovery state to assert that the peer recovery was successful. Closes #79455 Backport of #79469 --- .../indices/recovery/SnapshotBasedIndexRecoveryIT.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/SnapshotBasedIndexRecoveryIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/SnapshotBasedIndexRecoveryIT.java index 46fa7e184cc87..2fcfbc3db8ee8 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/SnapshotBasedIndexRecoveryIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/SnapshotBasedIndexRecoveryIT.java @@ -68,6 +68,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -812,7 +813,6 @@ public void testRecoveryConcurrentlyWithIndexing() throws Exception { assertDocumentsAreEqual(indexName, numDocs.get()); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/79455") public void testSeqNoBasedRecoveryIsUsedAfterPrimaryFailOver() throws Exception { List dataNodes = internalCluster().startDataOnlyNodes(3); String indexName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT); @@ -1373,8 +1373,10 @@ private RecoveryState getLatestPeerRecoveryStateForShard(String indexName, int s assertThat(indexRecoveries, notNullValue()); List peerRecoveries = indexRecoveries.stream() + .filter(recoveryState -> recoveryState.getStage() == RecoveryState.Stage.DONE) .filter(recoveryState -> recoveryState.getRecoverySource().equals(RecoverySource.PeerRecoverySource.INSTANCE)) .filter(recoveryState -> recoveryState.getShardId().getId() == shardId) + .sorted(Comparator.comparingLong(o -> o.getTimer().stopTime())) .collect(Collectors.toList()); assertThat(peerRecoveries, is(not(empty())));