From 3e28ed5c3e0165ffd5cb1c2b7f84fe92e017f1dc Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Mon, 4 Jan 2021 12:18:51 +0100 Subject: [PATCH] Safer Refresh of Index Stats in CCR IT (#66830) We should only force merge after we know that an index is green and refresh after forcemerge to ensure we get the latest stats in any case. closes #64167 --- .../elasticsearch/xpack/ccr/CcrRepositoryIT.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java index cb734380ca1d6..e9192511c379b 100644 --- a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java +++ b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java @@ -14,7 +14,6 @@ import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; -import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse; import org.elasticsearch.action.admin.indices.stats.IndexStats; import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction; import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest; @@ -78,6 +77,7 @@ import static java.util.Collections.singletonMap; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.Matchers.aMapWithSize; import static org.hamcrest.Matchers.equalTo; @@ -491,13 +491,12 @@ public void testCcrRepositoryFetchesSnapshotShardSizeFromIndexShardStoreStats() assertThat(bulkRequest.get().hasFailures(), is(false)); } - final ForceMergeResponse forceMergeResponse = leaderClient().admin().indices().prepareForceMerge(leaderIndex) - .setMaxNumSegments(1) - .setFlush(true) - .get(); - assertThat(forceMergeResponse.getSuccessfulShards(), equalTo(numberOfShards)); - assertThat(forceMergeResponse.getFailedShards(), equalTo(0)); ensureLeaderGreen(leaderIndex); + assertAllSuccessful(leaderClient().admin().indices().prepareForceMerge(leaderIndex) + .setMaxNumSegments(1) + .setFlush(true) + .get()); + refresh(leaderClient(), leaderIndex); final IndexStats indexStats = leaderClient().admin().indices().prepareStats(leaderIndex) .clear()