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

Support executing DDL when cluster is in BDR mode #48519

Closed
3 of 6 tasks
okJiang opened this issue Nov 10, 2023 · 2 comments · Fixed by #50039
Closed
3 of 6 tasks

Support executing DDL when cluster is in BDR mode #48519

okJiang opened this issue Nov 10, 2023 · 2 comments · Fixed by #50039
Labels
type/feature-request Categorizes issue or PR as related to a new feature.

Comments

@okJiang
Copy link
Member

okJiang commented Nov 10, 2023

Solution

DDL definition

In BDR mode, we can understand that in the operation of the business, we can only synchronize safe DDL for execution downstream.
Unsafe DDL can only be synchronized when the related applications are paused.
We call these safe DDL and unsafe DDL as managed DDL.
In addition, we refer to DDL other than managed DDL as unmanaged DDL, and unmanaged DDL can be executed freely on different clusters, independent of the BDR mode.

Circular synchronization

As we all know, bi-directional replication(BDR) will cause circular synchronization. So, in order for users to be able to execute DDL normally, we have divided BDR mode into two different situations:
  • restricted mode: In this mode, the user can execute safe DDL in Primary cluster(will be explained in the next section), and the DDL will be successfully synchronized to other Secondary clusters.
  • unrestricted mode: In this mode, the user can execute all managed DDL in Local_only cluster(will be explained in the next section) separately, and the DDL will be not synchronized to other clusters.
Note:
unrestricted mode must pause related applications. It's a temporary mode, and we recommend to switch back to restricted mode after completing the necessary DDL.

BDR role

In order to implement restricted mode and unrestricted mode. We introduce five bdr roles:
  • None: means that BDR mode is disabled.
  • Primary: can execute safe DDL and unmanaged DDL from users. Usually, the Primary does not receive DDL from CDC.
  • Secondary: can't execute DDL except unmanaged DDL from users. Usually, the Secondary only execute DDL from CDC.
  • Local_only: can execute all DDL from user. However, the DDL from Local_only can't be synced by CDC.

How to switch mode?

restricted mode

  1. Set one cluster to Primary
  2. Set other clusters to Secondary

unrestricted mode

  1. Set all clusters to Local_only

Implement

SQL

  • admin set bdr role (none|primary|secondary|local_only);
    • need admin privilege
  • admin show bdr role;
    • need admin privilege
    • > admin show bdr role; +----------+ | BDR ROLE | +----------+ | none | +----------+

BDR Mode (kernel)

  • List all the DDL, and then classify them as safe/unsafe/unmanaged.
    • For DDL executed in Primary, we check whether it is safe DDL or unmanaged DDL. If it is, DDL can be executed successfully. Otherwise, it is restricted.
    • For DDL executed in Secondary, we check whether it is unmanaged DDL. If it is, DDL can be executed successfully. Otherwise, it is restricted.
  • How does CDC check the bdr role of source cluster?
    • Add a field in tidb_ddl_job

Role Safe DDL(from user) Unsafe DDL(from user) Un-managed DDL(from user) All DDL (from CDC) Can be syncedby CDC
None Y Y Y Y Y
Primary Y N Y Y Y
Secondary N N Y Y N
local_only Y Y Y Y N

Work progress

@okJiang okJiang added the type/feature-request Categorizes issue or PR as related to a new feature. label Nov 10, 2023
@okJiang
Copy link
Member Author

okJiang commented Nov 10, 2023

@okJiang
Copy link
Member Author

okJiang commented Jan 5, 2024

Update:

In document, some definition changed

  • Safe DDL -> Replicable DDLs
  • Unsafe DDL -> NonReplicable DDLs
  • restricted mode -> one scene
  • unrestricted mode -> another scene
  • remove none and local_only roles, add sql admin unset bdr role

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature-request Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant