Skip to content

Commit

Permalink
Safer Refresh of Index Stats in CCR IT
Browse files Browse the repository at this point in the history
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 elastic#64167
  • Loading branch information
original-brownbear committed Dec 28, 2020
1 parent 820a813 commit bd61dbc
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,6 +76,7 @@
import java.util.stream.Collectors;

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;
Expand Down Expand Up @@ -489,13 +489,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()
Expand Down

0 comments on commit bd61dbc

Please sign in to comment.