-
Notifications
You must be signed in to change notification settings - Fork 710
reference/tidb-binlog: add docs about relay log #1881
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
255b119
TOC: add relay log entry
ran-huang 5ffcb76
reference/tidb-binlog: update deploy
ran-huang 04b7502
reference/tidb-binlog: add relay log in overview
ran-huang dfd71cf
reference/tidb-binlog: add relay log doc
ran-huang fb9965e
fix typos
ran-huang 765b456
ensure term consistency
ran-huang c6d501b
fix typo
ran-huang 59cac09
delete alias from relay-log
ran-huang 2477924
minor update
ran-huang e831eef
Merge branch 'master' into add-relay-log
ran-huang d71500c
Merge branch 'master' into add-relay-log
lilin90 6814b38
Merge branch 'master' into add-relay-log
lilin90 973e2bd
Apply suggestions from code review
ran-huang 430dd33
Merge branch 'master' into add-relay-log
lilin90 678bdbb
tidb-binlog: update sql code block format
lilin90 7b3b23e
Add one-sentence summary to relay log
ran-huang 4ee9488
Merge branch 'master' into add-relay-log
ran-huang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| --- | ||
| title: TiDB Binlog Relay Log | ||
| summary: Learn how to use relay log to maintain data consistency in extreme cases. | ||
| category: reference | ||
| --- | ||
|
|
||
| # TiDB Binlog Relay Log | ||
|
|
||
| When replicating binlogs, Drainer splits transactions from the upstream and replicates the split transactions concurrently to the downstream. | ||
|
|
||
| In extreme cases where the upstream clusters are not available and Drainer exits abnormally, the downstream clusters (MySQL or TiDB) might be in the intermediate states with inconsistent data. In such cases, Drainer can use the relay log to ensure that the downstream clusters are in a consistent state. | ||
|
|
||
| ## Consistent state during Drainer replication | ||
|
|
||
| The downstream clusters reaching a consistent state means the data of the downstream clusters are the same as the snapshot of the upstream which sets `tidb_snapshot = ts`. | ||
|
|
||
| The checkpoint consistency means Drainer checkpoint saves the consistent state of replication in `consistent`. When Drainer runs, `consistent` is `false`. After Drainer exits normally, `consistent` is set to `true`. | ||
|
|
||
| You can query the downstream checkpoint table as follows: | ||
|
|
||
| {{< copyable "sql" >}} | ||
|
|
||
| ```sql | ||
| select * from tidb_binlog.checkpoint; | ||
| ``` | ||
|
|
||
| ``` | ||
|
ran-huang marked this conversation as resolved.
|
||
| +---------------------+----------------------------------------------------------------+ | ||
| | clusterID | checkPoint | | ||
| +---------------------+----------------------------------------------------------------+ | ||
| | 6791641053252586769 | {"consistent":false,"commitTS":414529105591271429,"ts-map":{}} | | ||
| +---------------------+----------------------------------------------------------------+ | ||
| ``` | ||
|
|
||
| ## Implementation principles | ||
|
|
||
| After Drainer enables the relay log, it first writes the binlog events to the disks and then replicates the events to the downstream clusters. | ||
|
|
||
| If the upstream clusters are not available, Drainer can restore the downstream clusters to a consistent state by reading the relay log. | ||
|
|
||
| > **Note:** | ||
| > | ||
| > If the relay log data is lost at the same time, this method does not work, but its incidence is very low. In addition, you can use the Network File System to ensure data safety of the relay log. | ||
|
|
||
| ### Trigger scenarios where Drainer consumes binlogs from the relay log | ||
|
|
||
| When Drainer is started, if it fails to connect to the Placement Driver (PD) of the upstream clusters, and it detects that `consistent = false` in the checkpoint, Drainer will try to read the relay log, and restore the downstream clusters to a consistent state. After that, the Drainer process sets the checkpoint `consistent` to `true` and then exits. | ||
|
|
||
| ### GC mechanism of relay log | ||
|
|
||
| While Drainer is running, if it confirms that the whole data of a relay log file has been successfully replicated to the downstream, the file is deleted immediately. Therefore, the relay log does not occupy too much space. | ||
|
|
||
| If the size of a relay log file reaches 10MB (by default), the file is split, and data is written into a new relay log file. | ||
|
|
||
| ## Configuration | ||
|
|
||
| To enable the relay log, add the following configuration in Drainer: | ||
|
|
||
| {{< copyable "" >}} | ||
|
|
||
| ``` | ||
| [syncer.relay] | ||
| # It saves the directory of the relay log. The relay log is not enabled if the value is empty. | ||
| # The configuration only comes to effect if the downstream is TiDB or MySQL. | ||
| log-dir = "/dir/to/save/log" | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.