Skip to content
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

Merged
merged 25 commits into from
Mar 24, 2022
Merged

Conversation

docsir
Copy link
Contributor

@docsir docsir commented Feb 23, 2022

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

  • Unit test
  • Integration test

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Feb 23, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • lance6716
  • lichunzhu

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 23, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Feb 23, 2022

@lichunzhu lichunzhu added the component/dumpling This is related to Dumpling of TiDB. label Mar 2, 2022
@lichunzhu
Copy link
Contributor

Is this ready for review?

@docsir docsir closed this Mar 2, 2022
@docsir docsir reopened this Mar 2, 2022
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 2, 2022
showCreateView string
avgRowLength uint64
hasImplicitRowID bool
showCreateSequence string
Copy link
Contributor

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

@@ -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
Copy link
Contributor

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

dumpling/export/sql.go Outdated Show resolved Hide resolved
@@ -34,6 +34,14 @@ type TaskViewMeta struct {
CreateViewSQL string
}

// TaskSequenceMeta is a dumping sequence metadata task
type TaskSequenceMeta struct {
Copy link
Contributor

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?

Copy link
Contributor

@lichunzhu lichunzhu left a 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?

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)
Copy link
Contributor

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.

Copy link
Contributor

@lichunzhu lichunzhu Mar 23, 2022

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`;

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 23, 2022
@@ -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) {
Copy link
Contributor

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

Copy link
Contributor

@lichunzhu lichunzhu left a 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!!

return "", err
}
nextNotCachedValue, _ = strconv.ParseInt(oneRow1, 10, 64)
fmt.Fprintf(&createSequenceSQL, "DO SETVAL(`%s`,%d);\n", escapeString(sequence), nextNotCachedValue)
Copy link
Contributor

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?

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 24, 2022
@lichunzhu
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: bf086cf

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 24, 2022
@ti-chi-bot
Copy link
Member

@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.

@ti-chi-bot ti-chi-bot merged commit 5a17604 into pingcap:master Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/dumpling This is related to Dumpling of TiDB. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support dumping sequences
5 participants