@@ -20,6 +20,7 @@ import (
20
20
"encoding/hex"
21
21
"fmt"
22
22
"strconv"
23
+ "strings"
23
24
"sync"
24
25
"sync/atomic"
25
26
"time"
@@ -194,23 +195,49 @@ func newBackfillCtx(id int, rInfo *reorgInfo,
194
195
id = int (backfillContextID .Add (1 ))
195
196
}
196
197
198
+ colOrIdxName := ""
199
+ switch rInfo .Job .Type {
200
+ case model .ActionAddIndex , model .ActionAddPrimaryKey :
201
+ args , err := model .GetModifyIndexArgs (rInfo .Job )
202
+ if err != nil {
203
+ logutil .DDLLogger ().Error ("Fail to get ModifyIndexArgs" , zap .String ("label" , label ), zap .String ("schemaName" , schemaName ), zap .String ("tableName" , tbl .Meta ().Name .String ()))
204
+ } else {
205
+ colOrIdxName = getIdxNamesFromArgs (args )
206
+ }
207
+ case model .ActionModifyColumn :
208
+ oldCol , _ := getOldAndNewColumnsForUpdateColumn (tbl , rInfo .currElement .ID )
209
+ if oldCol != nil {
210
+ colOrIdxName = oldCol .Name .String ()
211
+ }
212
+ }
213
+
197
214
batchCnt := rInfo .ReorgMeta .GetBatchSizeOrDefault (int (variable .GetDDLReorgBatchSize ()))
198
215
return & backfillCtx {
199
- id : id ,
200
- ddlCtx : rInfo .jobCtx .oldDDLCtx ,
201
- warnings : warnHandler ,
202
- exprCtx : exprCtx ,
203
- tblCtx : tblCtx ,
204
- loc : exprCtx .GetEvalCtx ().Location (),
205
- schemaName : schemaName ,
206
- table : tbl ,
207
- batchCnt : batchCnt ,
208
- jobContext : jobCtx ,
209
- metricCounter : metrics .BackfillTotalCounter .WithLabelValues (
210
- metrics .GenerateReorgLabel (label , schemaName , tbl .Meta ().Name .String ())),
216
+ id : id ,
217
+ ddlCtx : rInfo .jobCtx .oldDDLCtx ,
218
+ warnings : warnHandler ,
219
+ exprCtx : exprCtx ,
220
+ tblCtx : tblCtx ,
221
+ loc : exprCtx .GetEvalCtx ().Location (),
222
+ schemaName : schemaName ,
223
+ table : tbl ,
224
+ batchCnt : batchCnt ,
225
+ jobContext : jobCtx ,
226
+ metricCounter : metrics .GetBackfillTotalByLabel (label , schemaName , tbl .Meta ().Name .String (), colOrIdxName ),
211
227
}, nil
212
228
}
213
229
230
+ func getIdxNamesFromArgs (args * model.ModifyIndexArgs ) string {
231
+ var sb strings.Builder
232
+ for i , idx := range args .IndexArgs {
233
+ if i > 0 {
234
+ sb .WriteString ("+" )
235
+ }
236
+ sb .WriteString (idx .IndexName .O )
237
+ }
238
+ return sb .String ()
239
+ }
240
+
214
241
func updateTxnEntrySizeLimitIfNeeded (txn kv.Transaction ) {
215
242
if entrySizeLimit := variable .TxnEntrySizeLimit .Load (); entrySizeLimit > 0 {
216
243
txn .SetOption (kv .SizeLimits , kv.TxnSizeLimits {
@@ -686,6 +713,7 @@ func (dc *ddlCtx) runAddIndexInLocalIngestMode(
686
713
idxCnt := len (reorgInfo .elements )
687
714
indexIDs := make ([]int64 , 0 , idxCnt )
688
715
indexInfos := make ([]* model.IndexInfo , 0 , idxCnt )
716
+ var indexNames strings.Builder
689
717
uniques := make ([]bool , 0 , idxCnt )
690
718
hasUnique := false
691
719
for _ , e := range reorgInfo .elements {
@@ -699,6 +727,10 @@ func (dc *ddlCtx) runAddIndexInLocalIngestMode(
699
727
return errors .Errorf ("index info not found: %d" , e .ID )
700
728
}
701
729
indexInfos = append (indexInfos , indexInfo )
730
+ if indexNames .Len () > 0 {
731
+ indexNames .WriteString ("+" )
732
+ }
733
+ indexNames .WriteString (indexInfo .Name .O )
702
734
uniques = append (uniques , indexInfo .Unique )
703
735
hasUnique = hasUnique || indexInfo .Unique
704
736
}
@@ -736,8 +768,7 @@ func (dc *ddlCtx) runAddIndexInLocalIngestMode(
736
768
rowCntListener := & localRowCntListener {
737
769
prevPhysicalRowCnt : reorgCtx .getRowCount (),
738
770
reorgCtx : reorgCtx ,
739
- counter : metrics .BackfillTotalCounter .WithLabelValues (
740
- metrics .GenerateReorgLabel ("add_idx_rate" , job .SchemaName , job .TableName )),
771
+ counter : metrics .GetBackfillTotalByLabel (metrics .LblAddIdxRate , job .SchemaName , job .TableName , indexNames .String ()),
741
772
}
742
773
743
774
sctx , err := sessPool .Get ()
0 commit comments