-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: Remove the check of initialized auto ID #4971
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ func (b *Builder) ApplyDiff(m *meta.Meta, diff *model.SchemaDiff) ([]int64, erro | |
// We try to reuse the old allocator, so the cached auto ID can be reused. | ||
var alloc autoid.Allocator | ||
if tableIDIsValid(oldTableID) { | ||
if oldTableID == newTableID { | ||
if oldTableID == newTableID && diff.Type != model.ActionRenameTable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can still reuse the allocator for rename table, just add a method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But, it needs to add an interface to Allocator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, skip auto ID when rename table is acceptable. |
||
alloc, _ = b.is.AllocByID(oldTableID) | ||
} | ||
if diff.Type == model.ActionRenameTable { | ||
|
@@ -162,10 +162,7 @@ func (b *Builder) applyCreateTable(m *meta.Meta, roDBInfo *model.DBInfo, tableID | |
} | ||
if alloc == nil { | ||
schemaID := roDBInfo.ID | ||
if tblInfo.OldSchemaID != 0 { | ||
schemaID = tblInfo.OldSchemaID | ||
} | ||
alloc = autoid.NewAllocator(b.handle.store, schemaID) | ||
alloc = autoid.NewAllocator(b.handle.store, tblInfo.OldSchemaID, schemaID) | ||
} | ||
tbl, err := tables.TableFromMeta(alloc, tblInfo) | ||
if err != nil { | ||
|
@@ -267,10 +264,7 @@ func (b *Builder) createSchemaTablesForDB(di *model.DBInfo) error { | |
b.is.schemaMap[di.Name.L] = schTbls | ||
for _, t := range di.Tables { | ||
schemaID := di.ID | ||
if t.OldSchemaID != 0 { | ||
schemaID = t.OldSchemaID | ||
} | ||
alloc := autoid.NewAllocator(b.handle.store, schemaID) | ||
alloc := autoid.NewAllocator(b.handle.store, t.OldSchemaID, schemaID) | ||
var tbl table.Table | ||
tbl, err := tables.TableFromMeta(alloc, t) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,18 +141,20 @@ func (m *Meta) parseTableID(key string) (int64, error) { | |
} | ||
|
||
// GenAutoTableID adds step to the auto ID of the table and returns the sum. | ||
func (m *Meta) GenAutoTableID(dbID int64, tableID int64, step int64) (int64, error) { | ||
func (m *Meta) GenAutoTableID(originalDBID, dbID, tableID, step int64) (int64, error) { | ||
// Check if DB exists. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also need to check if old db exists or not ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old db doesn't need to exist, it can be dropped. |
||
dbKey := m.dbKey(dbID) | ||
id, err := m.txn.HGet(dbKey, m.autoTableIDKey(tableID)) | ||
if err != nil { | ||
if err := m.checkDBExists(dbKey); err != nil { | ||
return 0, errors.Trace(err) | ||
} | ||
isNotExisting := len(id) == 0 | ||
if isNotExisting { | ||
return 0, kv.ErrNotExist | ||
// Check if table exists. | ||
tableKey := m.tableKey(tableID) | ||
if err := m.checkTableExists(dbKey, tableKey); err != nil { | ||
return 0, errors.Trace(err) | ||
} | ||
|
||
return m.txn.HInc(dbKey, m.autoTableIDKey(tableID), step) | ||
// Using original DB ID to generate auto ID. | ||
return m.txn.HInc(m.dbKey(originalDBID), m.autoTableIDKey(tableID), step) | ||
} | ||
|
||
// GetAutoTableID gets current auto id with table id. | ||
|
@@ -271,12 +273,6 @@ func (m *Meta) CreateTable(dbID int64, tableInfo *model.TableInfo) error { | |
return errors.Trace(err) | ||
} | ||
|
||
// Initial the auto ID key. | ||
base := []byte(strconv.FormatInt(0, 10)) | ||
err = m.txn.HSet(dbKey, m.autoTableIDKey(tableInfo.ID), base) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
return m.txn.HSet(dbKey, tableKey, data) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this result changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the change at your second question.