19
19
20
20
package org .elasticsearch .action .admin .indices .create ;
21
21
22
- import org .apache .lucene .index .CorruptIndexException ;
23
22
import org .apache .lucene .search .Sort ;
24
23
import org .apache .lucene .search .SortField ;
25
24
import org .apache .lucene .search .SortedSetSelector ;
29
28
import org .elasticsearch .action .admin .cluster .state .ClusterStateRequest ;
30
29
import org .elasticsearch .action .admin .cluster .state .ClusterStateResponse ;
31
30
import 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 ;
32
33
import org .elasticsearch .action .index .IndexRequest ;
33
34
import org .elasticsearch .action .support .ActiveShardCount ;
34
35
import org .elasticsearch .client .Client ;
35
36
import org .elasticsearch .cluster .ClusterInfoService ;
36
37
import org .elasticsearch .cluster .InternalClusterInfoService ;
37
38
import org .elasticsearch .cluster .metadata .IndexMetaData ;
38
39
import org .elasticsearch .cluster .node .DiscoveryNode ;
39
- import org .elasticsearch .cluster .routing .IndexShardRoutingTable ;
40
40
import org .elasticsearch .cluster .routing .Murmur3HashFunction ;
41
41
import org .elasticsearch .cluster .routing .RoutingTable ;
42
- import org .elasticsearch .cluster .routing .ShardRouting ;
43
42
import org .elasticsearch .cluster .routing .UnassignedInfo ;
44
43
import org .elasticsearch .common .Priority ;
45
44
import org .elasticsearch .common .collect .ImmutableOpenMap ;
48
47
import org .elasticsearch .index .Index ;
49
48
import org .elasticsearch .index .IndexService ;
50
49
import org .elasticsearch .index .query .TermsQueryBuilder ;
50
+ import org .elasticsearch .index .seqno .SeqNoStats ;
51
51
import org .elasticsearch .index .shard .IndexShard ;
52
- import org .elasticsearch .index .shard .ShardId ;
53
52
import org .elasticsearch .indices .IndicesService ;
54
53
import org .elasticsearch .plugins .Plugin ;
55
54
import org .elasticsearch .test .ESIntegTestCase ;
58
57
59
58
import java .util .Arrays ;
60
59
import java .util .Collection ;
61
- import java .util .HashSet ;
62
60
import java .util .List ;
63
- import java .util .Set ;
64
- import java .util .stream .Collectors ;
65
61
import java .util .stream .IntStream ;
66
62
67
63
import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
68
64
import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertHitCount ;
69
- import static org .hamcrest .CoreMatchers .not ;
70
65
import static org .hamcrest .Matchers .containsString ;
71
66
import static org .hamcrest .Matchers .equalTo ;
72
67
import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
@@ -233,7 +228,8 @@ public void testCreateShrinkIndex() {
233
228
.put ("number_of_shards" , randomIntBetween (2 , 7 ))
234
229
.put ("index.version.created" , version )
235
230
).get ();
236
- for (int i = 0 ; i < 20 ; i ++) {
231
+ final int docs = randomIntBetween (0 , 128 );
232
+ for (int i = 0 ; i < docs ; i ++) {
237
233
client ().prepareIndex ("source" , "type" )
238
234
.setSource ("{\" foo\" : \" bar\" , \" i\" : " + i + "}" , XContentType .JSON ).get ();
239
235
}
@@ -252,30 +248,43 @@ public void testCreateShrinkIndex() {
252
248
.put ("index.routing.allocation.require._name" , mergeNode )
253
249
.put ("index.blocks.write" , true )).get ();
254
250
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 ();
255
255
// now merge source into a single shard index
256
256
257
257
final boolean createWithReplicas = randomBoolean ();
258
258
assertAcked (client ().admin ().indices ().prepareShrinkIndex ("source" , "target" )
259
259
.setSettings (Settings .builder ().put ("index.number_of_replicas" , createWithReplicas ? 1 : 0 ).build ()).get ());
260
260
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 );
262
271
263
272
if (createWithReplicas == false ) {
264
273
// bump replicas
265
274
client ().admin ().indices ().prepareUpdateSettings ("target" )
266
275
.setSettings (Settings .builder ()
267
276
.put ("index.number_of_replicas" , 1 )).get ();
268
277
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 );
270
279
}
271
280
272
- for (int i = 20 ; i < 40 ; i ++) {
281
+ for (int i = docs ; i < 2 * docs ; i ++) {
273
282
client ().prepareIndex ("target" , "type" )
274
283
.setSource ("{\" foo\" : \" bar\" , \" i\" : " + i + "}" , XContentType .JSON ).get ();
275
284
}
276
285
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 );
279
288
GetSettingsResponse target = client ().admin ().indices ().prepareGetSettings ("target" ).get ();
280
289
assertEquals (version , target .getIndexToSettings ().get ("target" ).getAsVersion ("index.version.created" , null ));
281
290
}
0 commit comments