Skip to content

Commit 44f1c14

Browse files
authored
disttask: print total count in log (#56759)
ref #56733
1 parent ef390c2 commit 44f1c14

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

pkg/ddl/backfilling_operators.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ func NewWriteIndexToExternalStoragePipeline(
241241
srcOp := NewTableScanTaskSource(ctx, store, tbl, startKey, endKey, nil)
242242
scanOp := NewTableScanOperator(ctx, sessPool, copCtx, srcChkPool, readerCnt, nil, reorgMeta.BatchSize)
243243
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+
)
245248
sinkOp := newIndexWriteResultSink(ctx, nil, tbl, indexes, nil, rowCntListener)
246249

247250
operator.Compose[TableScanTask](srcOp, scanOp)
@@ -466,6 +469,8 @@ func (*TableScanTaskSource) String() string {
466469
// TableScanOperator scans table records in given key ranges from kv store.
467470
type TableScanOperator struct {
468471
*operator.AsyncOperator[TableScanTask, IndexRecordChunk]
472+
logger *zap.Logger
473+
totalCount *atomic.Int64
469474
}
470475

471476
// NewTableScanOperator creates a new TableScanOperator.
@@ -478,6 +483,7 @@ func NewTableScanOperator(
478483
cpMgr *ingest.CheckpointManager,
479484
hintBatchSize int,
480485
) *TableScanOperator {
486+
totalCount := new(atomic.Int64)
481487
pool := workerpool.NewWorkerPool(
482488
"TableScanOperator",
483489
util.DDL,
@@ -491,13 +497,22 @@ func NewTableScanOperator(
491497
srcChkPool: srcChkPool,
492498
cpMgr: cpMgr,
493499
hintBatchSize: hintBatchSize,
500+
totalCount: totalCount,
494501
}
495502
})
496503
return &TableScanOperator{
497504
AsyncOperator: operator.NewAsyncOperator[TableScanTask, IndexRecordChunk](ctx, pool),
505+
logger: logutil.Logger(ctx),
506+
totalCount: totalCount,
498507
}
499508
}
500509

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+
501516
type tableScanWorker struct {
502517
ctx *OperatorCtx
503518
copCtx copr.CopContext
@@ -507,6 +522,7 @@ type tableScanWorker struct {
507522

508523
cpMgr *ingest.CheckpointManager
509524
hintBatchSize int
525+
totalCount *atomic.Int64
510526
}
511527

512528
func (w *tableScanWorker) HandleTask(task TableScanTask, sender func(IndexRecordChunk)) {
@@ -561,6 +577,7 @@ func (w *tableScanWorker) scanRecords(task TableScanTask, sender func(IndexRecor
561577
if w.cpMgr != nil {
562578
w.cpMgr.UpdateTotalKeys(task.ID, srcChk.NumRows(), done)
563579
}
580+
w.totalCount.Add(int64(srcChk.NumRows()))
564581
sender(idxResult)
565582
}
566583
return rs.Close()
@@ -587,6 +604,8 @@ func (w *tableScanWorker) recycleChunk(chk *chunk.Chunk) {
587604
// WriteExternalStoreOperator writes index records to external storage.
588605
type WriteExternalStoreOperator struct {
589606
*operator.AsyncOperator[IndexRecordChunk, IndexWriteResult]
607+
logger *zap.Logger
608+
totalCount *atomic.Int64
590609
}
591610

592611
// NewWriteExternalStoreOperator creates a new WriteExternalStoreOperator.
@@ -615,6 +634,7 @@ func NewWriteExternalStoreOperator(
615634
}
616635
}
617636

637+
totalCount := new(atomic.Int64)
618638
pool := workerpool.NewWorkerPool(
619639
"WriteExternalStoreOperator",
620640
util.DDL,
@@ -644,14 +664,24 @@ func NewWriteExternalStoreOperator(
644664
writers: writers,
645665
srcChunkPool: srcChunkPool,
646666
reorgMeta: reorgMeta,
667+
totalCount: totalCount,
647668
},
648669
}
649670
})
650671
return &WriteExternalStoreOperator{
651672
AsyncOperator: operator.NewAsyncOperator[IndexRecordChunk, IndexWriteResult](ctx, pool),
673+
logger: logutil.Logger(ctx),
674+
totalCount: totalCount,
652675
}
653676
}
654677

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+
655685
// IndexWriteResult contains the result of writing index records to ingest engine.
656686
type IndexWriteResult struct {
657687
ID int
@@ -798,6 +828,8 @@ type indexIngestBaseWorker struct {
798828

799829
writers []ingest.Writer
800830
srcChunkPool chan *chunk.Chunk
831+
// only available in global sort
832+
totalCount *atomic.Int64
801833
}
802834

803835
func (w *indexIngestBaseWorker) HandleTask(rs IndexRecordChunk) (IndexWriteResult, error) {
@@ -818,6 +850,9 @@ func (w *indexIngestBaseWorker) HandleTask(rs IndexRecordChunk) (IndexWriteResul
818850
logutil.Logger(w.ctx).Info("finish a index ingest task", zap.Int("id", rs.ID))
819851
return result, nil
820852
}
853+
if w.totalCount != nil {
854+
w.totalCount.Add(int64(count))
855+
}
821856
result.Added = count
822857
result.Next = nextKey
823858
if ResultCounterForTest != nil {

0 commit comments

Comments
 (0)