-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
ddl: validate table info before doing ddl job to avoid load infoschema error #10464
Merged
+78
−7
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d2308fc
ddl: validate table info before do ddl job to avoid load infoschema e…
crazycs520 3f8fa03
Merge branch 'master' into validate_table_info
crazycs520 f946c9e
refine code
crazycs520 0485b1f
add test
crazycs520 73dc27d
refine comments
crazycs520 a6d6ef9
Address comment
crazycs520 8a2387c
Address comment
crazycs520 e9db988
Merge branch 'master' into validate_table_info
crazycs520 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1057,6 +1057,11 @@ func (d *ddl) CreateTableWithLike(ctx sessionctx.Context, ident, referIdent ast. | |
return errors.Trace(err) | ||
} | ||
|
||
func checkTableInfoValid(tblInfo *model.TableInfo) error { | ||
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 need to add comments for it? |
||
_, err := tables.TableFromMeta(nil, tblInfo) | ||
return err | ||
} | ||
|
||
func buildTableInfoWithLike(ident ast.Ident, referTblInfo *model.TableInfo) model.TableInfo { | ||
tblInfo := *referTblInfo | ||
// Check non-public column and adjust column offset. | ||
|
@@ -1191,6 +1196,12 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e | |
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
tbInfo.State = model.StatePublic | ||
err = checkTableInfoValid(tbInfo) | ||
if err != nil { | ||
return err | ||
} | ||
tbInfo.State = model.StateNone | ||
|
||
job := &model.Job{ | ||
SchemaID: schema.ID, | ||
|
@@ -2153,6 +2164,19 @@ func (d *ddl) DropColumn(ctx sessionctx.Context, ti ast.Ident, colName model.CIS | |
return errUnsupportedPKHandle | ||
} | ||
|
||
// Clone table info to avoid change memory schema. | ||
checkTblInfo := tblInfo.Clone() | ||
adjustColumnInfoInDropColumn(checkTblInfo, col.Offset) | ||
checkCol := model.FindColumnInfo(checkTblInfo.Columns, colName.L) | ||
if checkCol == nil { | ||
return ErrCantDropFieldOrKey.GenWithStack("column %s doesn't exist", colName) | ||
} | ||
checkCol.State = model.StateWriteOnly | ||
err = checkTableInfoValid(checkTblInfo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
job := &model.Job{ | ||
SchemaID: schema.ID, | ||
TableID: t.Meta().ID, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we should check if the tableInfo valid before we overwrite the tableInfo in TiKV.
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.
done. PTAL
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.
We have added
check
on line 265, why do it again?