1919
2020package org .elasticsearch .action .admin .indices .create ;
2121
22- import org .apache .lucene .index .CorruptIndexException ;
2322import org .apache .lucene .search .Sort ;
2423import org .apache .lucene .search .SortField ;
2524import org .apache .lucene .search .SortedSetSelector ;
2928import org .elasticsearch .action .admin .cluster .state .ClusterStateRequest ;
3029import org .elasticsearch .action .admin .cluster .state .ClusterStateResponse ;
3130import org .elasticsearch .action .admin .indices .settings .get .GetSettingsResponse ;
31+ import org .elasticsearch .action .admin .indices .stats .IndicesStatsResponse ;
32+ import org .elasticsearch .action .admin .indices .stats .ShardStats ;
3233import org .elasticsearch .action .index .IndexRequest ;
3334import org .elasticsearch .action .support .ActiveShardCount ;
3435import org .elasticsearch .client .Client ;
3536import org .elasticsearch .cluster .ClusterInfoService ;
3637import org .elasticsearch .cluster .InternalClusterInfoService ;
3738import org .elasticsearch .cluster .metadata .IndexMetaData ;
3839import org .elasticsearch .cluster .node .DiscoveryNode ;
39- import org .elasticsearch .cluster .routing .IndexShardRoutingTable ;
4040import org .elasticsearch .cluster .routing .Murmur3HashFunction ;
4141import org .elasticsearch .cluster .routing .RoutingTable ;
42- import org .elasticsearch .cluster .routing .ShardRouting ;
4342import org .elasticsearch .cluster .routing .UnassignedInfo ;
4443import org .elasticsearch .common .Priority ;
4544import org .elasticsearch .common .collect .ImmutableOpenMap ;
4847import org .elasticsearch .index .Index ;
4948import org .elasticsearch .index .IndexService ;
5049import org .elasticsearch .index .query .TermsQueryBuilder ;
50+ import org .elasticsearch .index .seqno .SeqNoStats ;
5151import org .elasticsearch .index .shard .IndexShard ;
52- import org .elasticsearch .index .shard .ShardId ;
5352import org .elasticsearch .indices .IndicesService ;
5453import org .elasticsearch .plugins .Plugin ;
5554import org .elasticsearch .test .ESIntegTestCase ;
5857
5958import java .util .Arrays ;
6059import java .util .Collection ;
61- import java .util .HashSet ;
6260import java .util .List ;
63- import java .util .Set ;
64- import java .util .stream .Collectors ;
6561import java .util .stream .IntStream ;
6662
6763import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
6864import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertHitCount ;
69- import static org .hamcrest .CoreMatchers .not ;
7065import static org .hamcrest .Matchers .containsString ;
7166import static org .hamcrest .Matchers .equalTo ;
7267import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
@@ -233,7 +228,8 @@ public void testCreateShrinkIndex() {
233228 .put ("number_of_shards" , randomIntBetween (2 , 7 ))
234229 .put ("index.version.created" , version )
235230 ).get ();
236- for (int i = 0 ; i < 20 ; i ++) {
231+ final int docs = randomIntBetween (0 , 128 );
232+ for (int i = 0 ; i < docs ; i ++) {
237233 client ().prepareIndex ("source" , "type" )
238234 .setSource ("{\" foo\" : \" bar\" , \" i\" : " + i + "}" , XContentType .JSON ).get ();
239235 }
@@ -252,30 +248,43 @@ public void testCreateShrinkIndex() {
252248 .put ("index.routing.allocation.require._name" , mergeNode )
253249 .put ("index.blocks.write" , true )).get ();
254250 ensureGreen ();
251+
252+ final IndicesStatsResponse sourceStats = client ().admin ().indices ().prepareStats ("source" ).get ();
253+ final long maxSeqNo =
254+ Arrays .stream (sourceStats .getShards ()).map (ShardStats ::getSeqNoStats ).mapToLong (SeqNoStats ::getMaxSeqNo ).max ().getAsLong ();
255255 // now merge source into a single shard index
256256
257257 final boolean createWithReplicas = randomBoolean ();
258258 assertAcked (client ().admin ().indices ().prepareShrinkIndex ("source" , "target" )
259259 .setSettings (Settings .builder ().put ("index.number_of_replicas" , createWithReplicas ? 1 : 0 ).build ()).get ());
260260 ensureGreen ();
261- assertHitCount (client ().prepareSearch ("target" ).setSize (100 ).setQuery (new TermsQueryBuilder ("foo" , "bar" )).get (), 20 );
261+
262+ final IndicesStatsResponse targetStats = client ().admin ().indices ().prepareStats ("target" ).get ();
263+ for (final ShardStats shardStats : targetStats .getShards ()) {
264+ final SeqNoStats seqNoStats = shardStats .getSeqNoStats ();
265+ assertThat (seqNoStats .getMaxSeqNo (), equalTo (maxSeqNo ));
266+ assertThat (seqNoStats .getLocalCheckpoint (), equalTo (maxSeqNo ));
267+ }
268+
269+ final int size = docs > 0 ? 2 * docs : 1 ;
270+ assertHitCount (client ().prepareSearch ("target" ).setSize (size ).setQuery (new TermsQueryBuilder ("foo" , "bar" )).get (), docs );
262271
263272 if (createWithReplicas == false ) {
264273 // bump replicas
265274 client ().admin ().indices ().prepareUpdateSettings ("target" )
266275 .setSettings (Settings .builder ()
267276 .put ("index.number_of_replicas" , 1 )).get ();
268277 ensureGreen ();
269- assertHitCount (client ().prepareSearch ("target" ).setSize (100 ).setQuery (new TermsQueryBuilder ("foo" , "bar" )).get (), 20 );
278+ assertHitCount (client ().prepareSearch ("target" ).setSize (size ).setQuery (new TermsQueryBuilder ("foo" , "bar" )).get (), docs );
270279 }
271280
272- for (int i = 20 ; i < 40 ; i ++) {
281+ for (int i = docs ; i < 2 * docs ; i ++) {
273282 client ().prepareIndex ("target" , "type" )
274283 .setSource ("{\" foo\" : \" bar\" , \" i\" : " + i + "}" , XContentType .JSON ).get ();
275284 }
276285 flushAndRefresh ();
277- assertHitCount (client ().prepareSearch ("target" ).setSize (100 ).setQuery (new TermsQueryBuilder ("foo" , "bar" )).get (), 40 );
278- assertHitCount (client ().prepareSearch ("source" ).setSize (100 ).setQuery (new TermsQueryBuilder ("foo" , "bar" )).get (), 20 );
286+ assertHitCount (client ().prepareSearch ("target" ).setSize (2 * size ).setQuery (new TermsQueryBuilder ("foo" , "bar" )).get (), 2 * docs );
287+ assertHitCount (client ().prepareSearch ("source" ).setSize (size ).setQuery (new TermsQueryBuilder ("foo" , "bar" )).get (), docs );
279288 GetSettingsResponse target = client ().admin ().indices ().prepareGetSettings ("target" ).get ();
280289 assertEquals (version , target .getIndexToSettings ().get ("target" ).getAsVersion ("index.version.created" , null ));
281290 }
0 commit comments