45
45
import org .elasticsearch .cluster .routing .Murmur3HashFunction ;
46
46
import org .elasticsearch .cluster .routing .ShardRouting ;
47
47
import org .elasticsearch .cluster .routing .allocation .decider .EnableAllocationDecider ;
48
- import org .elasticsearch .common .collect .ImmutableOpenMap ;
49
48
import org .elasticsearch .common .settings .Settings ;
49
+ import org .elasticsearch .common .unit .TimeValue ;
50
50
import org .elasticsearch .common .xcontent .XContentType ;
51
51
import org .elasticsearch .index .Index ;
52
52
import org .elasticsearch .index .IndexService ;
62
62
import java .io .UncheckedIOException ;
63
63
import java .util .Arrays ;
64
64
import java .util .HashSet ;
65
- import java .util .List ;
66
65
import java .util .Set ;
67
66
import java .util .function .BiFunction ;
68
67
import java .util .stream .IntStream ;
75
74
import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertNoFailures ;
76
75
import static org .hamcrest .Matchers .containsString ;
77
76
import static org .hamcrest .Matchers .equalTo ;
78
- import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
79
77
80
78
public class SplitIndexIT extends ESIntegTestCase {
81
79
@@ -184,9 +182,6 @@ private void splitToN(int sourceShards, int firstSplitShards, int secondSplitSha
184
182
}
185
183
}
186
184
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 );
190
185
ensureYellow ();
191
186
client ().admin ().indices ().prepareUpdateSettings ("source" )
192
187
.setSettings (Settings .builder ()
@@ -287,19 +282,13 @@ public void assertAllUniqueDocs(SearchResponse response, int numDocs) {
287
282
}
288
283
289
284
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 ));
294
287
internalCluster ().ensureAtLeastNumDataNodes (2 );
295
288
prepareCreate ("source" ).setSettings (Settings .builder ().put (indexSettings ())
296
289
.put ("number_of_shards" , numberOfShards )
297
290
.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
303
292
304
293
// fail random primary shards to force primary terms to increase
305
294
final Index source = resolveIndex ("source" );
@@ -352,7 +341,7 @@ public void testSplitIndexPrimaryTerm() throws Exception {
352
341
.setResizeType (ResizeType .SPLIT )
353
342
.setSettings (splitSettings ).get ());
354
343
355
- ensureGreen ();
344
+ ensureGreen (TimeValue . timeValueSeconds ( 120 )); // needs more than the default to relocate many shards
356
345
357
346
final IndexMetaData aftersplitIndexMetaData = indexMetaData (client (), "target" );
358
347
for (int shardId = 0 ; shardId < numberOfTargetShards ; shardId ++) {
@@ -365,9 +354,7 @@ private static IndexMetaData indexMetaData(final Client client, final String ind
365
354
return clusterStateResponse .getState ().metaData ().index (index );
366
355
}
367
356
368
- public void testCreateSplitIndex () {
369
- internalCluster ().ensureAtLeastNumDataNodes (2 );
370
-
357
+ public void testCreateSplitIndex () throws Exception {
371
358
Version version = VersionUtils .randomIndexCompatibleVersion (random ());
372
359
prepareCreate ("source" ).setSettings (Settings .builder ().put (indexSettings ())
373
360
.put ("number_of_shards" , 1 )
@@ -378,9 +365,7 @@ public void testCreateSplitIndex() {
378
365
client ().prepareIndex ("source" , "type" )
379
366
.setSource ("{\" foo\" : \" bar\" , \" i\" : " + i + "}" , XContentType .JSON ).get ();
380
367
}
381
- ImmutableOpenMap <String , DiscoveryNode > dataNodes =
382
- client ().admin ().cluster ().prepareState ().get ().getState ().nodes ().getDataNodes ();
383
- assertTrue ("at least 2 nodes but was: " + dataNodes .size (), dataNodes .size () >= 2 );
368
+ internalCluster ().ensureAtLeastNumDataNodes (2 );
384
369
// ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node
385
370
// if we change the setting too quickly we will end up with one replica unassigned which can't be assigned anymore due
386
371
// to the require._name below.
@@ -486,9 +471,6 @@ public void testCreateSplitWithIndexSort() throws Exception {
486
471
client ().prepareIndex ("source" , "type" , Integer .toString (i ))
487
472
.setSource ("{\" foo\" : \" bar\" , \" id\" : " + i + "}" , XContentType .JSON ).get ();
488
473
}
489
- ImmutableOpenMap <String , DiscoveryNode > dataNodes = client ().admin ().cluster ().prepareState ().get ().getState ().nodes ()
490
- .getDataNodes ();
491
- assertTrue ("at least 2 nodes but was: " + dataNodes .size (), dataNodes .size () >= 2 );
492
474
// ensure all shards are allocated otherwise the ensure green below might not succeed since we require the merge node
493
475
// if we change the setting too quickly we will end up with one replica unassigned which can't be assigned anymore due
494
476
// to the require._name below.
0 commit comments