-
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
dumpling: support dumping sequences #32570
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/b5e41930023c57c126659bae5d7e0a1cff350a49 |
Is this ready for review? |
dumpling/export/ir_impl.go
Outdated
showCreateView string | ||
avgRowLength uint64 | ||
hasImplicitRowID bool | ||
showCreateSequence string |
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.
it can be moved under showCreateView
dumpling/export/sql.go
Outdated
@@ -174,6 +174,42 @@ func ShowCreateView(tctx *tcontext.Context, db *BaseConn, database, view string) | |||
return createTableSQL.String(), createViewSQL.String(), nil | |||
} | |||
|
|||
// ShowCreateTable constructs the create table SQL for a specified table |
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.
need update comment to ShowCreateSequence
@@ -34,6 +34,14 @@ type TaskViewMeta struct { | |||
CreateViewSQL string | |||
} | |||
|
|||
// TaskSequenceMeta is a dumping sequence metadata task | |||
type TaskSequenceMeta struct { |
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.
where is this structure created?
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.
Could you please add an integration test for TiDB?
dumpling/export/sql.go
Outdated
createSequenceSQL.WriteString(";\n") | ||
|
||
query = fmt.Sprintf("SHOW TABLE `%s`.`%s` NEXT_ROW_ID", escapeString(database), escapeString(sequence)) | ||
results, err := db.QuerySQLWithColumns(tctx, []string{"NEXT_GLOBAL_ROW_ID", "ID_TYPE"}, query) |
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 use this sql only for TiDB here and we may need some other dump SQLs for MariaDB. But to me we can do this in next PR.
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 MariaDB we should use select next_not_cached_value from `%s`.`%s`;
dumpling/export/sql.go
Outdated
@@ -174,6 +174,43 @@ func ShowCreateView(tctx *tcontext.Context, db *BaseConn, database, view string) | |||
return createTableSQL.String(), createViewSQL.String(), nil | |||
} | |||
|
|||
// ShowCreateSequence constructs the create sequence SQL for a specified sequence | |||
// returns (createSequenceSQL, error) | |||
func ShowCreateSequence(tctx *tcontext.Context, db *BaseConn, database, sequence string) (string, error) { |
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.
You can put conf.ServerInfo
into this function
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.
Rest LGTM, great job!!
dumpling/export/sql.go
Outdated
return "", err | ||
} | ||
nextNotCachedValue, _ = strconv.ParseInt(oneRow1, 10, 64) | ||
fmt.Fprintf(&createSequenceSQL, "DO SETVAL(`%s`,%d);\n", escapeString(sequence), nextNotCachedValue) |
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.
Nit: Maybe use SELECT SETVAL
as TiDB?
/merge |
This pull request has been accepted and is ready to merge. Commit hash: bf086cf
|
@docsir: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: close #32538
Problem Summary: Support dumping MariaDB and TiDB sequences.
What is changed and how it works?
not finished, will fix ut and it later.
Check List
Tests
Release note