@@ -241,7 +241,10 @@ func NewWriteIndexToExternalStoragePipeline(
241
241
srcOp := NewTableScanTaskSource (ctx , store , tbl , startKey , endKey , nil )
242
242
scanOp := NewTableScanOperator (ctx , sessPool , copCtx , srcChkPool , readerCnt , nil , reorgMeta .BatchSize )
243
243
writeOp := NewWriteExternalStoreOperator (
244
- ctx , copCtx , sessPool , jobID , subtaskID , tbl , indexes , extStore , srcChkPool , writerCnt , onClose , memSizePerIndex , reorgMeta )
244
+ ctx , copCtx , sessPool , jobID , subtaskID ,
245
+ tbl , indexes , extStore , srcChkPool , writerCnt ,
246
+ onClose , memSizePerIndex , reorgMeta ,
247
+ )
245
248
sinkOp := newIndexWriteResultSink (ctx , nil , tbl , indexes , nil , rowCntListener )
246
249
247
250
operator .Compose [TableScanTask ](srcOp , scanOp )
@@ -466,6 +469,8 @@ func (*TableScanTaskSource) String() string {
466
469
// TableScanOperator scans table records in given key ranges from kv store.
467
470
type TableScanOperator struct {
468
471
* operator.AsyncOperator [TableScanTask , IndexRecordChunk ]
472
+ logger * zap.Logger
473
+ totalCount * atomic.Int64
469
474
}
470
475
471
476
// NewTableScanOperator creates a new TableScanOperator.
@@ -478,6 +483,7 @@ func NewTableScanOperator(
478
483
cpMgr * ingest.CheckpointManager ,
479
484
hintBatchSize int ,
480
485
) * TableScanOperator {
486
+ totalCount := new (atomic.Int64 )
481
487
pool := workerpool .NewWorkerPool (
482
488
"TableScanOperator" ,
483
489
util .DDL ,
@@ -491,13 +497,22 @@ func NewTableScanOperator(
491
497
srcChkPool : srcChkPool ,
492
498
cpMgr : cpMgr ,
493
499
hintBatchSize : hintBatchSize ,
500
+ totalCount : totalCount ,
494
501
}
495
502
})
496
503
return & TableScanOperator {
497
504
AsyncOperator : operator .NewAsyncOperator [TableScanTask , IndexRecordChunk ](ctx , pool ),
505
+ logger : logutil .Logger (ctx ),
506
+ totalCount : totalCount ,
498
507
}
499
508
}
500
509
510
+ // Close implements operator.Operator interface.
511
+ func (o * TableScanOperator ) Close () error {
512
+ o .logger .Info ("table scan operator total count" , zap .Int64 ("count" , o .totalCount .Load ()))
513
+ return o .AsyncOperator .Close ()
514
+ }
515
+
501
516
type tableScanWorker struct {
502
517
ctx * OperatorCtx
503
518
copCtx copr.CopContext
@@ -507,6 +522,7 @@ type tableScanWorker struct {
507
522
508
523
cpMgr * ingest.CheckpointManager
509
524
hintBatchSize int
525
+ totalCount * atomic.Int64
510
526
}
511
527
512
528
func (w * tableScanWorker ) HandleTask (task TableScanTask , sender func (IndexRecordChunk )) {
@@ -561,6 +577,7 @@ func (w *tableScanWorker) scanRecords(task TableScanTask, sender func(IndexRecor
561
577
if w .cpMgr != nil {
562
578
w .cpMgr .UpdateTotalKeys (task .ID , srcChk .NumRows (), done )
563
579
}
580
+ w .totalCount .Add (int64 (srcChk .NumRows ()))
564
581
sender (idxResult )
565
582
}
566
583
return rs .Close ()
@@ -587,6 +604,8 @@ func (w *tableScanWorker) recycleChunk(chk *chunk.Chunk) {
587
604
// WriteExternalStoreOperator writes index records to external storage.
588
605
type WriteExternalStoreOperator struct {
589
606
* operator.AsyncOperator [IndexRecordChunk , IndexWriteResult ]
607
+ logger * zap.Logger
608
+ totalCount * atomic.Int64
590
609
}
591
610
592
611
// NewWriteExternalStoreOperator creates a new WriteExternalStoreOperator.
@@ -615,6 +634,7 @@ func NewWriteExternalStoreOperator(
615
634
}
616
635
}
617
636
637
+ totalCount := new (atomic.Int64 )
618
638
pool := workerpool .NewWorkerPool (
619
639
"WriteExternalStoreOperator" ,
620
640
util .DDL ,
@@ -644,14 +664,24 @@ func NewWriteExternalStoreOperator(
644
664
writers : writers ,
645
665
srcChunkPool : srcChunkPool ,
646
666
reorgMeta : reorgMeta ,
667
+ totalCount : totalCount ,
647
668
},
648
669
}
649
670
})
650
671
return & WriteExternalStoreOperator {
651
672
AsyncOperator : operator .NewAsyncOperator [IndexRecordChunk , IndexWriteResult ](ctx , pool ),
673
+ logger : logutil .Logger (ctx ),
674
+ totalCount : totalCount ,
652
675
}
653
676
}
654
677
678
+ // Close implements operator.Operator interface.
679
+ func (o * WriteExternalStoreOperator ) Close () error {
680
+ o .logger .Info ("write external storage operator total count" ,
681
+ zap .Int64 ("count" , o .totalCount .Load ()))
682
+ return o .AsyncOperator .Close ()
683
+ }
684
+
655
685
// IndexWriteResult contains the result of writing index records to ingest engine.
656
686
type IndexWriteResult struct {
657
687
ID int
@@ -798,6 +828,8 @@ type indexIngestBaseWorker struct {
798
828
799
829
writers []ingest.Writer
800
830
srcChunkPool chan * chunk.Chunk
831
+ // only available in global sort
832
+ totalCount * atomic.Int64
801
833
}
802
834
803
835
func (w * indexIngestBaseWorker ) HandleTask (rs IndexRecordChunk ) (IndexWriteResult , error ) {
@@ -818,6 +850,9 @@ func (w *indexIngestBaseWorker) HandleTask(rs IndexRecordChunk) (IndexWriteResul
818
850
logutil .Logger (w .ctx ).Info ("finish a index ingest task" , zap .Int ("id" , rs .ID ))
819
851
return result , nil
820
852
}
853
+ if w .totalCount != nil {
854
+ w .totalCount .Add (int64 (count ))
855
+ }
821
856
result .Added = count
822
857
result .Next = nextKey
823
858
if ResultCounterForTest != nil {
0 commit comments