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: Fix unstable DROP TABLE/FLASHBACK TABLE/RECOVER TABLE #8422

Merged
merged 16 commits into from
Nov 30, 2023

Conversation

JaySon-Huang
Copy link
Contributor

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

What problem does this PR solve?

Issue Number: close #8395, close #1664, close #3777

Problem Summary:

Problem 1:
There could be a chance that raft snapshot or raft command of a table comes after it has been dropped.
Because tiflash will ignore the previous DROP TABLE, because storage instance is not created yet. The storage instance is created as "non tombstone" after that when raft snapshot or raft command comes. And the storage instance will never be physically dropped until tiflash restarts.

Problem 2:
In the second time when syncTableSchema calls trySyncTableSchema after table-id-mapping is up-to-date, it should use mvcc get to ensure it can use the table schema of tombstone table to create Storage instance or decode new raft logs, or some new columns data will not be decoded.
Previously updateTiFlashReplica will update the table info with the latest columns by accident. So tiflash pass the related tests sometimes.

CREATE TABLE t (a int, b int)
INSERT INTO t VALUES (1, 1);
ALTER TABLE t SET TIFLASH REPLICA 1;
# wait tiflash replica ready

ALTER TABLE t ADD COLUMN c int;
INSERT INTO t VALUES (1,2,3);
DROP TABLE t;

# the rows (1,2,3) comes after `drop table t` is executed in tiflash
RECOVER TABLE t; -- or FLASHBACK TABLE t

SELECT * FROM t;
# should return rows (1, 1, NULL), (1,2,3);

What is changed and how it works?

This is a PR following #8421
The logic changes is these commits: https://github.com/pingcap/tiflash/pull/8422/files/d88f6b6f4ae4c8026b969cd9c5ae50924b179529..1fe991997055f755aea89cd2e2bdb8ab26a848bf

  • In the first time when syncTableSchema calls trySyncTableSchema, it will not use mvcc get so that we can detect whether we need to update the table-id-mapping
  • In the second time when syncTableSchema calls trySyncTableSchema after table-id-mapping is up-to-date, it will use mvcc get to ensure it can use the table schema of tombstone table to create Storage instance or decode new raft logs.
  • SchemaGetter::getTableInfoImpl does not check the existence of db_key, so that we can still get the table info after database is dropped. (get ready for FLASHBACK DATABASE ... TO ...)
  • If a storage instance is created with the table info got by client-c mvcc get, then we will create the storage instance with a tombstone timestamp. So that it can be physically dropped after GC time.
  • applySetTiFlashReplica should only update the tiflash replica info instead of replacing all the table info, or it will lead to some later DDLs (changing partitions, etc) is not executed
  • Simplify recover table codes using early return

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 a potential issue that some data can not be recovered by `RECOVER TABLE` and `FLASHBACK TABLE`

@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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 26, 2023
@JaySon-Huang JaySon-Huang mentioned this pull request Nov 26, 2023
12 tasks
@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@JaySon-Huang JaySon-Huang changed the title [WIP] ddl: Fix unstable drop ddl: Fix unstable drop Nov 27, 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 Nov 27, 2023
@JaySon-Huang JaySon-Huang changed the title ddl: Fix unstable drop ddl: Fix unstable drop/flashback table Nov 27, 2023
@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. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Nov 27, 2023
@JaySon-Huang
Copy link
Contributor Author

/run-unit-test

@JaySon-Huang JaySon-Huang mentioned this pull request Nov 27, 2023
12 tasks
@JaySon-Huang JaySon-Huang changed the title ddl: Fix unstable drop/flashback table ddl: Fix unstable DROP TABLE/FLASHBACK TABLE/RECOVER TABLE Nov 27, 2023
@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

Copy link
Member

@CalvinNeo CalvinNeo left a comment

Choose a reason for hiding this comment

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

Can this pr fix #1664 ?
Seems the problem1 is #1664 (comment), and the problem2 is #1664 (comment)?

If so, please also close 1664.

Comment on lines -55 to -56
## drop table arrive tiflash before ddl and insert, and do recover, check the data is not lost
## because we want to test we actually drop the table, so please not use the same name for this table
Copy link
Contributor Author

@JaySon-Huang JaySon-Huang Nov 29, 2023

Choose a reason for hiding this comment

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

This case is moved to fullstack-test2/ddl/flashback/recover_table.test

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

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 Nov 30, 2023
Copy link
Contributor

ti-chi-bot bot commented Nov 30, 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 Nov 30, 2023
Copy link
Contributor

ti-chi-bot bot commented Nov 30, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-11-29 06:31:15.184817608 +0000 UTC m=+990703.850043803: ☑️ agreed by Lloyd-Pottiger.
  • 2023-11-30 03:24:26.486780154 +0000 UTC m=+1065895.152006351: ☑️ agreed by hongyunyan.

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot ti-chi-bot bot merged commit fbf4a35 into pingcap:master Nov 30, 2023
6 checks passed
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Nov 30, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Nov 30, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Nov 30, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Nov 30, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@JaySon-Huang JaySon-Huang deleted the fix_unstable_drop branch November 30, 2023 04:40
@JaySon-Huang JaySon-Huang removed needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. labels Nov 30, 2023
JaySon-Huang added a commit to ti-chi-bot/tiflash that referenced this pull request Nov 30, 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
5 participants