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

*: add function flashback database #30217

Merged
merged 0 commits into from
Aug 19, 2022

Conversation

erwadba
Copy link
Contributor

@erwadba erwadba commented Nov 29, 2021

What problem does this PR solve?

Issue Number: close #20463

Problem Summary:

What is changed and how it works?

  1. Add RecoverSchemaInfo struct contains SchemaInfo and TableInfo.
  2. Add recoverSchema code logical like the recovertable .

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
mysql> drop database m;
Query OK, 0 rows affected (0.43 sec)
mysql> create database m;
Query OK, 0 rows affected (0.20 sec)
mysql> use m;
Database changed
mysql> CREATE TABLE t(id int PRIMARY KEY AUTO_INCREMENT, c int);
Query OK, 0 rows affected (0.19 sec)
mysql> INSERT INTO t(c) VALUES (1);
Query OK, 1 row affected (0.03 sec)
mysql> INSERT INTO t(c) VALUES (2);
Query OK, 1 row affected (0.01 sec)
mysql> drop database m;
Query OK, 0 rows affected (0.42 sec)
mysql> flashback database m;
Query OK, 0 rows affected (0.97 sec)
mysql> use m ;
Database changed
mysql> select * from t;
+----+------+
| id | c    |
+----+------+
|  1 |    1 |
|  2 |    2 |
+----+------+
2 rows in set (0.01 sec)
mysql>

Side effects

  • N/A

Documentation

  • N/A

Release note

Add support `flashback database` command.

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Nov 29, 2021
@tangenta
Copy link
Contributor

/cc @crazycs520

@bb7133 bb7133 added sig/sql-infra SIG: SQL Infra type/new-feature require-LGT3 Indicates that the PR requires three LGTM. labels Dec 1, 2021
ddl/ddl_api.go Outdated
Args: []interface{}{recoverSchemaInfo.SchemaInfo, recoverSchemaInfo.RecoversInfo,
recoverSchemaInfo.DropJobID, recoverSchemaInfo.SnapshotTS, recoverSchemaInfo.OldSchemaName},
}
err = d.doDDLJob(ctx, job)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please handle the error here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to handle error in here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erwadba Please address this comment

executor/ddl.go Outdated Show resolved Hide resolved
@bb7133
Copy link
Member

bb7133 commented Dec 1, 2021

Please add some more test cases for your feature.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 1, 2021
@bb7133
Copy link
Member

bb7133 commented Dec 1, 2021

