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

*: fix 'duplicate entry' error when using br to restore AUTO_ID_CACHE=1 tables #44743

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1246,7 +1246,7 @@ func constructResultOfShowCreateTable(ctx sessionctx.Context, dbName *model.CISt
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