24
24
import com .lmax .disruptor .RingBuffer ;
25
25
import com .lmax .disruptor .Sequence ;
26
26
import com .lmax .disruptor .Sequencer ;
27
- import io .opentelemetry .api .trace .Span ;
28
- import io .opentelemetry .context .Scope ;
29
27
import java .io .IOException ;
30
28
import java .lang .reflect .Field ;
31
29
import java .util .ArrayDeque ;
53
51
import org .apache .hadoop .hbase .HBaseInterfaceAudience ;
54
52
import org .apache .hadoop .hbase .client .RegionInfo ;
55
53
import org .apache .hadoop .hbase .io .asyncfs .AsyncFSOutput ;
56
- import org .apache .hadoop .hbase .trace .TraceUtil ;
57
54
import org .apache .hadoop .hbase .wal .AsyncFSWALProvider ;
58
55
import org .apache .hadoop .hbase .wal .WALEdit ;
59
56
import org .apache .hadoop .hbase .wal .WALKeyImpl ;
@@ -345,7 +342,7 @@ private void syncCompleted(AsyncWriter writer, long processedTxid, long startTim
345
342
break ;
346
343
}
347
344
}
348
- postSync (System .nanoTime () - startTimeNs , finishSync (true ));
345
+ postSync (System .nanoTime () - startTimeNs , finishSync ());
349
346
if (trySetReadyForRolling ()) {
350
347
// we have just finished a roll, then do not need to check for log rolling, the writer will be
351
348
// closed soon.
@@ -394,23 +391,14 @@ private void sync(AsyncWriter writer) {
394
391
}, consumeExecutor );
395
392
}
396
393
397
- private void addTimeAnnotation (SyncFuture future , String annotation ) {
398
- Span .current ().addEvent (annotation );
399
- // TODO handle htrace API change, see HBASE-18895
400
- // future.setSpan(scope.getSpan());
401
- }
402
-
403
- private int finishSyncLowerThanTxid (long txid , boolean addSyncTrace ) {
394
+ private int finishSyncLowerThanTxid (long txid ) {
404
395
int finished = 0 ;
405
396
for (Iterator <SyncFuture > iter = syncFutures .iterator (); iter .hasNext ();) {
406
397
SyncFuture sync = iter .next ();
407
398
if (sync .getTxid () <= txid ) {
408
399
sync .done (txid , null );
409
400
iter .remove ();
410
401
finished ++;
411
- if (addSyncTrace ) {
412
- addTimeAnnotation (sync , "writer synced" );
413
- }
414
402
} else {
415
403
break ;
416
404
}
@@ -419,7 +407,7 @@ private int finishSyncLowerThanTxid(long txid, boolean addSyncTrace) {
419
407
}
420
408
421
409
// try advancing the highestSyncedTxid as much as possible
422
- private int finishSync (boolean addSyncTrace ) {
410
+ private int finishSync () {
423
411
if (unackedAppends .isEmpty ()) {
424
412
// All outstanding appends have been acked.
425
413
if (toWriteAppends .isEmpty ()) {
@@ -428,9 +416,6 @@ private int finishSync(boolean addSyncTrace) {
428
416
for (SyncFuture sync : syncFutures ) {
429
417
maxSyncTxid = Math .max (maxSyncTxid , sync .getTxid ());
430
418
sync .done (maxSyncTxid , null );
431
- if (addSyncTrace ) {
432
- addTimeAnnotation (sync , "writer synced" );
433
- }
434
419
}
435
420
highestSyncedTxid .set (maxSyncTxid );
436
421
int finished = syncFutures .size ();
@@ -444,23 +429,23 @@ private int finishSync(boolean addSyncTrace) {
444
429
assert lowestUnprocessedAppendTxid > highestProcessedAppendTxid ;
445
430
long doneTxid = lowestUnprocessedAppendTxid - 1 ;
446
431
highestSyncedTxid .set (doneTxid );
447
- return finishSyncLowerThanTxid (doneTxid , addSyncTrace );
432
+ return finishSyncLowerThanTxid (doneTxid );
448
433
}
449
434
} else {
450
435
// There are still unacked appends. So let's move the highestSyncedTxid to the txid of the
451
436
// first unacked append minus 1.
452
437
long lowestUnackedAppendTxid = unackedAppends .peek ().getTxid ();
453
438
long doneTxid = Math .max (lowestUnackedAppendTxid - 1 , highestSyncedTxid .get ());
454
439
highestSyncedTxid .set (doneTxid );
455
- return finishSyncLowerThanTxid (doneTxid , addSyncTrace );
440
+ return finishSyncLowerThanTxid (doneTxid );
456
441
}
457
442
}
458
443
459
444
private void appendAndSync () {
460
445
final AsyncWriter writer = this .writer ;
461
446
// maybe a sync request is not queued when we issue a sync, so check here to see if we could
462
447
// finish some.
463
- finishSync (false );
448
+ finishSync ();
464
449
long newHighestProcessedAppendTxid = -1L ;
465
450
for (Iterator <FSWALEntry > iter = toWriteAppends .iterator (); iter .hasNext ();) {
466
451
FSWALEntry entry = iter .next ();
@@ -501,7 +486,7 @@ private void appendAndSync() {
501
486
// stamped some region sequence id.
502
487
if (unackedAppends .isEmpty ()) {
503
488
highestSyncedTxid .set (highestProcessedAppendTxid );
504
- finishSync (false );
489
+ finishSync ();
505
490
trySetReadyForRolling ();
506
491
}
507
492
return ;
@@ -648,74 +633,54 @@ protected boolean markerEditOnly() {
648
633
649
634
@ Override
650
635
protected long append (RegionInfo hri , WALKeyImpl key , WALEdit edits , boolean inMemstore )
651
- throws IOException {
652
- if (markerEditOnly () && !edits .isMetaEdit ()) {
653
- throw new IOException ("WAL is closing, only marker edit is allowed" );
654
- }
655
- long txid = stampSequenceIdAndPublishToRingBuffer ( hri , key , edits , inMemstore ,
656
- waitingConsumePayloads );
636
+ throws IOException {
637
+ if (markerEditOnly () && !edits .isMetaEdit ()) {
638
+ throw new IOException ("WAL is closing, only marker edit is allowed" );
639
+ }
640
+ long txid =
641
+ stampSequenceIdAndPublishToRingBuffer ( hri , key , edits , inMemstore , waitingConsumePayloads );
657
642
if (shouldScheduleConsumer ()) {
658
643
consumeExecutor .execute (consumer );
659
644
}
660
645
return txid ;
661
646
}
662
647
663
648
@ Override
664
- public void sync () throws IOException {
665
- sync (useHsync );
666
- }
667
-
668
- @ Override
669
- public void sync (long txid ) throws IOException {
670
- sync (txid , useHsync );
671
- }
672
-
673
- @ Override
674
- public void sync (boolean forceSync ) throws IOException {
675
- Span span = TraceUtil .getGlobalTracer ().spanBuilder ("AsyncFSWAL.sync" ).startSpan ();
676
- try (Scope scope = span .makeCurrent ()) {
677
- long txid = waitingConsumePayloads .next ();
678
- SyncFuture future ;
679
- try {
680
- future = getSyncFuture (txid , forceSync );
681
- RingBufferTruck truck = waitingConsumePayloads .get (txid );
682
- truck .load (future );
683
- } finally {
684
- waitingConsumePayloads .publish (txid );
685
- }
686
- if (shouldScheduleConsumer ()) {
687
- consumeExecutor .execute (consumer );
688
- }
689
- blockOnSync (future );
649
+ protected void doSync (boolean forceSync ) throws IOException {
650
+ long txid = waitingConsumePayloads .next ();
651
+ SyncFuture future ;
652
+ try {
653
+ future = getSyncFuture (txid , forceSync );
654
+ RingBufferTruck truck = waitingConsumePayloads .get (txid );
655
+ truck .load (future );
690
656
} finally {
691
- span . end ( );
657
+ waitingConsumePayloads . publish ( txid );
692
658
}
659
+ if (shouldScheduleConsumer ()) {
660
+ consumeExecutor .execute (consumer );
661
+ }
662
+ blockOnSync (future );
693
663
}
694
664
695
665
@ Override
696
- public void sync (long txid , boolean forceSync ) throws IOException {
666
+ protected void doSync (long txid , boolean forceSync ) throws IOException {
697
667
if (highestSyncedTxid .get () >= txid ) {
698
668
return ;
699
669
}
700
- Span span = TraceUtil .getGlobalTracer ().spanBuilder ("AsyncFSWAL.sync" ).startSpan ();
701
- try (Scope scope = span .makeCurrent ()) {
702
- // here we do not use ring buffer sequence as txid
703
- long sequence = waitingConsumePayloads .next ();
704
- SyncFuture future ;
705
- try {
706
- future = getSyncFuture (txid , forceSync );
707
- RingBufferTruck truck = waitingConsumePayloads .get (sequence );
708
- truck .load (future );
709
- } finally {
710
- waitingConsumePayloads .publish (sequence );
711
- }
712
- if (shouldScheduleConsumer ()) {
713
- consumeExecutor .execute (consumer );
714
- }
715
- blockOnSync (future );
670
+ // here we do not use ring buffer sequence as txid
671
+ long sequence = waitingConsumePayloads .next ();
672
+ SyncFuture future ;
673
+ try {
674
+ future = getSyncFuture (txid , forceSync );
675
+ RingBufferTruck truck = waitingConsumePayloads .get (sequence );
676
+ truck .load (future );
716
677
} finally {
717
- span .end ();
678
+ waitingConsumePayloads .publish (sequence );
679
+ }
680
+ if (shouldScheduleConsumer ()) {
681
+ consumeExecutor .execute (consumer );
718
682
}
683
+ blockOnSync (future );
719
684
}
720
685
721
686
protected final AsyncWriter createAsyncWriter (FileSystem fs , Path path ) throws IOException {
0 commit comments