4545import org .elasticsearch .cluster .routing .Murmur3HashFunction ;
4646import org .elasticsearch .cluster .routing .ShardRouting ;
4747import org .elasticsearch .cluster .routing .allocation .decider .EnableAllocationDecider ;
48- import org .elasticsearch .common .collect .ImmutableOpenMap ;
4948import org .elasticsearch .common .settings .Settings ;
49+ import org .elasticsearch .common .unit .TimeValue ;
5050import org .elasticsearch .common .xcontent .XContentType ;
5151import org .elasticsearch .index .Index ;
5252import org .elasticsearch .index .IndexService ;
6262import java .io .UncheckedIOException ;
6363import java .util .Arrays ;
6464import java .util .HashSet ;
65- import java .util .List ;
6665import java .util .Set ;
6766import java .util .function .BiFunction ;
6867import java .util .stream .IntStream ;
7574import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertNoFailures ;
7675import static org .hamcrest .Matchers .containsString ;
7776import static org .hamcrest .Matchers .equalTo ;
78- import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
7977
8078public class SplitIndexIT extends ESIntegTestCase {
8179
@@ -184,9 +182,6 @@ private void splitToN(int sourceShards, int firstSplitShards, int secondSplitSha
184182 }
185183 }
186184
187- ImmutableOpenMap <String , DiscoveryNode > dataNodes = client ().admin ().cluster ().prepareState ().get ().getState ().nodes ()
188- .getDataNodes ();
189- assertTrue ("at least 2 nodes but was: " + dataNodes .size (), dataNodes .size () >= 2 );
190185 ensureYellow ();
191186 client ().admin ().indices ().prepareUpdateSettings ("source" )
192187 .setSettings (Settings .builder ()
@@ -287,19 +282,13 @@ public void assertAllUniqueDocs(SearchResponse response, int numDocs) {
287282 }
288283
289284 public void testSplitIndexPrimaryTerm () throws Exception {
290- final List <Integer > factors = Arrays .asList (1 , 2 , 4 , 8 );
291- final List <Integer > numberOfShardsFactors = randomSubsetOf (scaledRandomIntBetween (1 , factors .size ()), factors );
292- final int numberOfShards = randomSubsetOf (numberOfShardsFactors ).stream ().reduce (1 , (x , y ) -> x * y );
293- final int numberOfTargetShards = numberOfShardsFactors .stream ().reduce (2 , (x , y ) -> x * y );
285+ int numberOfTargetShards = randomIntBetween (2 , 20 );
286+ int numberOfShards = randomValueOtherThanMany (n -> numberOfTargetShards % n != 0 , () -> between (1 , numberOfTargetShards - 1 ));
294287 internalCluster ().ensureAtLeastNumDataNodes (2 );
295288 prepareCreate ("source" ).setSettings (Settings .builder ().put (indexSettings ())
296289 .put ("number_of_shards" , numberOfShards )
297290 .put ("index.number_of_routing_shards" , numberOfTargetShards )).get ();
298-
299- final ImmutableOpenMap <String , DiscoveryNode > dataNodes =
300- client ().admin ().cluster ().prepareState ().get ().getState ().nodes ().getDataNodes ();
301- assertThat (dataNodes .size (), greaterThanOrEqualTo (2 ));
302- ensureYellow ();
291+ ensureGreen (TimeValue .timeValueSeconds (120 )); // needs more than the default to allocate many shards
303292
304293 // fail random primary shards to force primary terms to increase
305294 final Index source = resolveIndex ("source" );
@@ -352,7 +341,7 @@ public void testSplitIndexPrimaryTerm() throws Exception {
352341 .setResizeType (ResizeType .SPLIT )
353342 .setSettings (splitSettings ).get ());
354343
355- ensureGreen ();
344+ ensureGreen (TimeValue . timeValueSeconds ( 120 )); // needs more than the default to relocate many shards
356345
357346 final IndexMetaData aftersplitIndexMetaData = indexMetaData (client (), "target" );
358347 for (int shardId = 0 ; shardId < numberOfTargetShards ; shardId ++) {
@@ -365,7 +354,7 @@ private static IndexMetaData indexMetaData(final Client client, final String ind
365354 return clusterStateResponse .getState ().metaData ().index (index );
366355 }
367356
368- public void testCreateSplitIndex () {
357+ public void testCreateSplitIndex () throws Exception {
369358 internalCluster ().ensureAtLeastNumDataNodes (2 );
370359 Version version = VersionUtils .randomVersionBetween (random (), Version .V_6_0_0_rc2 , Version .CURRENT );
371360 prepareCreate ("source" ).setSettings (Settings .builder ().put (indexSettings ())
@@ -377,9 +366,6 @@ public void testCreateSplitIndex() {
377366 client ().prepareIndex ("source" , "type" )
378367 .setSource ("{\" foo\" : \" bar\" , \" i\" : " + i + "}" , XContentType .JSON ).get ();
379368 }
380- ImmutableOpenMap <String , DiscoveryNode > dataNodes =
381- client ().admin ().cluster ().prepareState ().get ().getState ().nodes ().getDataNodes ();
382- assertTrue ("at least 2 nodes but was: " + dataNodes .size (), dataNodes .size () >= 2 );
383369 // ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node
384370 // if we change the setting too quickly we will end up with one replica unassigned which can't be assigned anymore due
385371 // to the require._name below.
@@ -485,9 +471,6 @@ public void testCreateSplitWithIndexSort() throws Exception {
485471 client ().prepareIndex ("source" , "type" , Integer .toString (i ))
486472 .setSource ("{\" foo\" : \" bar\" , \" id\" : " + i + "}" , XContentType .JSON ).get ();
487473 }
488- ImmutableOpenMap <String , DiscoveryNode > dataNodes = client ().admin ().cluster ().prepareState ().get ().getState ().nodes ()
489- .getDataNodes ();
490- assertTrue ("at least 2 nodes but was: " + dataNodes .size (), dataNodes .size () >= 2 );
491474 // ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node
492475 // if we change the setting too quickly we will end up with one replica unassigned which can't be assigned anymore due
493476 // to the require._name below.
0 commit comments