-
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: Implement TableMode feature #59009
Open
fishiu
wants to merge
28
commits into
pingcap:master
Choose a base branch
from
fishiu:tablemode
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
ea28019
init, currently no tests
fishiu 01d2e1f
fix some small problems, add comments
fishiu be92a6e
test alter table mode
fishiu 3a03551
AlterTableMode directly use JobVersion2
fishiu 56555c8
part of test, will have more. and will refine code later
fishiu 7143444
TestCreateTableWithModeInfo
fishiu 8d8b540
add new proper error code
fishiu 107017b
fix error message missing param
fishiu 996e5dd
remove an idiot todo
fishiu db34e54
modify createTable comments about mode consistency problem
fishiu 0f380aa
Merge branch 'master' into tablemode
fishiu 30310fb
typo
fishiu 1bf6658
fix bazel
fishiu 2cc27f6
fix bdr.go
fishiu d412aec
fix variable comment
fishiu d9cc5c7
move some tests from table_test.go into table_mode_test.go
fishiu 457331d
fix ineffassign
fishiu d4d4a1f
fix ineffassign
fishiu 68f1504
better error info and comment, fix several ineffassign
fishiu 801ad58
fix ineffassign and go import
fishiu fb868b3
fix meta test
fishiu 5910798
fix schemainfo integration test result (column 26->27)
fishiu 639c92f
add concurrency test
fishiu ffa0f25
fix format
fishiu 564ee92
fix integration test result related to infoschema
fishiu 68fd4e0
update errors.toml
fishiu 4472686
remove todo
fishiu 572e3f8
Copyright typo
fishiu 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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
fishiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ddl | ||
|
||
import ( | ||
"fmt" | ||
"github.com/pingcap/tidb/pkg/infoschema" | ||
"github.com/pingcap/tidb/pkg/meta/model" | ||
) | ||
|
||
// onAlterTableMode should only be called by alterTableMode, will call updateVersionAndTableInfo | ||
func onAlterTableMode(jobCtx *jobContext, job *model.Job) (ver int64, err error) { | ||
args, err := model.GetAlterTableModeArgs(job) | ||
var tbInfo *model.TableInfo | ||
metaMut := jobCtx.metaMut | ||
tbInfo, err = GetTableInfoAndCancelFaultJob(metaMut, job, job.SchemaID) | ||
if err != nil { | ||
return ver, err | ||
} | ||
|
||
switch tbInfo.TableMode { | ||
case model.TableModeNormal, model.TableModeImport, model.TableModeRestore: | ||
// directly change table mode to target mode | ||
err = alterTableMode(tbInfo, args) | ||
if err != nil { | ||
job.State = model.JobStateCancelled | ||
} else { | ||
// update table info and schema version | ||
ver, err = updateVersionAndTableInfo(jobCtx, job, tbInfo, true) | ||
job.FinishTableJob(model.JobStateDone, model.StatePublic, ver, tbInfo) // TODO: change of schema state | ||
} | ||
default: | ||
job.State = model.JobStateCancelled | ||
err = infoschema.ErrTableModeInvalidTransition.GenWithStackByArgs( | ||
fmt.Sprintf("invalid transition from '%s' to '%s'", tbInfo.TableMode, args.TableMode), | ||
) | ||
} | ||
|
||
return ver, err | ||
} | ||
|
||
// alterTableMode first checks if the change is valid and changes table mode to target mode | ||
func alterTableMode(tbInfo *model.TableInfo, args *model.AlterTableModeArgs) error { | ||
// currently we can assume args.TableMode will not be model.TableModeRestore | ||
if args.TableMode == model.TableModeImport { | ||
// only transition from ModeNormal to ModeImport is allowed | ||
if tbInfo.TableMode != model.TableModeNormal { | ||
return infoschema.ErrTableModeInvalidTransition.GenWithStackByArgs( | ||
fmt.Sprintf("invalid transition from '%s' to '%s'", tbInfo.TableMode, args.TableMode), | ||
) | ||
} | ||
} | ||
tbInfo.TableMode = args.TableMode | ||
return nil | ||
} |
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
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
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
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.
maybe I'm missing something, is there a good way to alter table mode in batches? similar to op like
BatchCreateTableWithInfo
. right now we can create tables with table mode in batches but at the end of the restore we need to set tables back to normal and without batching it's probably going to be slow. thanks!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.
for sure, but we think support modify table mode for one single table as first pr is better. We will support alter table mode in batches in next pr(not difficult implement).
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.
Seems @Tristan1900 's current PR for BR requires this batch feature. I will try adding the batch DDL job soon (hopefully this Thursday).