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

[YSQL] Enable 2DC replication bootstrap for YSQL tables #5601

Closed
hectorgcr opened this issue Sep 4, 2020 · 0 comments
Closed

[YSQL] Enable 2DC replication bootstrap for YSQL tables #5601

hectorgcr opened this issue Sep 4, 2020 · 0 comments
Assignees
Labels
area/cdc Change Data Capture

Comments

@hectorgcr
Copy link
Contributor

Currently, we support replication bootstrap which allows the producer to know from where to start replicating. The typical flow for this is:

  1. Create a replication bootstrap using the command:
    yb-admin -master_addresses <master addresses> bootstrap_cdc_producer <list of tables ids>
  2. Create a backup of the tables
  3. Restore backup on the consumer
  4. Setup replication using the generated bootstrap id from step 1:
    yb-admin -master_addresses <consumer master address> setup_universe_replication cluster-A <producer master address> <list of tables ids> <bootstrap id>

This workflow works well for CQL tables, but we need to enable it for YSQL tables.

@hectorgcr hectorgcr self-assigned this Sep 4, 2020
@hectorgcr hectorgcr added the area/cdc Change Data Capture label Sep 4, 2020
hectorgcr added a commit that referenced this issue Sep 8, 2020
Summary:
Currently, we support replication bootstrap which allows the producer to know from where to start replicating. The typical flow for this is:

1. Create a replication bootstrap using the command:
```yb-admin -master_addresses <master addresses> bootstrap_cdc_producer <list of tables ids>```
2. Create a backup of the tables
3. Restore backup on the consumer
4. Setup replication using the generated bootstrap id from step 1:
```yb-admin -master_addresses <consumer master address> setup_universe_replication cluster-A <producer master address> <list of tables ids> <bootstrap id>```

This workflow works well for CQL tables, but we need to enable it for YSQL tables.

