Skip to content

Commit

Permalink
ddl: add comment for onRebaseAutoID (pingcap#10206)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored and winkyao committed Apr 28, 2019
1 parent 7611a7d commit 5f03462
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,11 @@ func (d *ddl) RebaseAutoID(ctx sessionctx.Context, ident ast.Ident, newBase int6
if err != nil {
return errors.Trace(err)
}
// If newBase < autoIncID, we need to do a rebase before returning.
// Assume there are 2 TiDB servers: TiDB-A with allocator range of 0 ~ 30000; TiDB-B with allocator range of 30001 ~ 60000.
// If the user sends SQL `alter table t1 auto_increment = 100` to TiDB-B,
// and TiDB-B finds 100 < 30001 but returns without any handling,
// then TiDB-A may still allocate 99 for auto_increment column. This doesn't make sense for the user.
newBase = mathutil.MaxInt64(newBase, autoIncID)
job := &model.Job{
SchemaID: schema.ID,
Expand Down
1 change: 1 addition & 0 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ func onRebaseAutoID(store kv.Storage, t *meta.Meta, job *model.Job) (ver int64,
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
}
// No need to check `newBase` again, because `RebaseAutoID` will do this check.
tblInfo.AutoIncID = newBase
tbl, err := getTable(store, schemaID, tblInfo)
if err != nil {
Expand Down

0 comments on commit 5f03462

Please sign in to comment.