# cdc-sink **Repository Path**: eiDear/cdc-sink ## Basic Information - **Project Name**: cdc-sink - **Description**: mirror of https://github.com/cockroachdb/cdc-sink - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-09-06 - **Last Updated**: 2021-09-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: Database ## README # cdc-sink This tool lets one CockroachDB cluster injest CDC feeds from one or more CockroachDB clusters. For more information on CDC, please see: ***This is just a prototype and is not officially supported by Cockroach Labs.*** We cannot provide support for it at this time but may in the future. Use of this tool is entirely at your own risk and Cockroach Labs makes no guarantees or warranties about its operation. ## Overview - Source CRDB emits changes in realtime via CRDB CDC feature - CDC sink accepts the changes via the HTTP end point - CDC sink applies the changes to the target CRDB ```text +---------------------+ | source CRDB | | | | CDC {source_table} | +---------------------+ | V http://ip:26258 +---------------------+ | CDC sink | |CDC SINK {end_point} | +---------------------+ | V postgresql://ip:26257 +---------------------+ | target CRDB | | {destination_table} | +---------------------+ ``` ## Instructions _Note that this is subject to change as this is still under development._ 1. In the source cluster, choose the table(s) you would like to stream. 2. In the destination cluster, re-create those tables and match the schema exactly. * Don't create any new constraints on any destination table. * Don't have any foreign key relationships with the destination table. * It's imperative that the columns are named exactly the same in the destination table. 3. Startup cdc-sink either on * all nodes of the destination cluster * one or more servers that can reach the destination cluster 4. startup CDC-SINK on all servers that it's running on using the flags listed below 5. Set the cluster setting of the source cluster to enable range feeds: `SET CLUSTER SETTING kv.rangefeed.enabled = true` 6. Once it starts up, enable a cdc feed from the source cluster * `CREATE CHANGEFEED FOR TABLE [source_table] INTO 'experimental-[cdc-sink-url:port]/test.sql' WITH updated,resolved` * Be sure to always use the options `updated` and `resolved` as these are required for this to work ### A short exmaple with YCSB workload ```bash # install the cdc-sink go get github.com/cockroachdb/cdc-sink # source CRDB is single node cockroach start-single-node --listen-addr :30000 --http-addr :30001 --store cockroach-data/30000 --insecure --background # target CRDB is single node as well -- does not need be cockroach start-single-node --listen-addr :30002 --http-addr :30003 --store cockroach-data/30002 --insecure --background # source ycsb.usertable is populated with 10 rows cockroach workload init ycsb postgresql://root@localhost:30000/ycsb?sslmode=disable --families=false --insert-count=10 # target ycsb.usertable is empty cockroach workload init ycsb postgresql://root@localhost:30002/ycsb?sslmode=disable --families=false --insert-count=0 # source has rows, target is empty cockroach sql --port 30000 --insecure -e "select * from ycsb.usertable" cockroach sql --port 30002 --insecure -e "select * from ycsb.usertable" # cdc-sink started as a background task cdc-sink --port 30004 --conn postgresql://root@localhost:30002/defaultdb?sslmode=disable --config="[{\"endpoint\":\"crdbusertable\", \"source_table\":\"usertable\", \"destination_database\":\"ycsb\", \"destination_table\":\"usertable\"}]" & # start the CDC that will send across the initial datashapshot cockroach sql --insecure --port 30000 < * schema changes do not work, * in order to perform a schema change 1. stop the change feed 2. stop cdc_sink 3. make the schema changes to both tables 4. start cdc_sink 5. restart the change feed * constraints on the destination table * foreign keys * there is no guarantee that foreign keys between two tables will arrive in the correct order so please only use them on the source table * different table constraints * anything that has a tighter constraint than the original table may break the streaming * the schema of the destination table must match the primary table exactly ## Expansions While the schema of the secondary table must match that of the primary table, specifically the primary index. There are some other changes than can be made on the destination side. * Different and new secondary indexes are allowed. * Different zone configs are allowed. * Adding new computed columns, that cannot reject any row, should work. ## Troubleshootings