Test Plan:
```++ pkill yb-tserver
++ pkill yb-master
++ rm -rf '/tmp/yb-datacenter-*'
++ ./bin/yb-ctl create --rf 1 --data_dir /tmp/yb-datacenter-A --ip_start 11
Creating cluster.
Waiting for cluster to be ready.
----------------------------------------------------------------------------------------------------
| Node Count: 1 | Replication Factor: 1                                                            |
----------------------------------------------------------------------------------------------------
| JDBC                : jdbc:postgresql://127.0.0.11:5433/yugabyte                                 |
| YSQL Shell          : build/latest/bin/ysqlsh -h 127.0.0.11                                      |
| YCQL Shell          : build/latest/bin/ycqlsh 127.0.0.11                                         |
| YEDIS Shell         : build/latest/bin/redis-cli -h 127.0.0.11                                   |
| Web UI              : http://127.0.0.11:7000/                                                    |
| Cluster Data        : /tmp/yb-datacenter-A                                                       |
----------------------------------------------------------------------------------------------------

For more info, please use: yb-ctl --data_dir /tmp/yb-datacenter-A status
++ ./bin/yb-ctl create --rf 1 --data_dir /tmp/yb-datacenter-B --ip_start 22
Creating cluster.
Waiting for cluster to be ready.
----------------------------------------------------------------------------------------------------
| Node Count: 1 | Replication Factor: 1                                                            |
----------------------------------------------------------------------------------------------------
| JDBC                : jdbc:postgresql://127.0.0.22:5433/yugabyte                                 |
| YSQL Shell          : build/latest/bin/ysqlsh -h 127.0.0.22                                      |
| YCQL Shell          : build/latest/bin/ycqlsh 127.0.0.22                                         |
| YEDIS Shell         : build/latest/bin/redis-cli -h 127.0.0.22                                   |
| Web UI              : http://127.0.0.22:7000/                                                    |
| Cluster Data        : /tmp/yb-datacenter-B                                                       |
----------------------------------------------------------------------------------------------------

For more info, please use: yb-ctl --data_dir /tmp/yb-datacenter-B status
++ ./bin/ysqlsh -h 127.0.0.11 -c 'create table t1(k int primary key, v text);'
CREATE TABLE
++ ./bin/ysqlsh -h 127.0.0.22 -c 'create table t1(k int primary key, v text);'
CREATE TABLE
+++ grep -v transactions
+++ awk '{print $9}'
+++ grep 'Successfully created table' /tmp/yb-datacenter-A/node-1/disk-1/yb-data/master/logs/yb-master.INFO
+++ sed 's/\[id=//g'
+++ sed 's/\]//g'
+++ paste -s -d, -
++ TABLE_IDS=000030a9000030008000000000004000
++ echo 'TABLE IDS: 000030a9000030008000000000004000'
TABLE IDS: 000030a9000030008000000000004000
++ sleep 5
++ ./bin/ysqlsh -h 127.0.0.11 -c 'insert into t1(k,v) values (0, '\''cero no txn'\'');'
INSERT 0 1
++ ./bin/ysqlsh -h 127.0.0.11 -c 'BEGIN; insert into t1(k,v) values (1, '\''uno txn 1'\''); insert into t1(k,v) values (2, '\''dos txn 1'\''); select pg_sleep(1); COMMIT;'
COMMIT
+++ ./build/latest/bin/yb-admin -master_addresses 127.0.0.11:7100,127.0.0.12:7100,127.0.0.13:7100 bootstrap_cdc_producer 000030a9000030008000000000004000
+++ tee /dev/tty
+++ grep bootstrap
+++ awk '{print $7}'
+++ paste -s -d, -
table id: 000030a9000030008000000000004000, CDC bootstrap id: 43d45fcb90af48848777e4b982c9f615
++ BOOTSTRAP_IDS=43d45fcb90af48848777e4b982c9f615
++ /home/hector/code/yugabyte-db/build/latest/bin/yb-admin -master_addresses 127.0.0.22:7100 setup_universe_replication cluster-A 127.0.0.11:7100 000030a9000030008000000000004000 43d45fcb90af48848777e4b982c9f615
Replication setup successfully
++ sleep 1
++ ./bin/ysqlsh -h 127.0.0.11 -c 'BEGIN; insert into t1(k,v) values (3, '\''tres txn 2'\''); COMMIT;'
COMMIT
++ ./bin/ysqlsh -h 127.0.0.11 -c 'insert into t1(k,v) values (4, '\''cuatro no txn'\'');'
INSERT 0 1
++ ./bin/ysqlsh -h 127.0.0.11 -c 'insert into t1(k,v) values (5, '\''cinco no txn'\'');'
INSERT 0 1
++ ./bin/cqlsh 127.0.0.11 -e 'select * from system.cdc_state'

 tablet_id                        | stream_id                        | checkpoint | data | last_replication_time
----------------------------------+----------------------------------+------------+------+-----------------------
 6045b56d647d4f799af39e54163dfb44 | 43d45fcb90af48848777e4b982c9f615 |        1.4 | null |                  null
 535b7c3958f247458df4a9ff264c1cd3 | 43d45fcb90af48848777e4b982c9f615 |        1.5 | null |                  null

(2 rows)
++ sleep 5
++ ./bin/ysqlsh -h 127.0.0.22 -c 'SELECT * from t1 ORDER BY k'
 k |       v
---+---------------
 3 | tres txn 2
 4 | cuatro no txn
 5 | cinco no txn
(3 rows)

++ sleep 6
++ ./bin/ysqlsh -h 127.0.0.22 -c 'SELECT * from t1 ORDER BY k'
 k |       v
---+---------------
 3 | tres txn 2
 4 | cuatro no txn
 5 | cinco no txn
(3 rows)

++ ./bin/ysqlsh -h 127.0.0.11 -c 'ALTER TABLE t1 ADD COLUMN v2 int'
ALTER TABLE
++ ./bin/ysqlsh -h 127.0.0.11 -c 'SELECT * FROM t1'
 k |       v       | v2
---+---------------+----
 5 | cinco no txn  |
 1 | uno txn 1     |
 4 | cuatro no txn |
 0 | cero no txn   |
 2 | dos txn 1     |
 3 | tres txn 2    |
(6 rows)
```

Reviewers: bogdan, rahuldesirazu, nicolas

Reviewed By: nicolas

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D9321
hectorgcr added a commit that referenced this issue Sep 9, 2020
Summary:
Currently, we support replication bootstrap which allows the producer to know from where to start replicating. The typical flow for this is:

    1. Create a replication bootstrap using the command:
    ```yb-admin -master_addresses <master addresses> bootstrap_cdc_producer <list of tables ids>```
    2. Create a backup of the tables
    3. Restore backup on the consumer
    4. Setup replication using the generated bootstrap id from step 1:
    ```yb-admin -master_addresses <consumer master address> setup_universe_replication cluster-A <producer master address> <list of tables ids> <bootstrap id>```

    This workflow works well for CQL tables, but we need to enable it for YSQL tables.

