Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

sync: return an error for rename table statement in optimistic mode #1512

Merged
merged 7 commits into from
Mar 25, 2021

Conversation

GMHDBJD
Copy link
Collaborator

@GMHDBJD GMHDBJD commented Mar 16, 2021

What problem does this PR solve?

we do not support rename table now, simply return an error in optimistic mode.
For pessimistic mode, though shardddl group was wrong, dm works well and data are still consistent 🙈.

TODO: support rename table for all mode.

What is changed and how it works?

prefilter before handle statement in optimistic mode.

Check List

Tests

  • Integration test

TODO: emphasize don't mixed sharding tables with normal tables in one task, in other words,sharding-mode means applying to all tables in this task, not only table-routes tables

@GMHDBJD GMHDBJD added status/PTAL This PR is ready for review. Add this label back after committing new changes needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated needs-cherry-pick-release-2.0 This PR should be cherry-picked to release-2.0. Remove this label after cherry-picked to release-2.0 labels Mar 16, 2021
@@ -998,6 +999,7 @@ var (
ErrSyncerOperatorNotExist = New(codeSyncerOperatorNotExist, ClassSyncUnit, ScopeInternal, LevelLow, "error operator not exist, position: %s", "")
ErrSyncerReplaceEventNotExist = New(codeSyncerReplaceEventNotExist, ClassSyncUnit, ScopeInternal, LevelHigh, "replace event not exist, location: %s", "")
ErrSyncerParseDDL = New(codeSyncerParseDDL, ClassSyncUnit, ScopeInternal, LevelHigh, "parse DDL: %s", "Please confirm your DDL statement is correct and needed. For TiDB compatible DDL, see https://docs.pingcap.com/tidb/stable/mysql-compatibility#ddl. You can use `handle-error` command to skip or replace the DDL or add a binlog filter rule to ignore it if the DDL is not needed.")
ErrSyncerUnsupportedStmt = New(codeSyncerUnsupportedStmt, ClassSyncUnit, ScopeInternal, LevelHigh, "`%s` statement not supported in %s mode", "")
Copy link
Collaborator

Choose a reason for hiding this comment

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

we could add a workaround 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can't find out a solution. Maybe we should support rename to the same group now. 😥

@lance6716
Copy link
Collaborator

need to tell user how to handle this situation. rest LGTM

syncer/syncer.go Outdated Show resolved Hide resolved
@lance6716 lance6716 added this to the v2.0.2 milestone Mar 17, 2021
@GMHDBJD GMHDBJD added status/DNM Do not merge, test is failing or blocked by another PR and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Mar 18, 2021
@GMHDBJD GMHDBJD changed the title sync: return an error for rename table statement in shard mode sync: return an error for rename table statement in optimistic mode Mar 24, 2021
@GMHDBJD GMHDBJD added status/PTAL This PR is ready for review. Add this label back after committing new changes and removed status/DNM Do not merge, test is failing or blocked by another PR labels Mar 24, 2021
@@ -1856,6 +1856,8 @@ func (s *Syncer) handleQueryEvent(ev *replication.QueryEvent, ec eventContext, o
case *ast.TruncateTableStmt:
ec.tctx.L().Info("ignore truncate table statement in shard group", zap.String("event", "query"), zap.String("statement", sqlDDL))
continue
case *ast.RenameTableStmt:
Copy link
Collaborator

Choose a reason for hiding this comment

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

we heavily rely on "an optimistic sharding task should sync no other tables than table-route", if user both sync sharding tables and non sharding tables in one task, non sharding tables will not permitted to RENAME.

How about we give an error when user both specify block-allow list and table routes, to ensure user add a minimal sharding task that will not sync non-sharding tables? we might talk to PM if you think that's reasonable. @GMHDBJD @lichunzhu

could join us after your vacation @gozssky

Copy link
Collaborator

Choose a reason for hiding this comment

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

(but #1517 is still not solved)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems there is not associated between #1517 and rename table? We will support rename in both pessimistic and optimistic later. It's no conflict that we can also support #1517 later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, what do you think "this PR also forbid user RENAME a non sharding table in a optimistic sharding task", could we raise an error when user both specify block-allow list and table routes (use table routes as allow list)?

Copy link
Collaborator Author

@GMHDBJD GMHDBJD Mar 25, 2021

Choose a reason for hiding this comment

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

We have other stmts not supported for a non sharding table in shard mode(truncate statement). So it's not a problem of Rename.

raise an error when user both specify block-allow list and table routes

We can support it in another pr or #1517? Maybe talk to PM will be better.

@lance6716 lance6716 added the needs-update-docs Should update docs after this PR is merged. Remove this label once the docs are updated label Mar 25, 2021
@lance6716
Copy link
Collaborator

/lgtm

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • lance6716

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 writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added the status/LGT1 One reviewer already commented LGTM label Mar 25, 2021
@GMHDBJD GMHDBJD merged commit 173b829 into pingcap:master Mar 25, 2021
ti-srebot pushed a commit to ti-srebot/dm that referenced this pull request Mar 25, 2021
@ti-srebot
Copy link

cherry pick to release-2.0 in PR #1535

@ti-srebot ti-srebot added already-cherry-pick-2.0 The related PR is already cherry-picked to release-2.0. Add this label once the PR is cherry-picked and removed needs-cherry-pick-release-2.0 This PR should be cherry-picked to release-2.0. Remove this label after cherry-picked to release-2.0 labels Mar 25, 2021
lance6716 pushed a commit that referenced this pull request Apr 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
already-cherry-pick-2.0 The related PR is already cherry-picked to release-2.0. Add this label once the PR is cherry-picked needs-update-docs Should update docs after this PR is merged. Remove this label once the docs are updated needs-update-release-note This PR should be added into release notes. Remove this label once the release notes are updated size/M status/LGT1 One reviewer already commented LGTM status/PTAL This PR is ready for review. Add this label back after committing new changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants