Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

domain: save action type directly instead of left shift it #39660

Merged
merged 13 commits into from
Dec 7, 2022
17 changes: 11 additions & 6 deletions session/schema_amender.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"encoding/hex"
"fmt"
"golang.org/x/exp/slices"
hawkingrei marked this conversation as resolved.
Show resolved Hide resolved
"reflect"

"github.com/pingcap/errors"
Expand All @@ -42,10 +43,6 @@ import (
"go.uber.org/zap"
)

const amendableType = nonMemAmendType | memBufAmendType
const nonMemAmendType = (1 << model.ActionAddColumn) | (1 << model.ActionDropColumn) | (1 << model.ActionDropIndex)
const memBufAmendType = uint64(1<<model.ActionAddIndex) | (1 << model.ActionModifyColumn)

// Amend operation types.
const (
AmendNone int = iota
Expand Down Expand Up @@ -657,13 +654,21 @@ func (s *SchemaAmender) AmendTxn(ctx context.Context, startInfoSchema tikv.Schem
infoSchemaAtStart := startInfoSchema.(infoschema.InfoSchema)
infoSchemaAtCheck := change.LatestInfoSchema.(infoschema.InfoSchema)

var amendableType = []uint64{
uint64(model.ActionAddColumn),
uint64(model.ActionDropColumn),
uint64(model.ActionDropIndex),
uint64(model.ActionAddIndex),
uint64(model.ActionModifyColumn),
}

// Collect amend operations for each table by physical table ID.
var needAmendMem bool
amendCollector := newAmendCollector()
for i, tblID := range change.PhyTblIDS {
actionType := change.ActionTypes[i]
// Check amendable flags, return if not supported flags exist.
if actionType&(^amendableType) != 0 {
if !slices.Contains(amendableType, actionType) {
Defined2014 marked this conversation as resolved.
Show resolved Hide resolved
logutil.Logger(ctx).Info("amend action type not supported for txn", zap.Int64("tblID", tblID), zap.Uint64("actionType", actionType))
return nil, errors.Trace(table.ErrUnsupportedOp)
}
Expand All @@ -681,7 +686,7 @@ func (s *SchemaAmender) AmendTxn(ctx context.Context, startInfoSchema tikv.Schem
if !ok {
return nil, errors.Trace(errors.Errorf("tableID=%d is not found in infoSchema", tblID))
}
if actionType&(memBufAmendType) != 0 {
if actionType == uint64(model.ActionAddIndex) || actionType == uint64(model.ActionModifyColumn) {
needAmendMem = true
err := amendCollector.collectTblAmendOps(s.sess, tblID, tblInfoAtStart, tblInfoAtCommit, actionType)
if err != nil {
Expand Down