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

ddl: Support FLASHBACK DATABASE #8424

Merged
merged 12 commits into from
Dec 7, 2023

Conversation

JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Nov 27, 2023

What problem does this PR solve?

Issue Number: close #8450

Problem Summary:

tidb support FLASHBACK DATABASE DBName [TO newDBName] since v6.4.0 https://docs.pingcap.com/tidb/stable/sql-statement-flashback-database

After executing FLASHBACK DATABASE ... TO ..., the storage instances in TiFlash are not recovered as non tombstone. After the gc safepoint advanced, the storage instances will be physically drop.

What is changed and how it works?

Recover all the tables on the database when FLASHBACK DATABASE is executed.

Note that the implementation is different from that on release-7.1, release-6.5

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Fix the issue that `FLASHBACK DATABASE` is not applied to TiFlash replica data

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue 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. labels Nov 27, 2023
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 30, 2023
@JaySon-Huang JaySon-Huang changed the title ddl: Support FLASHBACK DATABASE [WIP] ddl: Support FLASHBACK DATABASE Nov 30, 2023
@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 30, 2023
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 1, 2023
@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten into flashback/flashback_database.test

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/needs-triage-completed needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. and removed release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-linked-issue do-not-merge/needs-triage-completed labels Dec 1, 2023
@JaySon-Huang JaySon-Huang changed the title [WIP] ddl: Support FLASHBACK DATABASE ddl: Support FLASHBACK DATABASE Dec 1, 2023
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 1, 2023
@JaySon-Huang JaySon-Huang removed needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. labels Dec 1, 2023
@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. labels Dec 1, 2023
Copy link
Contributor

@Lloyd-Pottiger Lloyd-Pottiger left a comment

Choose a reason for hiding this comment

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

Others LGTM

dbms/src/TiDB/Schema/SchemaBuilder.cpp Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Dec 1, 2023
@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

LOG_INFO(log, "Recover database begin, database_id={}", database_id);
auto db_name = name_mapper.mapDatabaseName(database_id, keyspace_id);
auto db = context.tryGetDatabase(db_name);
if (unlikely(!db))
Copy link
Contributor

Choose a reason for hiding this comment

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

If the db is not existed now, do we need to create the db and related tables based on it's db info?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little worried about this scenario: the customer is stuck in the gc time to do the flash back, and tiflash may receive and process it later, which may be just longer than tiflash's local gc, so the db and tables still don't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. the tombstone_ts for IDatabase and IStorage are allocated by tiflash when it receives the DROP DATABASE or DROP TABLE DDL. So the tombstone_ts are usually sliently larger than the user actually executed those DROP statements. When a user execute FLASHBACK DATABASE, those IDatabase and IStorage instance are possible not pass the gc safepoint.
  2. If those IStorage and IDatabase instance are actually get physically dropped in TiFlash instance, it is dangerous to "create" them when applying "FLASHBACK DATABASE". Because there are some rows is permanently deleted from tiflash instance. If we silently "create" them, it means the error is hard to find out but data inconsistency happens. An explicit error is better than implicit data loss.

Copy link
Contributor

@hongyunyan hongyunyan left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added the lgtm label Dec 7, 2023
Copy link
Contributor

ti-chi-bot bot commented Dec 7, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hongyunyan, Lloyd-Pottiger

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Lloyd-Pottiger,hongyunyan]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 7, 2023
Copy link
Contributor

ti-chi-bot bot commented Dec 7, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-01 13:52:31.48675992 +0000 UTC m=+1189980.151986100: ☑️ agreed by Lloyd-Pottiger.
  • 2023-12-07 02:47:37.481343317 +0000 UTC m=+1668486.146569497: ☑️ agreed by hongyunyan.

Copy link
Contributor

ti-chi-bot bot commented Dec 7, 2023

@JaySon-Huang: 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

trigger some heavy tests which will not run always when PR updated.

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.

@JaySon-Huang JaySon-Huang removed needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. labels Dec 7, 2023
@ti-chi-bot ti-chi-bot bot merged commit 3085414 into pingcap:master Dec 7, 2023
6 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #8477.

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Dec 7, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@JaySon-Huang JaySon-Huang deleted the support_flashback_database branch December 7, 2023 03:52
JaySon-Huang added a commit to ti-chi-bot/tiflash that referenced this pull request Dec 7, 2023
ti-chi-bot bot pushed a commit that referenced this pull request Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TiFlash can not prevent data being removed after FLASHBACK DATABASE
4 participants