TiKV-CDC is TiKV's change data capture framework. It supports replicating change data to another TiKV cluster.
TiKV-CDC is a fork of TiCDC, but focus on NoSQL scenario that uses TiKV as a Key-Value storage. By now, it can be used by RawKV to build a storage system with Cross Cluster Replication, to provide financial-level disaster recovery capabilities.
Please note that the minimal required version of TiKV is v6.2.0.
TODO
To check the source code, run test cases and build binaries, you can simply run:
$ make dev
$ make cdc
(Will be supported soon)
- Set up two TiKV cluster, one for upstream and another for downstream.
- Start a TiKV-CDC cluster, which contains one or more TiKV-CDC servers. The command to start on TiKV-CDC server is
tikv-cdc server --pd <upstream PD endpoints>. - Start a replication changefeed by
tikv-cdc cli changefeed create --pd <upstream PD endpoints> --sink-uri tikv://<downstream PD endpoints>
addr: The listening address of TiKV-CDC, the HTTP API address, and the Prometheus address of the TiKV-CDC service. The default value is 127.0.0.1:8600.advertise-addr: The advertised address via which clients access TiKV-CDC. If unspecified, the value is the same asaddr.pd: A comma-separated list of PD endpoints.config: The address of the configuration file that TiKV-CDC uses (optional).data-dir: Specifies the directory that TiKV-CDC uses to store temporary files for sorting. It is recommended to ensure that the free disk space for this directory is greater than or equal to 500 GiB.gc-ttl: The TTL (Time To Live) of the service levelGC safepointin PD set by TiKV-CDC, and the duration that the replication task can suspend, in seconds. The default value is 86400, which means 24 hours. Note: Suspending of the TiKV-CDC replication task affects the progress of TiKV-CDCGC safepoint. The longer ofgc-ttl, the longer a changefeed can be paused, but at the same time more outdate data will be kept, larger space will be occupied. And vice versa.log-file: The path to which logs are output when the TiKV-CDC process is running. If this parameter is not specified, logs are written to the standard output (stdout).log-level: The log level when the TiKV-CDC process is running. The default value is "info".
tikv-cdc cli capture list --pd=http://192.168.100.122:2379
[
{
"id": "07684765-52df-42a0-8dd1-a4e9084bb7c1",
"is-owner": false,
"address": "192.168.100.9:8600"
},
{
"id": "aea1445b-c065-4dc5-be53-a445261f7fc2",
"is-owner": true,
"address": "192.168.100.26:8600"
},
{
"id": "f29496df-f6b4-4c1e-bfa3-41a058ce2144",
"is-owner": false,
"address": "192.168.100.142:8600"
}
]
In the result above:
id: The ID of the service process.is-owner: Indicates whether the service process is the owner node.address: The address via which the service process provides interface to the outside.
tikv-cdc cli changefeed create --pd=http://192.168.100.122:2379 --sink-uri="tikv://192.168.100.61:2379/" --changefeed-id="rawkv-replication-task"
Create changefeed successfully!
ID: rawkv-replication-task
Info: {"sink-uri":"tikv://192.168.100.61:2379","opts":{},"create-time":"2022-07-20T15:35:47.860947953+08:00","start-ts":434714063103852547,"target-ts":0,"admin-job-type":0,"sort-engine":"unified","sort-dir":"","scheduler":{"type":"keyspan-number","polling-time":-1},"state":"normal","history":null,"error":null}
In the command and result above:
-
--changefeed-id: The ID of the replication task. The format must match the ^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$ regular expression. If this ID is not specified, TiKV-CDC automatically generates a UUID (the version 4 format) as the ID. -
--sink-uri: The downstream address of the replication task. Configure --sink-uri according to the following format. Currently, the scheme supportstikvonly. Besides, when a URI contains special characters, you need to process these special characters using URL encoding.
[scheme]://[userinfo@][host]:[port][/path]?[query_parameters]
--start-ts: Specifies the starting TSO of the changefeed. From this TSO, the TiKV-CDC cluster starts pulling data. The default value is the current time. If the replication is deployed on a existing cluster, it is recommended that using TiKV-BR to backup & restore existing data to downstream, getbackup-tsfrom backup result ofTiKV-BR, and then deploy changefeed with--start-ts=<backup-ts+1>.
--sink-uri="tikv://192.168.100.61:2379/"
| Parameter/Parameter Value | Description |
|---|---|
| 192.168.100.61:2379 | The endpoints of the downstream PD. Multiple addresses are separated by comma. |
tikv-cdc cli changefeed list --pd=http://192.168.100.122:2379
[
{
"id": "rawkv-replication-task",
"summary": {
"state": "normal",
"tso": 434715745556889877,
"checkpoint": "2022-07-20 17:22:45.900",
"error": null
}
}
]
In the result above:
checkpointindicates that TiKV-CDC has already replicated data before this time point to the downstream.stateindicates the state of the replication task.normal: The replication task runs normally.stopped: The replication task is stopped (manually paused).error: The replication task is stopped (by an error).removed: The replication task is removed. Tasks of this state are displayed only when you have specified the --all option. To see these tasks when this option is not specified, execute the changefeed query command.
tikv-cdc cli changefeed query -s --changefeed-id rawkv-replication-task --pd=http://192.168.100.122:2379
{
"state": "normal",
"tso": 434716089136185435,
"checkpoint": "2022-07-20 17:44:36.551",
"error": null
}
In the result above:
stateis the replication state of the current changefeed. Each state must be consistent with the state in changefeed list.tsorepresents the largest TSO in the current changefeed that has been successfully replicated to the downstream.checkpointrepresents the corresponding time of the largest TSO in the current changefeed that has been successfully replicated to the downstream.errorrecords whether an error has occurred in the current changefeed.
tikv-cdc cli changefeed query --changefeed-id rawkv-replication-task --pd=http://192.168.100.122:2379
{
"info": {
"sink-uri": "tikv://192.168.100.61:2379/",
"opts": {},
"create-time": "2022-07-20T17:21:54.115625346+08:00",
"start-ts": 434715731964985345,
"target-ts": 0,
"admin-job-type": 0,
"sort-engine": "unified",
"sort-dir": "",
"config": {
"check-gc-safe-point": true,
"scheduler": {
"type": "keyspan-number",
"polling-time": -1
},
},
"state": "normal",
"history": null,
"error": null,
"sync-point-enabled": false,
"sync-point-interval": 600000000000,
},
"status": {
"resolved-ts": 434715754364928912,
"checkpoint-ts": 434715754103047044,
"admin-job-type": 0
},
"count": 0,
"task-status": [
{
"capture-id": "aea1445b-c065-4dc5-be53-a445261f7fc2",
"status": {
"keyspans": {
"15137828009456710810": {
"start-ts": 434715731964985345,
"Start": "cg==",
"End": "cw=="
}
},
"operation": {},
"admin-job-type": 0
}
}
]
}
In the result above:
infois the replication configuration of the queried changefeed.statusis the replication state of the queried changefeed.resolved-ts: The largest TS in the current changefeed. Note that this TS has been successfully sent from TiKV to TiKV-CDC.checkpoint-ts: The largest TS in the current changefeed. Note that this TS has been successfully written to the downstream.admin-job-type: The status of a changefeed:0: The state is normal.1: The task is paused. When the task is paused, all replicated processors exit. The configuration and the replication status of the task are retained, so you can resume the task fromcheckpoint-ts.2: The task is resumed. The replication task resumes fromcheckpoint-ts.3: The task is removed. When the task is removed, all replicated processors are ended, and the configuration information of the replication task is cleared up. Only the replication status is retained for later queries.
task-statusindicates the state of each replication sub-task in the queried changefeed.
tikv-cdc cli changefeed pause --changefeed-id rawkv-replication-task --pd=http://192.168.100.122:2379
tikv-cdc cli changefeed list --pd=http://192.168.100.122:2379
[
{
"id": "rawkv-replication-task",
"summary": {
"state": "stopped",
"tso": 434715759083521004,
"checkpoint": "2022-07-20 17:23:37.500",
"error": null
}
}
]
In the command above:
--changefeed-id=uuidrepresents the ID of the changefeed that corresponds to the replication task you want to pause.
tikv-cdc cli changefeed resume --changefeed-id rawkv-replication-task --pd=http://192.168.100.122:2379
tikv-cdc cli changefeed list --pd=http://192.168.100.122:2379
[
{
"id": "rawkv-replication-task",
"summary": {
"state": "normal",
"tso": 434715759083521004,
"checkpoint": "2022-07-20 17:23:37.500",
"error": null
}
}
]
tikv-cdc cli changefeed remove --changefeed-id rawkv-replication-task --pd=http://192.168.100.122:2379
tikv-cdc cli changefeed list --pd=http://192.168.100.122:2379
[]
tikv-cdc cli processor list --pd=http://192.168.100.122:2379`
[
{
"changefeed_id": "rawkv-replication-task",
"capture_id": "07684765-52df-42a0-8dd1-a4e9084bb7c1"
}
]
Contributions are welcomed and greatly appreciated. See CONTRIBUTING.md for details on submitting patches and the contribution workflow.
TiKV-CDC is under the Apache 2.0 license. See the LICENSE file for details.