@@ -78,7 +78,7 @@ public static void main(String[] clArgs) throws Exception {
7878 }
7979 }
8080
81- private static MergeScheduler getMergeScheduler (AtomicBoolean indexingFailed , boolean useCMS , int maxConcurrentMerges ) {
81+ private static MergeScheduler getMergeScheduler (AtomicBoolean indexingFailed , boolean useCMS , int maxConcurrentMerges , boolean disableIOThrottle ) {
8282 if (useCMS ) {
8383 ConcurrentMergeScheduler cms = new ConcurrentMergeScheduler () {
8484 @ Override
@@ -90,6 +90,9 @@ protected void handleMergeException(Directory dir, Throwable exc) {
9090 }
9191 };
9292 cms .setMaxMergesAndThreads (maxConcurrentMerges +4 , maxConcurrentMerges );
93+ if (disableIOThrottle ) {
94+ cms .disableAutoIOThrottle ();
95+ }
9396 return cms ;
9497 } else {
9598 // Gives better repeatability because if you use CMS, the order in which the merges complete can impact how the merge policy later
@@ -200,6 +203,7 @@ private static void _main(String[] clArgs) throws Exception {
200203 final boolean doDeletions = args .getFlag ("-deletions" );
201204 final boolean printDPS = args .getFlag ("-printDPS" );
202205 final boolean waitForMerges = args .getFlag ("-waitForMerges" );
206+ final boolean waitForCommit = args .getFlag ("-waitForCommit" );
203207 final String mergePolicy = args .getString ("-mergePolicy" );
204208 final Mode mode ;
205209 final boolean doUpdate = args .getFlag ("-update" );
@@ -224,6 +228,23 @@ private static void _main(String[] clArgs) throws Exception {
224228 final boolean addDVFields = args .getFlag ("-dvfields" );
225229 final boolean doRandomCommit = args .getFlag ("-randomCommit" );
226230 final boolean useCMS = args .getFlag ("-useCMS" );
231+ final boolean disableIOThrottle = args .getFlag ("-disableIOThrottle" );
232+
233+ if (waitForCommit == false && waitForMerges ) {
234+ throw new RuntimeException ("pass -waitForCommit if you pass -waitForMerges" );
235+ }
236+
237+ if (waitForCommit == false && doForceMerge ) {
238+ throw new RuntimeException ("pass -waitForCommit if you pass -forceMerge" );
239+ }
240+
241+ if (waitForCommit == false && doDeletions ) {
242+ throw new RuntimeException ("pass -waitForCommit if you pass -deletions" );
243+ }
244+
245+ if (useCMS == false && disableIOThrottle ) {
246+ throw new RuntimeException ("-disableIOThrottle only makes sense with -useCMS" );
247+ }
227248
228249 final double nrtEverySec ;
229250 if (args .hasArg ("-nrtEverySec" )) {
@@ -263,6 +284,8 @@ private static void _main(String[] clArgs) throws Exception {
263284 System .out .println ("Default postings format: " + defaultPostingsFormat );
264285 System .out .println ("Do deletions: " + (doDeletions ? "yes" : "no" ));
265286 System .out .println ("Wait for merges: " + (waitForMerges ? "yes" : "no" ));
287+ System .out .println ("Wait for commit: " + (waitForCommit ? "yes" : "no" ));
288+ System .out .println ("IO throttle: " + (disableIOThrottle ? "no" : "yes" ));
266289 System .out .println ("Merge policy: " + mergePolicy );
267290 System .out .println ("Mode: " + mode );
268291 if (mode == Mode .UPDATE ) {
@@ -310,7 +333,7 @@ private static void _main(String[] clArgs) throws Exception {
310333
311334 final AtomicBoolean indexingFailed = new AtomicBoolean ();
312335
313- iwc .setMergeScheduler (getMergeScheduler (indexingFailed , useCMS , maxConcurrentMerges ));
336+ iwc .setMergeScheduler (getMergeScheduler (indexingFailed , useCMS , maxConcurrentMerges , disableIOThrottle ));
314337 iwc .setMergePolicy (getMergePolicy (mergePolicy , useCFS ));
315338
316339 // Keep all commit points:
@@ -401,11 +424,12 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
401424 throw new RuntimeException ("w.maxDoc()=" + w .maxDoc () + " but expected " + docCountLimit );
402425 }
403426
404- final long t2 ;
427+ final Map <String ,String > commitData = new HashMap <String ,String >();
428+
405429 if (waitForMerges ) {
406430 w .close ();
407431 IndexWriterConfig iwc2 = new IndexWriterConfig (a );
408- iwc2 .setMergeScheduler (getMergeScheduler (indexingFailed , useCMS , maxConcurrentMerges ));
432+ iwc2 .setMergeScheduler (getMergeScheduler (indexingFailed , useCMS , maxConcurrentMerges , disableIOThrottle ));
409433 iwc2 .setMergePolicy (getMergePolicy (mergePolicy , useCFS ));
410434 iwc2 .setCodec (codec );
411435 iwc2 .setUseCompoundFile (useCFS );
@@ -416,29 +440,33 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
416440 }
417441
418442 w = new IndexWriter (dir , iwc2 );
419- t2 = System .currentTimeMillis ();
443+ long t2 = System .currentTimeMillis ();
420444 System .out .println ("\n Indexer: waitForMerges done (" + (t2 -t1 ) + " msec)" );
421- } else {
422- t2 = System .currentTimeMillis ();
423445 }
424446
425- final Map <String ,String > commitData = new HashMap <String ,String >();
426- commitData .put ("userData" , "multi" );
427- w .setCommitData (commitData );
428- w .commit ();
429- final long t3 = System .currentTimeMillis ();
430- System .out .println ("\n Indexer: commit multi (took " + (t3 -t2 ) + " msec)" );
447+ if (waitForCommit ) {
448+ commitData .put ("userData" , "multi" );
449+ w .setCommitData (commitData );
450+ long t2 = System .currentTimeMillis ();
451+ w .commit ();
452+ long t3 = System .currentTimeMillis ();
453+ System .out .println ("\n Indexer: commit multi (took " + (t3 -t2 ) + " msec)" );
454+ } else {
455+ w .rollback ();
456+ w = null ;
457+ }
431458
432459 if (doForceMerge ) {
460+ long forceMergeStartMSec = System .currentTimeMillis ();
433461 w .forceMerge (1 );
434- final long t4 = System .currentTimeMillis ();
435- System .out .println ("\n Indexer: force merge done (took " + (t4 - t3 ) + " msec)" );
462+ long forceMergeEndMSec = System .currentTimeMillis ();
463+ System .out .println ("\n Indexer: force merge done (took " + (forceMergeEndMSec - forceMergeStartMSec ) + " msec)" );
436464
437465 commitData .put ("userData" , "single" );
438466 w .setCommitData (commitData );
439467 w .commit ();
440468 final long t5 = System .currentTimeMillis ();
441- System .out .println ("\n Indexer: commit single done (took " + (t5 -t4 ) + " msec)" );
469+ System .out .println ("\n Indexer: commit single done (took " + (t5 -forceMergeEndMSec ) + " msec)" );
442470 }
443471
444472 if (doDeletions ) {
@@ -476,17 +504,27 @@ public DocValuesFormat getDocValuesFormatForField(String field) {
476504 }
477505
478506 final long tCloseStart = System .currentTimeMillis ();
479- if (waitForMerges == false ) {
480- w .rollback ();
481- } else {
507+ if (w != null ) {
482508 w .close ();
509+ w = null ;
510+ }
511+ if (waitForCommit ) {
512+ System .out .println ("\n Indexer: at close: " + SegmentInfos .readLatestCommit (dir ));
513+ System .out .println ("\n Indexer: close took " + (System .currentTimeMillis () - tCloseStart ) + " msec" );
483514 }
484- System .out .println ("\n Indexer: at close: " + SegmentInfos .readLatestCommit (dir ));
485- System .out .println ("\n Indexer: close took " + (System .currentTimeMillis () - tCloseStart ) + " msec" );
515+
486516 dir .close ();
487517 final long tFinal = System .currentTimeMillis ();
488- System .out .println ("\n Indexer: finished (" + (tFinal -t0 ) + " msec)" );
489518 System .out .println ("\n Indexer: net bytes indexed " + threads .getBytesIndexed ());
490- System .out .println ("\n Indexer: " + (threads .getBytesIndexed ()/1024. /1024. /1024. /((tFinal -t0 )/3600000. )) + " GB/hour plain text" );
519+
520+ final long indexingTime ;
521+ if (waitForCommit ) {
522+ indexingTime = tFinal - t0 ;
523+ System .out .println ("\n Indexer: finished (" + indexingTime + " msec)" );
524+ } else {
525+ indexingTime = t1 - t0 ;
526+ System .out .println ("\n Indexer: finished (" + indexingTime + " msec), excluding commit" );
527+ }
528+ System .out .println ("\n Indexer: " + (threads .getBytesIndexed ()/1024. /1024. /1024. /(indexingTime /3600000. )) + " GB/hour plain text" );
491529 }
492530}
0 commit comments