diff --git a/pkg/ddl/table.go b/pkg/ddl/table.go index a53946e7d7bf9..90a97822a46de 100644 --- a/pkg/ddl/table.go +++ b/pkg/ddl/table.go @@ -742,11 +742,12 @@ func onRenameTable(jobCtx *jobContext, t *meta.Meta, job *model.Job) (ver int64, return ver, errors.Trace(err) } + oldSchemaID, oldSchemaName, tableName := args.OldSchemaID, args.OldSchemaName, args.NewTableName if job.SchemaState == model.StatePublic { return finishJobRenameTable(jobCtx, t, job) } newSchemaID := job.SchemaID - err = checkTableNotExists(jobCtx.infoCache, newSchemaID, args.NewTableName.L) + err = checkTableNotExists(jobCtx.infoCache, newSchemaID, tableName.L) if err != nil { if infoschema.ErrDatabaseNotExists.Equal(err) || infoschema.ErrTableExists.Equal(err) { job.State = model.JobStateCancelled @@ -754,18 +755,18 @@ func onRenameTable(jobCtx *jobContext, t *meta.Meta, job *model.Job) (ver int64, return ver, errors.Trace(err) } - tblInfo, err := GetTableInfoAndCancelFaultJob(t, job, args.OldSchemaID) + tblInfo, err := GetTableInfoAndCancelFaultJob(t, job, oldSchemaID) if err != nil { return ver, errors.Trace(err) } oldTableName := tblInfo.Name - ver, err = checkAndRenameTables(t, job, tblInfo, args.OldSchemaID, job.SchemaID, &args.OldSchemaName, &args.NewTableName) + ver, err = checkAndRenameTables(t, job, tblInfo, oldSchemaID, job.SchemaID, &oldSchemaName, &tableName) if err != nil { return ver, errors.Trace(err) } fkh := newForeignKeyHelper() err = adjustForeignKeyChildTableInfoAfterRenameTable(jobCtx.infoCache, t, - job, &fkh, tblInfo, args.OldSchemaName, oldTableName, args.NewTableName, newSchemaID) + job, &fkh, tblInfo, oldSchemaName, oldTableName, tableName, newSchemaID) if err != nil { return ver, errors.Trace(err) } diff --git a/pkg/meta/model/job_args.go b/pkg/meta/model/job_args.go index b21fae9f6fa8b..f0442433bf369 100644 --- a/pkg/meta/model/job_args.go +++ b/pkg/meta/model/job_args.go @@ -325,7 +325,7 @@ func GetFinishedTruncateTableArgs(job *Job) (*TruncateTableArgs, error) { } func getTruncateTableArgs(job *Job, argsOfFinished bool) (*TruncateTableArgs, error) { - if job.Version <= JobVersion1 { + if job.Version == JobVersion1 { if argsOfFinished { var startKey []byte var oldPartitionIDs []int64 @@ -380,18 +380,10 @@ func GetRenameTableArgs(job *Job) (*RenameTableArgs, error) { if job.Version == JobVersion1 { // decode args and cache in args. - if len(job.Args) == 0 { - err := job.DecodeArgs(&oldSchemaID, &newTableName, &oldSchemaName) - if err != nil { - return nil, errors.Trace(err) - } - job.Args = []any{oldSchemaID, newTableName, oldSchemaName} - } else { - oldSchemaID = job.Args[0].(int64) - newTableName = job.Args[1].(pmodel.CIStr) - oldSchemaName = job.Args[2].(pmodel.CIStr) + err := job.DecodeArgs(&oldSchemaID, &newTableName, &oldSchemaName) + if err != nil { + return nil, errors.Trace(err) } - args := RenameTableArgs{ OldSchemaID: oldSchemaID, OldSchemaName: oldSchemaName, @@ -410,7 +402,7 @@ func UpdateRenameTableArgs(job *Job) error { var err error // for job version1 - if job.Version <= JobVersion1 { + if job.Version == JobVersion1 { // update schemaID and marshal() job.Args[0] = job.SchemaID job.RawArgs, err = json.Marshal(job.Args) diff --git a/pkg/meta/model/job_args_test.go b/pkg/meta/model/job_args_test.go index 14ca86a9a66dc..1235a9ddfafb3 100644 --- a/pkg/meta/model/job_args_test.go +++ b/pkg/meta/model/job_args_test.go @@ -243,18 +243,13 @@ func TestRenameTableArgs(t *testing.T) { } job.FillArgs(inArgs) - // get the args from args - args, err := GetRenameTableArgs(job) - require.NoError(t, err) - require.Equal(t, args, inArgs) - // encode job - _, err = job.Encode(true) + _, err := job.Encode(true) require.NoError(t, err) job.Args = nil // get the args after decode - args, err = GetRenameTableArgs(job) + args, err := GetRenameTableArgs(job) require.NoError(t, err) require.Equal(t, args, inArgs)