Skip to content

Commit

Permalink
*: fix 'duplicate entry' error when using br to restore AUTO_ID_CACHE…
Browse files Browse the repository at this point in the history
…=1 tables (#44743) (#44817)

ref #38442, close #44716
  • Loading branch information
ti-chi-bot authored Jul 10, 2023
1 parent 6b60bce commit c7f1ee2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion br/pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ func BuildBackupSchemas(
case tableInfo.IsView() || !utils.NeedAutoID(tableInfo):
// no auto ID for views or table without either rowID nor auto_increment ID.
default:
globalAutoID, err = autoIDAccess.RowID().Get()
if tableInfo.SepAutoInc() {
globalAutoID, err = autoIDAccess.IncrementID(tableInfo.Version).Get()
} else {
globalAutoID, err = autoIDAccess.RowID().Get()
}
}
if err != nil {
return errors.Trace(err)
Expand Down
4 changes: 2 additions & 2 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3176,7 +3176,7 @@ func TestAutoIncrementForceAutoIDCache(t *testing.T) {
"t CREATE TABLE `t` (\n" +
" `a` int(11) NOT NULL AUTO_INCREMENT,\n" +
" PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_id_cache] AUTO_ID_CACHE=1 */"))
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=201 /*T![auto_id_cache] AUTO_ID_CACHE=1 */"))
tk.MustExec("alter table t auto_increment=100;")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Can't reset AUTO_INCREMENT to 100 without FORCE option, using 201 instead"))
tk.MustExec("insert into t values ()")
Expand All @@ -3185,7 +3185,7 @@ func TestAutoIncrementForceAutoIDCache(t *testing.T) {
"t CREATE TABLE `t` (\n" +
" `a` int(11) NOT NULL AUTO_INCREMENT,\n" +
" PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![auto_id_cache] AUTO_ID_CACHE=1 */"))
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=212 /*T![auto_id_cache] AUTO_ID_CACHE=1 */"))
tk.MustExec("drop table t")
}

Expand Down
2 changes: 1 addition & 1 deletion executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
fmt.Fprintf(buf, " COMPRESSION='%s'", tableInfo.Compression)
}

incrementAllocator := allocators.Get(autoid.RowIDAllocType)
incrementAllocator := allocators.Get(autoid.AutoIncrementType)
if hasAutoIncID && incrementAllocator != nil {
autoIncID, err := incrementAllocator.NextGlobalAutoID()
if err != nil {
Expand Down

0 comments on commit c7f1ee2

Please sign in to comment.