@@ -568,50 +568,61 @@ public void testNonThrottleStats() throws Exception {
568
568
569
569
public void testThrottleStats () throws Exception {
570
570
assertAcked (
571
- prepareCreate ("test " ).setSettings (
571
+ prepareCreate ("test_throttle_stats_index " ).setSettings (
572
572
settingsBuilder ().put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , "1" )
573
573
.put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , "0" )
574
574
.put (MergePolicyConfig .INDEX_MERGE_POLICY_MAX_MERGE_AT_ONCE_SETTING .getKey (), "2" )
575
575
.put (MergePolicyConfig .INDEX_MERGE_POLICY_SEGMENTS_PER_TIER_SETTING .getKey (), "2" )
576
576
.put (MergeSchedulerConfig .MAX_THREAD_COUNT_SETTING .getKey (), "1" )
577
577
.put (MergeSchedulerConfig .MAX_MERGE_COUNT_SETTING .getKey (), "1" )
578
+ .put (MergeSchedulerConfig .AUTO_THROTTLE_SETTING .getKey (), "true" )
578
579
.put (IndexSettings .INDEX_TRANSLOG_DURABILITY_SETTING .getKey (), Translog .Durability .ASYNC .name ())
579
580
)
580
581
);
581
- ensureGreen ();
582
- long termUpto = 0 ;
583
- IndicesStatsResponse stats ;
582
+ ensureGreen ("test_throttle_stats_index" );
584
583
// make sure we see throttling kicking in:
585
- boolean done = false ;
586
- long start = System .currentTimeMillis ();
587
- while (done == false ) {
588
- for (int i = 0 ; i < 100 ; i ++) {
589
- // Provoke slowish merging by making many unique terms:
590
- StringBuilder sb = new StringBuilder ();
591
- for (int j = 0 ; j < 100 ; j ++) {
592
- sb .append (' ' );
593
- sb .append (termUpto ++);
594
- }
595
- client ().prepareIndex ("test" , "type" , "" + termUpto ).setSource ("field" + (i % 10 ), sb .toString ()).get ();
596
- if (i % 2 == 0 ) {
597
- refresh ();
584
+ AtomicBoolean done = new AtomicBoolean ();
585
+ AtomicLong termUpTo = new AtomicLong ();
586
+ Thread [] indexingThreads = new Thread [5 ];
587
+ for (int threadIdx = 0 ; threadIdx < indexingThreads .length ; threadIdx ++) {
588
+ indexingThreads [threadIdx ] = new Thread (() -> {
589
+ while (done .get () == false ) {
590
+ for (int i = 0 ; i < 100 ; i ++) {
591
+ // Provoke slowish merging by making many unique terms:
592
+ StringBuilder sb = new StringBuilder ();
593
+ for (int j = 0 ; j < 100 ; j ++) {
594
+ sb .append (' ' );
595
+ sb .append (termUpTo .incrementAndGet ());
596
+ }
597
+ prepareIndex ("test_throttle_stats_index" ).setId ("" + termUpTo .get ())
598
+ .setSource ("field" + (i % 10 ), sb .toString ())
599
+ .get ();
600
+ if (i % 2 == 0 ) {
601
+ refresh ("test_throttle_stats_index" );
602
+ }
603
+ }
604
+ refresh ("test_throttle_stats_index" );
598
605
}
599
- }
600
- refresh ();
601
- stats = client ().admin ().indices ().prepareStats ().execute ().actionGet ();
602
- // nodesStats = client().admin().cluster().prepareNodesStats().setIndices(true).get();
603
- done = stats .getPrimaries ().getIndexing ().getTotal ().getThrottleTime ().millis () > 0 ;
604
- if (System .currentTimeMillis () - start > 300 * 1000 ) { // Wait 5 minutes for throttling to kick in
605
- fail ("index throttling didn't kick in after 5 minutes of intense merging" );
606
- }
606
+ });
607
+ indexingThreads [threadIdx ].start ();
608
+ }
609
+
610
+ assertBusy (() -> {
611
+ IndicesStatsResponse stats = indicesAdmin ().prepareStats ("test_throttle_stats_index" ).get ();
612
+ assertTrue (stats .getPrimaries ().getIndexing ().getTotal ().getThrottleTime ().millis () > 0 );
613
+ done .set (true );
614
+ }, 5L , TimeUnit .MINUTES );
615
+
616
+ for (Thread indexingThread : indexingThreads ) {
617
+ indexingThread .join ();
607
618
}
608
619
609
620
// Optimize & flush and wait; else we sometimes get a "Delete Index failed - not acked"
610
621
// when ESIntegTestCase.after tries to remove indices created by the test:
611
- logger .info ("test: now optimize" );
612
- client ().admin (). indices (). prepareForceMerge ("test " ).get ();
613
- flush ();
614
- logger .info ("test: test done" );
622
+ logger .info ("test throttle stats : now optimize" );
623
+ indicesAdmin ().prepareForceMerge ("test_throttle_stats_index " ).get ();
624
+ flush ("test_throttle_stats_index" );
625
+ logger .info ("test throttle stats : test done" );
615
626
}
616
627
617
628
public void testSimpleStats () throws Exception {
0 commit comments