@@ -519,7 +519,7 @@ func (s *session) doCommit(ctx context.Context) error {
519
519
return plannererrors .ErrSQLInReadOnlyMode
520
520
}
521
521
}
522
- err := s .checkPlacementPolicyBeforeCommit ()
522
+ err := s .checkPlacementPolicyBeforeCommit (ctx )
523
523
if err != nil {
524
524
return err
525
525
}
@@ -795,7 +795,7 @@ func (s *session) doCommitWithRetry(ctx context.Context) error {
795
795
err = s .doCommit (ctx )
796
796
if err != nil {
797
797
// polish the Write Conflict error message
798
- newErr := s .tryReplaceWriteConflictError (err )
798
+ newErr := s .tryReplaceWriteConflictError (ctx , err )
799
799
if newErr != nil {
800
800
err = newErr
801
801
}
@@ -846,7 +846,7 @@ func (s *session) doCommitWithRetry(ctx context.Context) error {
846
846
847
847
// adds more information about the table in the error message
848
848
// precondition: oldErr is a 9007:WriteConflict Error
849
- func (s * session ) tryReplaceWriteConflictError (oldErr error ) (newErr error ) {
849
+ func (s * session ) tryReplaceWriteConflictError (ctx context. Context , oldErr error ) (newErr error ) {
850
850
if ! kv .ErrWriteConflict .Equal (oldErr ) {
851
851
return nil
852
852
}
@@ -863,19 +863,19 @@ func (s *session) tryReplaceWriteConflictError(oldErr error) (newErr error) {
863
863
if is == nil {
864
864
return nil
865
865
}
866
- newKeyTableField , ok := addTableNameInTableIDField (args [3 ], is )
866
+ newKeyTableField , ok := addTableNameInTableIDField (ctx , args [3 ], is )
867
867
if ok {
868
868
args [3 ] = newKeyTableField
869
869
}
870
- newPrimaryKeyTableField , ok := addTableNameInTableIDField (args [5 ], is )
870
+ newPrimaryKeyTableField , ok := addTableNameInTableIDField (ctx , args [5 ], is )
871
871
if ok {
872
872
args [5 ] = newPrimaryKeyTableField
873
873
}
874
874
return kv .ErrWriteConflict .FastGenByArgs (args ... )
875
875
}
876
876
877
877
// precondition: is != nil
878
- func addTableNameInTableIDField (tableIDField any , is infoschema.InfoSchema ) (enhancedMsg string , done bool ) {
878
+ func addTableNameInTableIDField (ctx context. Context , tableIDField any , is infoschema.InfoSchema ) (enhancedMsg string , done bool ) {
879
879
keyTableID , ok := tableIDField .(string )
880
880
if ! ok {
881
881
return "" , false
@@ -890,7 +890,7 @@ func addTableNameInTableIDField(tableIDField any, is infoschema.InfoSchema) (enh
890
890
return "" , false
891
891
}
892
892
var tableName string
893
- tbl , ok := is .TableByID (context . Background () , tableID )
893
+ tbl , ok := is .TableByID (ctx , tableID )
894
894
if ! ok {
895
895
tableName = "unknown"
896
896
} else {
@@ -2296,7 +2296,7 @@ func runStmt(ctx context.Context, se *session, s sqlexec.Statement) (rs sqlexec.
2296
2296
if err != nil {
2297
2297
err = se .handleAssertionFailure (ctx , err )
2298
2298
}
2299
- newErr := se .tryReplaceWriteConflictError (err )
2299
+ newErr := se .tryReplaceWriteConflictError (ctx , err )
2300
2300
if newErr != nil {
2301
2301
err = newErr
2302
2302
}
@@ -3394,12 +3394,12 @@ func InitMDLVariable(store kv.Storage) error {
3394
3394
3395
3395
// BootstrapSession bootstrap session and domain.
3396
3396
func BootstrapSession (store kv.Storage ) (* domain.Domain , error ) {
3397
- return bootstrapSessionImpl (store , createSessions )
3397
+ return bootstrapSessionImpl (context . Background (), store , createSessions )
3398
3398
}
3399
3399
3400
3400
// BootstrapSession4DistExecution bootstrap session and dom for Distributed execution test, only for unit testing.
3401
3401
func BootstrapSession4DistExecution (store kv.Storage ) (* domain.Domain , error ) {
3402
- return bootstrapSessionImpl (store , createSessions4DistExecution )
3402
+ return bootstrapSessionImpl (context . Background (), store , createSessions4DistExecution )
3403
3403
}
3404
3404
3405
3405
// bootstrapSessionImpl bootstraps session and domain.
@@ -3414,8 +3414,8 @@ func BootstrapSession4DistExecution(store kv.Storage) (*domain.Domain, error) {
3414
3414
// - initialization global variables from system table that's required to use sessionCtx,
3415
3415
// such as system time zone
3416
3416
// - start domain and other routines.
3417
- func bootstrapSessionImpl (store kv.Storage , createSessionsImpl func (store kv.Storage , cnt int ) ([]* session , error )) (* domain.Domain , error ) {
3418
- ctx : = kv .WithInternalSourceType (context . Background () , kv .InternalTxnBootstrap )
3417
+ func bootstrapSessionImpl (ctx context. Context , store kv.Storage , createSessionsImpl func (store kv.Storage , cnt int ) ([]* session , error )) (* domain.Domain , error ) {
3418
+ ctx = kv .WithInternalSourceType (ctx , kv .InternalTxnBootstrap )
3419
3419
cfg := config .GetGlobalConfig ()
3420
3420
if len (cfg .Instance .PluginLoad ) > 0 {
3421
3421
err := plugin .Load (context .Background (), plugin.Config {
@@ -3505,7 +3505,7 @@ func bootstrapSessionImpl(store kv.Storage, createSessionsImpl func(store kv.Sto
3505
3505
}
3506
3506
3507
3507
// To deal with the location partition failure caused by inconsistent NewCollationEnabled values(see issue #32416).
3508
- rebuildAllPartitionValueMapAndSorted (ses [0 ])
3508
+ rebuildAllPartitionValueMapAndSorted (ctx , ses [0 ])
3509
3509
3510
3510
// We should make the load bind-info loop before other loops which has internal SQL.
3511
3511
// Because the internal SQL may access the global bind-info handler. As the result, the data race occurs here as the
@@ -4136,7 +4136,7 @@ func (s *session) recordOnTransactionExecution(err error, counter int, duration
4136
4136
}
4137
4137
}
4138
4138
4139
- func (s * session ) checkPlacementPolicyBeforeCommit () error {
4139
+ func (s * session ) checkPlacementPolicyBeforeCommit (ctx context. Context ) error {
4140
4140
var err error
4141
4141
// Get the txnScope of the transaction we're going to commit.
4142
4142
txnScope := s .GetSessionVars ().TxnCtx .TxnScope
@@ -4154,7 +4154,7 @@ func (s *session) checkPlacementPolicyBeforeCommit() error {
4154
4154
tableName = tblInfo .Meta ().Name .String ()
4155
4155
partitionName = partInfo .Name .String ()
4156
4156
} else {
4157
- tblInfo , _ := is .TableByID (s . currentCtx , physicalTableID )
4157
+ tblInfo , _ := is .TableByID (ctx , physicalTableID )
4158
4158
tableName = tblInfo .Meta ().Name .String ()
4159
4159
}
4160
4160
bundle , ok := is .PlacementBundleByPhysicalTableID (physicalTableID )
0 commit comments