Skip to content

Commit

Permalink
Address some CCR REST test case flakiness (elastic#38975)
Browse files Browse the repository at this point in the history
The CCR REST tests that rely on these assertions are flaky. They are
flaky since the introduction of recovery from the remote.

The underlying problem is this: these tests are making assertions about
the number of operations read by the shard following task. However, with
recovery from remote, we no longer have guarantees that the assumptions
these tests were relying on hold. Namely, these tests were assuming that
the only way that a document could land in the follower index is via the
shard following task. With recovery from remote, there is another way,
which is via the files that are copied over during the recovery
phase. Most of the time this will not be a problem because with the
small number of documents that we are indexing in these tests, it is
usally not the case that a flush would occur and so there would not be
any documents in the files copied over. However, a flush can occur any
time at which point all of the indexed documents could end up in a safe
commit and copied over during recovery from remote. This commit modifies
these assertions to ones that are not prone to this issue, yet still
validate the health of the follower shard.
  • Loading branch information
jasontedor authored Feb 15, 2019
1 parent 065fec0 commit 7342d5a
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;

public class ESCCRRestTestCase extends ESRestTestCase {
Expand Down Expand Up @@ -139,8 +140,9 @@ protected static void verifyCcrMonitoring(final String expectedLeaderIndex, fina
throw new AssertionError("error while searching", e);
}

int numberOfOperationsReceived = 0;
int numberOfOperationsIndexed = 0;
int followerMaxSeqNo = 0;
int followerMappingVersion = 0;
int followerSettingsVersion = 0;

List<?> hits = (List<?>) XContentMapValues.extractValue("hits.hits", response);
assertThat(hits.size(), greaterThanOrEqualTo(1));
Expand All @@ -153,16 +155,20 @@ protected static void verifyCcrMonitoring(final String expectedLeaderIndex, fina
final String followerIndex = (String) XContentMapValues.extractValue("_source.ccr_stats.follower_index", hit);
assertThat(followerIndex, equalTo(expectedFollowerIndex));

int foundNumberOfOperationsReceived =
(int) XContentMapValues.extractValue("_source.ccr_stats.operations_read", hit);
numberOfOperationsReceived = Math.max(numberOfOperationsReceived, foundNumberOfOperationsReceived);
int foundNumberOfOperationsIndexed =
(int) XContentMapValues.extractValue("_source.ccr_stats.operations_written", hit);
numberOfOperationsIndexed = Math.max(numberOfOperationsIndexed, foundNumberOfOperationsIndexed);
int foundFollowerMaxSeqNo =
(int) XContentMapValues.extractValue("_source.ccr_stats.follower_max_seq_no", hit);
followerMaxSeqNo = Math.max(followerMaxSeqNo, foundFollowerMaxSeqNo);
int foundFollowerMappingVersion =
(int) XContentMapValues.extractValue("_source.ccr_stats.follower_mapping_version", hit);
followerMappingVersion = Math.max(followerMappingVersion, foundFollowerMappingVersion);
int foundFollowerSettingsVersion =
(int) XContentMapValues.extractValue("_source.ccr_stats.follower_settings_version", hit);
followerSettingsVersion = Math.max(followerSettingsVersion, foundFollowerSettingsVersion);
}

assertThat(numberOfOperationsReceived, greaterThanOrEqualTo(1));
assertThat(numberOfOperationsIndexed, greaterThanOrEqualTo(1));
assertThat(followerMaxSeqNo, greaterThan(0));
assertThat(followerMappingVersion, greaterThan(0));
assertThat(followerSettingsVersion, greaterThan(0));
}

protected static void verifyAutoFollowMonitoring() throws IOException {
Expand Down

0 comments on commit 7342d5a

Please sign in to comment.