19
19
package org .apache .accumulo .manager .tableOps .bulkVer2 ;
20
20
21
21
import static java .nio .charset .StandardCharsets .UTF_8 ;
22
- import static java .util .concurrent .TimeUnit .MILLISECONDS ;
23
22
import static org .apache .accumulo .core .metadata .schema .TabletMetadata .ColumnType .LOADED ;
24
23
import static org .apache .accumulo .core .metadata .schema .TabletMetadata .ColumnType .LOCATION ;
25
24
import static org .apache .accumulo .core .metadata .schema .TabletMetadata .ColumnType .PREV_ROW ;
26
25
26
+ import java .time .Duration ;
27
27
import java .util .ArrayList ;
28
28
import java .util .Comparator ;
29
29
import java .util .HashMap ;
@@ -315,6 +315,16 @@ long finish() throws Exception {
315
315
}
316
316
}
317
317
318
+ /**
319
+ * Stats for the loadFiles method. Helps track wasted time and iterations.
320
+ */
321
+ private static class ImportTimingStats {
322
+ Duration totalWastedTime = Duration .ZERO ;
323
+ long wastedIterations = 0 ;
324
+ long tabletCount = 0 ;
325
+ long callCount = 0 ;
326
+ }
327
+
318
328
/**
319
329
* Make asynchronous load calls to each overlapping Tablet in the bulk mapping. Return a sleep
320
330
* time to isReady based on a factor of the TabletServer with the most Tablets. This method will
@@ -344,20 +354,33 @@ private long loadFiles(TableId tableId, Path bulkDir, LoadMappingIterator loadMa
344
354
345
355
loader .start (bulkDir , manager , tid , bulkInfo .setTime );
346
356
347
- long t1 = System .currentTimeMillis ();
357
+ ImportTimingStats importTimingStats = new ImportTimingStats ();
358
+
359
+ Timer timer = Timer .startNew ();
348
360
while (lmi .hasNext ()) {
349
361
loadMapEntry = lmi .next ();
350
362
List <TabletMetadata > tablets =
351
- findOverlappingTablets (fmtTid , loadMapEntry .getKey (), tabletIter );
363
+ findOverlappingTablets (fmtTid , loadMapEntry .getKey (), tabletIter , importTimingStats );
352
364
loader .load (tablets , loadMapEntry .getValue ());
353
365
}
366
+ Duration totalProcessingTime = timer .elapsed ();
354
367
355
368
log .trace ("{}: Completed Finding Overlapping Tablets" , fmtTid );
356
369
370
+ if (importTimingStats .callCount > 0 ) {
371
+ log .info (
372
+ "Bulk import stats for {} (tid = {}): processed {} tablets in {} calls which took {}ms ({} nanos). Skipped {} iterations which took {}ms ({} nanos) or {}% of the processing time." ,
373
+ bulkInfo .sourceDir , FateTxId .formatTid (tid ), importTimingStats .tabletCount ,
374
+ importTimingStats .callCount , totalProcessingTime .toMillis (),
375
+ totalProcessingTime .toNanos (), importTimingStats .wastedIterations ,
376
+ importTimingStats .totalWastedTime .toMillis (), importTimingStats .totalWastedTime .toNanos (),
377
+ (importTimingStats .totalWastedTime .toNanos () * 100 ) / totalProcessingTime .toNanos ());
378
+ }
379
+
357
380
long sleepTime = loader .finish ();
358
381
if (sleepTime > 0 ) {
359
382
log .trace ("{}: Tablet Max Sleep is {}" , fmtTid , sleepTime );
360
- long scanTime = Math .min (System . currentTimeMillis () - t1 , 30_000 );
383
+ long scanTime = Math .min (totalProcessingTime . toMillis () , 30_000 );
361
384
log .trace ("{}: Scan time is {}" , fmtTid , scanTime );
362
385
sleepTime = Math .max (sleepTime , scanTime * 2 );
363
386
}
@@ -372,7 +395,7 @@ private long loadFiles(TableId tableId, Path bulkDir, LoadMappingIterator loadMa
372
395
* Find all the tablets within the provided bulk load mapping range.
373
396
*/
374
397
private List <TabletMetadata > findOverlappingTablets (String fmtTid , KeyExtent loadRange ,
375
- Iterator <TabletMetadata > tabletIter ) {
398
+ Iterator <TabletMetadata > tabletIter , ImportTimingStats importTimingStats ) {
376
399
377
400
TabletMetadata currTablet = null ;
378
401
@@ -394,7 +417,7 @@ private List<TabletMetadata> findOverlappingTablets(String fmtTid, KeyExtent loa
394
417
currTablet = tabletIter .next ();
395
418
}
396
419
397
- long wastedMillis = timer .elapsed (MILLISECONDS );
420
+ Duration wastedTime = timer .elapsed ();
398
421
399
422
if (cmp != 0 ) {
400
423
throw new IllegalStateException (
@@ -416,11 +439,10 @@ private List<TabletMetadata> findOverlappingTablets(String fmtTid, KeyExtent loa
416
439
throw new IllegalStateException ("Unexpected end row " + currTablet + " " + loadRange );
417
440
}
418
441
419
- if (wastedIterations > 0 ) {
420
- log .debug (
421
- "Skipped {} tablets searching for prevEndRow of loadRange in {} ms to return {} tablets total in {}ms." ,
422
- wastedIterations , wastedMillis , tablets .size (), timer .elapsed (MILLISECONDS ));
423
- }
442
+ importTimingStats .wastedIterations += wastedIterations ;
443
+ importTimingStats .totalWastedTime = importTimingStats .totalWastedTime .plus (wastedTime );
444
+ importTimingStats .tabletCount += tablets .size ();
445
+ importTimingStats .callCount ++;
424
446
425
447
return tablets ;
426
448
} catch (NoSuchElementException e ) {
0 commit comments