Please fix the lint checking(https://ci.pingcap.net/blue/organizations/jenkins/tidb_ghpr_check/detail/tidb_ghpr_check/36907/pipeline):

[2021-11-30T01:45:41.313Z] ddl/schema.go:312:17: Error return value is not checked (errcheck)
[2021-11-30T01:45:41.313Z] 		defer enableGC(w)
[2021-11-30T01:45:41.313Z] 		              ^
[2021-11-30T01:45:41.313Z] ddl/schema.go:346:9: ineffectual assignment to err (ineffassign)
[2021-11-30T01:45:41.313Z] 			ver, err = updateVersionAndTableInfo(t, job, recoverInfo.TableInfo, false)
[2021-11-30T01:45:41.313Z] 			     ^
[2021-11-30T01:45:41.313Z] level=info msg="File cache stats: 1341 entries of total size 21.8MiB"
[2021-11-30T01:45:41.313Z] level=info msg="Memory: 1578 samples, avg is 2342.1MB, max is 9654.6MB"
[2021-11-30T01:45:41.313Z] level=info msg="Execution took 2m43.233059097s"

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 2, 2021
@erwadba
Copy link
Contributor Author

erwadba commented Dec 3, 2021

/cc @bb7133 @crazycs520
PTAL

@erwadba
Copy link
Contributor Author

erwadba commented Dec 6, 2021

/cc @bb7133 @crazycs520
PTAL

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 9, 2021
@bb7133
Copy link
Member

bb7133 commented Dec 10, 2021

@erwadba Sorry that I missed this PR before, I will try to review it recently.

@easonn7
Copy link

easonn7 commented Dec 10, 2021

LGTM,but this feature should be designed under BR system, so please add BR PM and reviewed with LGTM.

executor/ddl.go Outdated Show resolved Hide resolved
executor/ddl.go Outdated Show resolved Hide resolved
executor/ddl.go Outdated Show resolved Hide resolved
ddl/schema.go Outdated Show resolved Hide resolved
ddl/schema.go Outdated Show resolved Hide resolved
ddl/schema.go Outdated
Comment on lines 358 to 361
ver, err = updateVersionAndTableInfo(t, job, recoverInfo.TableInfo, false)
if err != nil {
return ver, errors.Trace(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ver, err = updateVersionAndTableInfo(t, job, recoverInfo.TableInfo, false)
if err != nil {
return ver, errors.Trace(err)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should only update schema version once in this situation. the related schema change should be set in updateSchemaVersion, related with the comment: https://github.com/pingcap/tidb/pull/30217/files#r767778383

ddl/schema.go Outdated
Comment on lines 363 to 367
schemaInfo.State = model.StatePublic
err = t.UpdateDatabase(schemaInfo)
if err != nil {
return ver, errors.Trace(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
schemaInfo.State = model.StatePublic
err = t.UpdateDatabase(schemaInfo)
if err != nil {
return ver, errors.Trace(err)
}

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 create database with public state, then no need update schema info here.

@erwadba
Copy link
Contributor Author

erwadba commented Dec 18, 2021

/run-unit-test

1 similar comment
@erwadba
Copy link
Contributor Author

erwadba commented Dec 18, 2021

/run-unit-test

@sre-bot
Copy link
Contributor

sre-bot commented Dec 18, 2021

parser/ast/ddl_test.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
ddl/ddl_worker.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
ddl/ddl_api.go Outdated Show resolved Hide resolved
tids, err = b.applyCreateTable(m, di, tblInfo.ID, allocs, diff.Type, tids)
if err != nil {
return errors.Trace(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need applyPlacementUpdate for each table?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erwadba Please check this comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xhebox Could you give some advice?

@@ -1066,6 +1090,7 @@ func updateSchemaVersion(t *meta.Meta, job *model.Job) (int64, error) {
diff.AffectedOpts = buildPlacementAffects(oldIDs, oldIDs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @djshow832 I'm not sure whether ActionRecoverSchema ddl job need this to update placement rule cache, PTAL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lcwangchao Do we implement it in this PR or not? I think we could recover placement rules without much problem..

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @djshow832 PTAL, some part about placement rule, I'm not familiar with it.

@erwadba
Copy link
Contributor Author

erwadba commented Dec 30, 2021

/run-unit-test

@ti-chi-bot
Copy link
Member

@erwadba: PR needs rebase.

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 kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 31, 2021
@bb7133
Copy link
Member

bb7133 commented Jan 19, 2022

Hi @erwadba Could you please resolve the conflicts? Thanks.

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 25, 2022
@erwadba
Copy link
Contributor Author

erwadba commented Jan 26, 2022

/cc @bb7133
PTAL

Copy link
Member

@wjhuang2016 wjhuang2016 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve all the comments

@erwadba
Copy link
Contributor Author

erwadba commented Jan 26, 2022

/run-all-tests

@erwadba
Copy link
Contributor Author

erwadba commented Jan 27, 2022

/cc @bb7133 @wjhuang2016
PTAL

ddl/ddl_api.go Outdated
SchemaID: recoverSchemaInfo.SchemaInfo.ID,
Type: model.ActionRecoverSchema,
BinlogInfo: &model.HistoryInfo{},
Args: []interface{}{recoverSchemaInfo, recoverCheckFlagNone},
}
err = d.doDDLJob(ctx, job)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = d.doDDLJob(ctx, job)
err = d.doDDLJob(ctx, job)
if err != nil {
return err
}

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 28, 2022
@ti-chi-bot
Copy link
Member

@erwadba: PR needs rebase.

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 kubernetes/test-infra repository.

@erwadba erwadba merged commit d1f75f0 into pingcap:master Aug 19, 2022
@bb7133
Copy link
Member

bb7133 commented Aug 26, 2022

Hi @erwadba , this PR has been closed(due to a bug of Github, I believe), would you like to file another PR and we could work on it?

@erwadba
Copy link
Contributor Author

erwadba commented Aug 29, 2022

Too many files conflicts,open another pr #37438. Another problem is here when exec flashback #37386

@erwadba erwadba deleted the add_flashback_database branch September 2, 2022 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. require-LGT3 Indicates that the PR requires three LGTM. sig/sql-infra SIG: SQL Infra size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/new-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FLASHBACK DATABASE command in feature
10 participants