Test Plan:
 ```++ pkill yb-tserver
    ++ pkill yb-master
    ++ rm -rf '/tmp/yb-datacenter-*'
    ++ ./bin/yb-ctl create --rf 1 --data_dir /tmp/yb-datacenter-A --ip_start 11
    Creating cluster.
    Waiting for cluster to be ready.
    ----------------------------------------------------------------------------------------------------
    | Node Count: 1 | Replication Factor: 1                                                            |
    ----------------------------------------------------------------------------------------------------
    | JDBC                : jdbc:postgresql://127.0.0.11:5433/yugabyte                                 |
    | YSQL Shell          : build/latest/bin/ysqlsh -h 127.0.0.11                                      |
    | YCQL Shell          : build/latest/bin/ycqlsh 127.0.0.11                                         |
    | YEDIS Shell         : build/latest/bin/redis-cli -h 127.0.0.11                                   |
    | Web UI              : http://127.0.0.11:7000/                                                    |
    | Cluster Data        : /tmp/yb-datacenter-A                                                       |
    ----------------------------------------------------------------------------------------------------

    For more info, please use: yb-ctl --data_dir /tmp/yb-datacenter-A status
    ++ ./bin/yb-ctl create --rf 1 --data_dir /tmp/yb-datacenter-B --ip_start 22
    Creating cluster.
    Waiting for cluster to be ready.
    ----------------------------------------------------------------------------------------------------
    | Node Count: 1 | Replication Factor: 1                                                            |
    ----------------------------------------------------------------------------------------------------
    | JDBC                : jdbc:postgresql://127.0.0.22:5433/yugabyte                                 |
    | YSQL Shell          : build/latest/bin/ysqlsh -h 127.0.0.22                                      |
    | YCQL Shell          : build/latest/bin/ycqlsh 127.0.0.22                                         |
    | YEDIS Shell         : build/latest/bin/redis-cli -h 127.0.0.22                                   |
    | Web UI              : http://127.0.0.22:7000/                                                    |
    | Cluster Data        : /tmp/yb-datacenter-B                                                       |
    ----------------------------------------------------------------------------------------------------

    For more info, please use: yb-ctl --data_dir /tmp/yb-datacenter-B status
    ++ ./bin/ysqlsh -h 127.0.0.11 -c 'create table t1(k int primary key, v text);'
    CREATE TABLE
    ++ ./bin/ysqlsh -h 127.0.0.22 -c 'create table t1(k int primary key, v text);'
    CREATE TABLE
    +++ grep -v transactions
    +++ awk '{print $9}'
    +++ grep 'Successfully created table' /tmp/yb-datacenter-A/node-1/disk-1/yb-data/master/logs/yb-master.INFO
    +++ sed 's/\[id=//g'
    +++ sed 's/\]//g'
    +++ paste -s -d, -
    ++ TABLE_IDS=000030a9000030008000000000004000
    ++ echo 'TABLE IDS: 000030a9000030008000000000004000'
    TABLE IDS: 000030a9000030008000000000004000
    ++ sleep 5
    ++ ./bin/ysqlsh -h 127.0.0.11 -c 'insert into t1(k,v) values (0, '\''cero no txn'\'');'
    INSERT 0 1
    ++ ./bin/ysqlsh -h 127.0.0.11 -c 'BEGIN; insert into t1(k,v) values (1, '\''uno txn 1'\''); insert into t1(k,v) values (2, '\''dos txn 1'\''); select pg_sleep(1); COMMIT;'
    COMMIT
    +++ ./build/latest/bin/yb-admin -master_addresses 127.0.0.11:7100,127.0.0.12:7100,127.0.0.13:7100 bootstrap_cdc_producer 000030a9000030008000000000004000
    +++ tee /dev/tty
    +++ grep bootstrap
    +++ awk '{print $7}'
    +++ paste -s -d, -
    table id: 000030a9000030008000000000004000, CDC bootstrap id: 43d45fcb90af48848777e4b982c9f615
    ++ BOOTSTRAP_IDS=43d45fcb90af48848777e4b982c9f615
    ++ /home/hector/code/yugabyte-db/build/latest/bin/yb-admin -master_addresses 127.0.0.22:7100 setup_universe_replication cluster-A 127.0.0.11:7100 000030a9000030008000000000004000 43d45fcb90af48848777e4b982c9f615
    Replication setup successfully
    ++ sleep 1
    ++ ./bin/ysqlsh -h 127.0.0.11 -c 'BEGIN; insert into t1(k,v) values (3, '\''tres txn 2'\''); COMMIT;'
    COMMIT
    ++ ./bin/ysqlsh -h 127.0.0.11 -c 'insert into t1(k,v) values (4, '\''cuatro no txn'\'');'
    INSERT 0 1
    ++ ./bin/ysqlsh -h 127.0.0.11 -c 'insert into t1(k,v) values (5, '\''cinco no txn'\'');'
    INSERT 0 1
    ++ ./bin/cqlsh 127.0.0.11 -e 'select * from system.cdc_state'

     tablet_id                        | stream_id                        | checkpoint | data | last_replication_time
    ----------------------------------+----------------------------------+------------+------+-----------------------
     6045b56d647d4f799af39e54163dfb44 | 43d45fcb90af48848777e4b982c9f615 |        1.4 | null |                  null
     535b7c3958f247458df4a9ff264c1cd3 | 43d45fcb90af48848777e4b982c9f615 |        1.5 | null |                  null

    (2 rows)
    ++ sleep 5
    ++ ./bin/ysqlsh -h 127.0.0.22 -c 'SELECT * from t1 ORDER BY k'
     k |       v
    ---+---------------
     3 | tres txn 2
     4 | cuatro no txn
     5 | cinco no txn
    (3 rows)

    ++ sleep 6
    ++ ./bin/ysqlsh -h 127.0.0.22 -c 'SELECT * from t1 ORDER BY k'
     k |       v
    ---+---------------
     3 | tres txn 2
     4 | cuatro no txn
     5 | cinco no txn
    (3 rows)

    ++ ./bin/ysqlsh -h 127.0.0.11 -c 'ALTER TABLE t1 ADD COLUMN v2 int'
    ALTER TABLE
    ++ ./bin/ysqlsh -h 127.0.0.11 -c 'SELECT * FROM t1'
     k |       v       | v2
    ---+---------------+----
     5 | cinco no txn  |
     1 | uno txn 1     |
     4 | cuatro no txn |
     0 | cero no txn   |
     2 | dos txn 1     |
     3 | tres txn 2    |
    (6 rows)
    ```

