Skip to content

Commit

Permalink
Safer Refresh of Index Stats in CCR IT (elastic#66830)
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 Jan 4, 2021
1 parent 4e0f7bb commit 3e28ed5
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 @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3e28ed5

Please sign in to comment.