|
23 | 23 | import org.elasticsearch.action.DocWriteResponse; |
24 | 24 | import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; |
25 | 25 | import org.elasticsearch.action.admin.indices.shards.IndicesShardStoresResponse; |
26 | | -import org.elasticsearch.action.admin.indices.stats.ShardStats; |
27 | 26 | import org.elasticsearch.action.bulk.BulkResponse; |
28 | 27 | import org.elasticsearch.action.index.IndexResponse; |
29 | 28 | import org.elasticsearch.action.support.ActiveShardCount; |
30 | | -import org.elasticsearch.action.support.IndicesOptions; |
31 | 29 | import org.elasticsearch.cluster.ClusterState; |
32 | 30 | import org.elasticsearch.cluster.ClusterStateListener; |
33 | 31 | import org.elasticsearch.cluster.metadata.IndexMetaData; |
|
67 | 65 | import java.util.concurrent.ExecutionException; |
68 | 66 | import java.util.concurrent.TimeUnit; |
69 | 67 | import java.util.stream.Collectors; |
70 | | -import java.util.stream.Stream; |
71 | 68 |
|
72 | 69 | import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; |
73 | 70 | import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; |
@@ -231,9 +228,7 @@ public void testForceStaleReplicaToBePromotedToPrimary() throws Exception { |
231 | 228 | Set<String> historyUUIDs = Arrays.stream(client().admin().indices().prepareStats("test").clear().get().getShards()) |
232 | 229 | .map(shard -> shard.getCommitStats().getUserData().get(Engine.HISTORY_UUID_KEY)).collect(Collectors.toSet()); |
233 | 230 | createStaleReplicaScenario(master); |
234 | | - if (randomBoolean()) { |
235 | | - assertAcked(client().admin().indices().prepareClose("test").setWaitForActiveShards(0)); |
236 | | - } |
| 231 | + |
237 | 232 | boolean useStaleReplica = randomBoolean(); // if true, use stale replica, otherwise a completely empty copy |
238 | 233 | logger.info("--> explicitly promote old primary shard"); |
239 | 234 | final String idxName = "test"; |
@@ -283,18 +278,15 @@ public void testForceStaleReplicaToBePromotedToPrimary() throws Exception { |
283 | 278 | assertBusy(() -> assertTrue(client().admin().cluster().prepareState().get() |
284 | 279 | .getState().routingTable().index(idxName).allPrimaryShardsActive())); |
285 | 280 | } |
286 | | - ShardStats[] shardStats = client().admin().indices().prepareStats("test") |
287 | | - .setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED).get().getShards(); |
288 | | - for (ShardStats shardStat : shardStats) { |
289 | | - assertThat(shardStat.getCommitStats().getNumDocs(), equalTo(useStaleReplica ? 1 : 0)); |
290 | | - } |
| 281 | + assertHitCount(client().prepareSearch(idxName).setSize(0).setQuery(matchAllQuery()).get(), useStaleReplica ? 1L : 0L); |
| 282 | + |
291 | 283 | // allocation id of old primary was cleaned from the in-sync set |
292 | 284 | final ClusterState state = client().admin().cluster().prepareState().get().getState(); |
293 | 285 |
|
294 | 286 | assertEquals(Collections.singleton(state.routingTable().index(idxName).shard(0).primary.allocationId().getId()), |
295 | 287 | state.metaData().index(idxName).inSyncAllocationIds(0)); |
296 | 288 |
|
297 | | - Set<String> newHistoryUUIds = Stream.of(shardStats) |
| 289 | + Set<String> newHistoryUUIds = Arrays.stream(client().admin().indices().prepareStats("test").clear().get().getShards()) |
298 | 290 | .map(shard -> shard.getCommitStats().getUserData().get(Engine.HISTORY_UUID_KEY)).collect(Collectors.toSet()); |
299 | 291 | assertThat(newHistoryUUIds, everyItem(not(isIn(historyUUIDs)))); |
300 | 292 | assertThat(newHistoryUUIds, hasSize(1)); |
|
0 commit comments