From 5f03462166c976ca2a229f00b8ae5e2c6c102fbd Mon Sep 17 00:00:00 2001 From: crazycs Date: Sun, 28 Apr 2019 10:52:04 +0800 Subject: [PATCH] ddl: add comment for onRebaseAutoID (#10206) --- ddl/ddl_api.go | 5 +++++ ddl/table.go | 1 + 2 files changed, 6 insertions(+) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index d49b228c46677..d8e96e056d206 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -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, diff --git a/ddl/table.go b/ddl/table.go index 225a11208a62b..cec8c7ca07a8e 100644 --- a/ddl/table.go +++ b/ddl/table.go @@ -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 {