Skip to content

Commit db318b8

Browse files
authored
session: fix bootstrap panic when upgrading to master (#56517) (#56616)
close #56489
1 parent 8516d55 commit db318b8

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

pkg/session/bootstrap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,7 +3561,7 @@ func oldPasswordUpgrade(pass string) (string, error) {
35613561
}
35623562

35633563
// rebuildAllPartitionValueMapAndSorted rebuilds all value map and sorted info for list column partitions with InfoSchema.
3564-
func rebuildAllPartitionValueMapAndSorted(s *session) {
3564+
func rebuildAllPartitionValueMapAndSorted(ctx context.Context, s *session) {
35653565
type partitionExpr interface {
35663566
PartitionExpr() *tables.PartitionExpr
35673567
}
@@ -3575,7 +3575,7 @@ func rebuildAllPartitionValueMapAndSorted(s *session) {
35753575
if pi == nil || pi.Type != model.PartitionTypeList {
35763576
continue
35773577
}
3578-
tbl, ok := is.TableByID(s.currentCtx, t.ID)
3578+
tbl, ok := is.TableByID(ctx, t.ID)
35793579
intest.Assert(ok, "table not found in infoschema")
35803580
pe := tbl.(partitionExpr).PartitionExpr()
35813581
for _, cp := range pe.ColPrunes {

pkg/session/session.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ func (s *session) doCommit(ctx context.Context) error {
519519
return plannererrors.ErrSQLInReadOnlyMode
520520
}
521521
}
522-
err := s.checkPlacementPolicyBeforeCommit()
522+
err := s.checkPlacementPolicyBeforeCommit(ctx)
523523
if err != nil {
524524
return err
525525
}
@@ -795,7 +795,7 @@ func (s *session) doCommitWithRetry(ctx context.Context) error {
795795
err = s.doCommit(ctx)
796796
if err != nil {
797797
// polish the Write Conflict error message
798-
newErr := s.tryReplaceWriteConflictError(err)
798+
newErr := s.tryReplaceWriteConflictError(ctx, err)
799799
if newErr != nil {
800800
err = newErr
801801
}
@@ -846,7 +846,7 @@ func (s *session) doCommitWithRetry(ctx context.Context) error {
846846

847847
// adds more information about the table in the error message
848848
// 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) {
850850
if !kv.ErrWriteConflict.Equal(oldErr) {
851851
return nil
852852
}
@@ -863,19 +863,19 @@ func (s *session) tryReplaceWriteConflictError(oldErr error) (newErr error) {
863863
if is == nil {
864864
return nil
865865
}
866-
newKeyTableField, ok := addTableNameInTableIDField(args[3], is)
866+
newKeyTableField, ok := addTableNameInTableIDField(ctx, args[3], is)
867867
if ok {
868868
args[3] = newKeyTableField
869869
}
870-
newPrimaryKeyTableField, ok := addTableNameInTableIDField(args[5], is)
870+
newPrimaryKeyTableField, ok := addTableNameInTableIDField(ctx, args[5], is)
871871
if ok {
872872
args[5] = newPrimaryKeyTableField
873873
}
874874
return kv.ErrWriteConflict.FastGenByArgs(args...)
875875
}
876876

877877
// 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) {
879879
keyTableID, ok := tableIDField.(string)
880880
if !ok {
881881
return "", false
@@ -890,7 +890,7 @@ func addTableNameInTableIDField(tableIDField any, is infoschema.InfoSchema) (enh
890890
return "", false
891891
}
892892
var tableName string
893-
tbl, ok := is.TableByID(context.Background(), tableID)
893+
tbl, ok := is.TableByID(ctx, tableID)
894894
if !ok {
895895
tableName = "unknown"
896896
} else {
@@ -2296,7 +2296,7 @@ func runStmt(ctx context.Context, se *session, s sqlexec.Statement) (rs sqlexec.
22962296
if err != nil {
22972297
err = se.handleAssertionFailure(ctx, err)
22982298
}
2299-
newErr := se.tryReplaceWriteConflictError(err)
2299+
newErr := se.tryReplaceWriteConflictError(ctx, err)
23002300
if newErr != nil {
23012301
err = newErr
23022302
}
@@ -3394,12 +3394,12 @@ func InitMDLVariable(store kv.Storage) error {
33943394

33953395
// BootstrapSession bootstrap session and domain.
33963396
func BootstrapSession(store kv.Storage) (*domain.Domain, error) {
3397-
return bootstrapSessionImpl(store, createSessions)
3397+
return bootstrapSessionImpl(context.Background(), store, createSessions)
33983398
}
33993399

34003400
// BootstrapSession4DistExecution bootstrap session and dom for Distributed execution test, only for unit testing.
34013401
func BootstrapSession4DistExecution(store kv.Storage) (*domain.Domain, error) {
3402-
return bootstrapSessionImpl(store, createSessions4DistExecution)
3402+
return bootstrapSessionImpl(context.Background(), store, createSessions4DistExecution)
34033403
}
34043404

34053405
// bootstrapSessionImpl bootstraps session and domain.
@@ -3414,8 +3414,8 @@ func BootstrapSession4DistExecution(store kv.Storage) (*domain.Domain, error) {
34143414
// - initialization global variables from system table that's required to use sessionCtx,
34153415
// such as system time zone
34163416
// - 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)
34193419
cfg := config.GetGlobalConfig()
34203420
if len(cfg.Instance.PluginLoad) > 0 {
34213421
err := plugin.Load(context.Background(), plugin.Config{
@@ -3505,7 +3505,7 @@ func bootstrapSessionImpl(store kv.Storage, createSessionsImpl func(store kv.Sto
35053505
}
35063506

35073507
// To deal with the location partition failure caused by inconsistent NewCollationEnabled values(see issue #32416).
3508-
rebuildAllPartitionValueMapAndSorted(ses[0])
3508+
rebuildAllPartitionValueMapAndSorted(ctx, ses[0])
35093509

35103510
// We should make the load bind-info loop before other loops which has internal SQL.
35113511
// 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
41364136
}
41374137
}
41384138

4139-
func (s *session) checkPlacementPolicyBeforeCommit() error {
4139+
func (s *session) checkPlacementPolicyBeforeCommit(ctx context.Context) error {
41404140
var err error
41414141
// Get the txnScope of the transaction we're going to commit.
41424142
txnScope := s.GetSessionVars().TxnCtx.TxnScope
@@ -4154,7 +4154,7 @@ func (s *session) checkPlacementPolicyBeforeCommit() error {
41544154
tableName = tblInfo.Meta().Name.String()
41554155
partitionName = partInfo.Name.String()
41564156
} else {
4157-
tblInfo, _ := is.TableByID(s.currentCtx, physicalTableID)
4157+
tblInfo, _ := is.TableByID(ctx, physicalTableID)
41584158
tableName = tblInfo.Meta().Name.String()
41594159
}
41604160
bundle, ok := is.PlacementBundleByPhysicalTableID(physicalTableID)

0 commit comments

Comments
 (0)