Skip to content

Rebase auto increment not executed after second restore #60804

Closed

Description

@3pointer

Bug Report

In the restore process, if the first restore fails but leaves partial table structures in the cluster, and the second restore uses OnExistIgnore, those pre-existing tables will be skipped.

As a result, row_id rebase is not executed for these tables, leading to incorrect auto-increment behavior.

The root cause is that batchCreateTables is not atomic.

tbInfo, err := createTable(d, t, stubJob, fkCheck)

Some table could become public while the whole Create Tables job still on going.

1. Minimal reproduce step (Required)

  1. doing a restore with batch tables.
  2. random kill restore process, try to make createTables partial succeed.

2. What did you expect to see? (Required)

All tables in the createTables batch should either be created successfully together or fail entirely — there should be no partial success.

3. What did you see instead (Required)

After the restore process exited, some tables from the batch were still present, indicating a partial creation.

4. What is your TiDB version? (Required)

v7.5.5

Activity

  1. self-assigned this
    on Apr 25, 2025
  2. D3Hunter commented on May 8, 2025

    @D3Hunter
    Contributor

    suppose we are creating 2 tables using batchCreateTables, we create the metakv of first table success on owner, but the second table already exists, we will mark the whole job as cancelled

    retryable, err := checkTableForeignKeyValidInOwner(jobCtx, job, tbInfo, fkCheck)
    if err != nil {
    if !retryable {
    job.State = model.JobStateCancelled
    }
    return tbInfo, errors.Trace(err)
    }

    and then we commit the transaction, so metakv of the first table is commited

    tidb/pkg/ddl/job_worker.go

    Lines 622 to 626 in f030b63

    if job.IsCancelled() {
    defer jobCtx.unlockSchemaVersion(jobCtx, job.ID)
    w.sess.Reset()
    return 0, w.handleJobDone(jobCtx, job)
    }

    then on executor part, we return directly, without running createTableWithInfoPost for any table

    tidb/pkg/ddl/executor.go

    Lines 1303 to 1317 in f030b63

    err = e.DoDDLJobWrapper(ctx, jobW)
    if err != nil {
    // table exists, but if_not_exists flags is true, so we ignore this error.
    if c.OnExist == OnExistIgnore && infoschema.ErrTableExists.Equal(err) {
    ctx.GetSessionVars().StmtCtx.AppendNote(err)
    err = nil
    }
    return errors.Trace(err)
    }
    for _, tblArgs := range args.Tables {
    if err = e.createTableWithInfoPost(ctx, tblArgs.TableInfo, jobW.SchemaID); err != nil {
    return errors.Trace(err)
    }
    }

  3. joechenrh commented on Jul 18, 2025

    @joechenrh
    Contributor

    batch create tables is added before 6.1
    /label affects-8.5
    /label affects-8.1
    /label affects-7.5
    /label affects-7.1
    /label affects-6.5
    /label affects-6.1

  4. added
    affects-8.5This bug affects the 8.5.x(LTS) versions.
    affects-8.1This bug affects the 8.1.x(LTS) versions.
    on Jul 18, 2025
  5. 5 remaining items

  6. ti-chi-bot commented on Jul 18, 2025

    @ti-chi-bot

    @joechenrh: The label(s) affects-6.1 cannot be applied. These labels are supported: fuzz/sqlancer, fuzz/comp, challenge-program, compatibility-breaker, first-time-contributor, contribution, good first issue, correctness, duplicate, proposal, security, needs-more-info, needs-cherry-pick-release-6.5, needs-cherry-pick-release-7.1, needs-cherry-pick-release-7.5, needs-cherry-pick-release-8.1, needs-cherry-pick-release-8.5, needs-cherry-pick-release-9.0-beta.2, affects-6.5, affects-7.1, affects-7.5, affects-8.1, affects-8.5, affects-9.0, may-affects-6.5, may-affects-7.1, may-affects-7.5, may-affects-8.1, may-affects-8.5.

    Details

    In response to this:

    batch create tables is added before 6.1
    /label affects-8.5
    /label affects-8.1
    /label affects-7.5
    /label affects-7.1
    /label affects-6.5
    /label affects-6.1

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

  7. joechenrh commented on Jul 18, 2025

    @joechenrh
    Contributor

    /remove-label may-affects-6.1

  8. ti-chi-bot commented on Jul 18, 2025

    @ti-chi-bot

    @joechenrh: The label(s) may-affects-6.1 cannot be applied. These labels are supported: fuzz/sqlancer, fuzz/comp, challenge-program, compatibility-breaker, first-time-contributor, contribution, good first issue, correctness, duplicate, proposal, security, needs-more-info, needs-cherry-pick-release-6.5, needs-cherry-pick-release-7.1, needs-cherry-pick-release-7.5, needs-cherry-pick-release-8.1, needs-cherry-pick-release-8.5, needs-cherry-pick-release-9.0-beta.2, affects-6.5, affects-7.1, affects-7.5, affects-8.1, affects-8.5, affects-9.0, may-affects-6.5, may-affects-7.1, may-affects-7.5, may-affects-8.1, may-affects-8.5.

    Details

    In response to this:

    /remove-label may-affects-6.1

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

  9. added a commit that references this issue on Jul 23, 2025
    a50e1a9
  10. added a commit that references this issue on Aug 10, 2025
    443f0eb
  11. added a commit that references this issue on Nov 28, 2025
    ac0fc22
  12. added a commit that references this issue on Dec 8, 2025
    45b6429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.component/ddlThis issue is related to DDL of TiDB.severity/majortype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions