Skip to content

2.31.0.0-b191

@Sumukh-Phalgaonkar Sumukh-Phalgaonkar tagged this 23 Jun 10:19
Summary:
##### Code changes summary
Currently when a replication slot is created, retention barriers are setup and cdc_state table entries are written for all the tablets in the DB. In an environment where large number of tables are present and only a small subset is being used for CDC, this leads to unnecessary retention barrier setup. Also the cdc_state table is bloated with unnecessary entries.

To prevent this, this diff introduces a mechanism to create gRPC streams that are bound to only specific tables at the time of their creation. To create such a stream, a comma separated list of  table ids should be provided to the create_change_data_stream yb-admin command. The syntax is as follows:

```
./yb-admin create_change_data_stream ysql.<DB-name> EXPLICIT CHANGE NOEXPORT_SNAPSHOT DYNAMIC_TABLES_DISABLED <comma separated table_ids>
```
 For example:
```
./yb-admin create_change_data_stream ysql.yugabyte EXPLICIT CHANGE NOEXPORT_SNAPSHOT DYNAMIC_TABLES_DISABLED 000034e1000030008000000000004000,000034e1000030008000000000004005
CDC Stream ID: 9fbec9b0395a2caacd48676d714ced0d

```

The table_ids are passed to the `CreateCDCStream` rpc by populating the `bound_table_ids` field in the `CDCSDKStreamCreateOptionsPB`.  Only these table_ids are written to the stream metadata. The retention barriers are set on the tablets of only these tables, and their entries are written to the cdc_state table.

Dynamic table addition is disabled for the table bound streams, meaning that the tables which can be polled using these streams is fixed at the stream creation. Any attmept to create such streams with dynamic tables enabled will fail. Also such streams can only be created for gRPC model.

##### Upgrade / Rollback safety
Only proto change made in this diff is in `CDCSDKStreamCreateOptionsPB` which is a part of `CreateCDCStreamRequestPB`. The CreateCDCStream rpc flows from the tserver to the master. Since all the masters are upgraded before the tservers, this change is upgrade safe.

Additionally the bound_table_ids field added in `CDCSDKStreamCreateOptionsPB` is an optional field. To make the repeated field optional it has been wrapped in a separate proto called  `CDCSDKBoundTableIds`.

A table bound stream created before rollback will continue to operate as intended after rollback, i.e post rollback user can use the table bound stream to get the change events from the tables present in the stream metadata. Hence this change is rollback safe.

##### Considerations for colocated tables
If a stream is created such that it is bound to subset of colocated tables residing on the tablet, cdcsdk_producer will filter out the change records corresponding to other tables.

##### Considerations for connector
NA

Test Plan:
New tests added:
  - ./yb_build.sh --cxx-test integration-tests_cdcsdk_ysql-test --gtest_filter 'CDCSDKYsqlTest.TestgRPCStreamBoundToSpecificTables'
  - ./yb_build.sh --cxx-test integration-tests_cdcsdk_ysql-test --gtest_filter 'CDCSDKYsqlTest.TestgRPCStreamBoundToSpecificColocatedTables'
  - ./yb_build.sh --cxx-test integration-tests_cdcsdk_ysql-test --gtest_filter 'CDCSDKYsqlTest.TestTableBoundStreamRejectsWithReplicationSlot'
  - ./yb_build.sh --cxx-test integration-tests_cdcsdk_ysql-test --gtest_filter 'CDCSDKYsqlTest.TestTableBoundStreamDisablesDynamicAddition'
  - ./yb_build.sh --cxx-test integration-tests_cdcsdk_ysql-test --gtest_filter 'CDCSDKYsqlTest.TestCreationOfgRPCStreamBoundToSpecificTablesViaYBAdmin'
  - ./yb_build.sh --cxx-test integration-tests_cdcsdk_ysql-test --gtest_filter 'CDCSDKYsqlTest.TestTableBoundStreamYbAdminRejectsTableFromDifferentNamespace'
  - ./yb_build.sh --cxx-test integration-tests_cdcsdk_ysql-test --gtest_filter 'CDCSDKYsqlTest.TestTableBoundStreamYbAdminRejectsTableFromDifferentNamespaceTestTableBoundStreamYbAdminRejectsDynamicTablesEnabled'

Reviewers: xCluster, hsunder, skumar, asrinivasan, devansh.singhal, #db-approvers

Reviewed By: asrinivasan, #db-approvers

Subscribers: svc_phabricator, ybase

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D54632
Assets 2
Loading