Reviewers: bogdan, nicolas

Reviewed By: nicolas

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D9330
hectorgcr added a commit that referenced this issue Sep 15, 2020
… tables

Summary:
Currently, we support replication bootstrap which allows the producer to know from where to start replicating. The typical flow for this is:

1. Create a replication bootstrap using the command:
```yb-admin -master_addresses <master addresses> bootstrap_cdc_producer <list of tables ids>```
2. Create a backup of the tables
3. Restore backup on the consumer
4. Setup replication using the generated bootstrap id from step 1:
```yb-admin -master_addresses <consumer master address> setup_universe_replication cluster-A <producer master address> <list of tables ids> <bootstrap id>```

This workflow works well for CQL tables, but we need to enable it for YSQL tables.

Test Plan:
```++ pkill yb-tserver
++ pkill yb-master
++ rm -rf '/tmp/yb-datacenter-*'
++ ./bin/yb-ctl create --rf 1 --data_dir /tmp/yb-datacenter-A --ip_start 11
Creating cluster.
Waiting for cluster to be ready.
----------------------------------------------------------------------------------------------------
| Node Count: 1 | Replication Factor: 1                                                            |
----------------------------------------------------------------------------------------------------
| JDBC                : jdbc:postgresql://127.0.0.11:5433/yugabyte                                 |
| YSQL Shell          : build/latest/bin/ysqlsh -h 127.0.0.11                                      |
| YCQL Shell          : build/latest/bin/ycqlsh 127.0.0.11                                         |
| YEDIS Shell         : build/latest/bin/redis-cli -h 127.0.0.11                                   |
| Web UI              : http://127.0.0.11:7000/                                                    |
| Cluster Data        : /tmp/yb-datacenter-A                                                       |
----------------------------------------------------------------------------------------------------

For more info, please use: yb-ctl --data_dir /tmp/yb-datacenter-A status
++ ./bin/yb-ctl create --rf 1 --data_dir /tmp/yb-datacenter-B --ip_start 22
Creating cluster.
Waiting for cluster to be ready.
----------------------------------------------------------------------------------------------------
| Node Count: 1 | Replication Factor: 1                                                            |
----------------------------------------------------------------------------------------------------
| JDBC                : jdbc:postgresql://127.0.0.22:5433/yugabyte                                 |
| YSQL Shell          : build/latest/bin/ysqlsh -h 127.0.0.22                                      |
| YCQL Shell          : build/latest/bin/ycqlsh 127.0.0.22                                         |
| YEDIS Shell         : build/latest/bin/redis-cli -h 127.0.0.22                                   |
| Web UI              : http://127.0.0.22:7000/                                                    |
| Cluster Data        : /tmp/yb-datacenter-B                                                       |
----------------------------------------------------------------------------------------------------

For more info, please use: yb-ctl --data_dir /tmp/yb-datacenter-B status
++ ./bin/ysqlsh -h 127.0.0.11 -c 'create table t1(k int primary key, v text);'
CREATE TABLE
++ ./bin/ysqlsh -h 127.0.0.22 -c 'create table t1(k int primary key, v text);'
CREATE TABLE
+++ grep -v transactions
+++ awk '{print $9}'
+++ grep 'Successfully created table' /tmp/yb-datacenter-A/node-1/disk-1/yb-data/master/logs/yb-master.INFO
+++ sed 's/\[id=//g'
+++ sed 's/\]//g'
+++ paste -s -d, -
++ TABLE_IDS=000030a9000030008000000000004000
++ echo 'TABLE IDS: 000030a9000030008000000000004000'
TABLE IDS: 000030a9000030008000000000004000
++ sleep 5
++ ./bin/ysqlsh -h 127.0.0.11 -c 'insert into t1(k,v) values (0, '\''cero no txn'\'');'
INSERT 0 1
++ ./bin/ysqlsh -h 127.0.0.11 -c 'BEGIN; insert into t1(k,v) values (1, '\''uno txn 1'\''); insert into t1(k,v) values (2, '\''dos txn 1'\''); select pg_sleep(1); COMMIT;'
COMMIT
+++ ./build/latest/bin/yb-admin -master_addresses 127.0.0.11:7100,127.0.0.12:7100,127.0.0.13:7100 bootstrap_cdc_producer 000030a9000030008000000000004000
+++ tee /dev/tty
+++ grep bootstrap
+++ awk '{print $7}'
+++ paste -s -d, -
table id: 000030a9000030008000000000004000, CDC bootstrap id: 43d45fcb90af48848777e4b982c9f615
++ BOOTSTRAP_IDS=43d45fcb90af48848777e4b982c9f615
++ /home/hector/code/yugabyte-db/build/latest/bin/yb-admin -master_addresses 127.0.0.22:7100 setup_universe_replication cluster-A 127.0.0.11:7100 000030a9000030008000000000004000 43d45fcb90af48848777e4b982c9f615
Replication setup successfully
++ sleep 1
++ ./bin/ysqlsh -h 127.0.0.11 -c 'BEGIN; insert into t1(k,v) values (3, '\''tres txn 2'\''); COMMIT;'
COMMIT
++ ./bin/ysqlsh -h 127.0.0.11 -c 'insert into t1(k,v) values (4, '\''cuatro no txn'\'');'
INSERT 0 1
++ ./bin/ysqlsh -h 127.0.0.11 -c 'insert into t1(k,v) values (5, '\''cinco no txn'\'');'
INSERT 0 1
++ ./bin/cqlsh 127.0.0.11 -e 'select * from system.cdc_state'

 tablet_id                        | stream_id                        | checkpoint | data | last_replication_time
----------------------------------+----------------------------------+------------+------+-----------------------
 6045b56d647d4f799af39e54163dfb44 | 43d45fcb90af48848777e4b982c9f615 |        1.4 | null |                  null
 535b7c3958f247458df4a9ff264c1cd3 | 43d45fcb90af48848777e4b982c9f615 |        1.5 | null |                  null

(2 rows)
++ sleep 5
++ ./bin/ysqlsh -h 127.0.0.22 -c 'SELECT * from t1 ORDER BY k'
 k |       v
---+---------------
 3 | tres txn 2
 4 | cuatro no txn
 5 | cinco no txn
(3 rows)

++ sleep 6
++ ./bin/ysqlsh -h 127.0.0.22 -c 'SELECT * from t1 ORDER BY k'
 k |       v
---+---------------
 3 | tres txn 2
 4 | cuatro no txn
 5 | cinco no txn
(3 rows)

++ ./bin/ysqlsh -h 127.0.0.11 -c 'ALTER TABLE t1 ADD COLUMN v2 int'
ALTER TABLE
++ ./bin/ysqlsh -h 127.0.0.11 -c 'SELECT * FROM t1'
 k |       v       | v2
---+---------------+----
 5 | cinco no txn  |
 1 | uno txn 1     |
 4 | cuatro no txn |
 0 | cero no txn   |
 2 | dos txn 1     |
 3 | tres txn 2    |
(6 rows)
```

Reviewers: rahuldesirazu, nicolas

Reviewed By: nicolas

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D9365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cdc Change Data Capture
Projects
None yet
Development

No branches or pull requests

1 participant