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

cdc: Add Debezium protocol #10197

Merged
merged 30 commits into from
Dec 13, 2023
Merged

cdc: Add Debezium protocol #10197

merged 30 commits into from
Dec 13, 2023

Conversation

breezewish
Copy link
Member

@breezewish breezewish commented Nov 30, 2023

What problem does this PR solve?

Issue Number: ref #1799

What is changed and how it works?

  • Debezium output format for Kafka sink
  • Optimized for performance and memory footprint
  • Unit tests for the Debezium output format

Integration tests are now excluded from this PR, in order to make review easier.

Benchmark:

Debezium JSON using JSON Writer in this PR:

BenchmarkEncodeOneTinyColumn-10    	 2771671	       430.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkEncodeLargeText-10        	  974575	      1250 ns/op	       0 B/op	       0 allocs/op
BenchmarkEncodeLargeBinary-10      	  978442	      1143 ns/op	    1154 B/op	       3 allocs/op

Debezium JSON using golang's JSON Marshaler:

BenchmarkEncodeOneTinyColumn-10    	 1000000	      1007 ns/op	    1072 B/op	      10 allocs/op
BenchmarkEncodeLargeText-10        	  526785	      2144 ns/op	    3169 B/op	      12 allocs/op
BenchmarkEncodeLargeBinary-10      	  363991	      3232 ns/op	    5348 B/op	      13 allocs/op

Cancel JSON:

BenchmarkEncodeOneTinyColumn-10    	 2046062	       593.4 ns/op	     819 B/op	       6 allocs/op
BenchmarkEncodeLargeText-10        	  703260	      1544 ns/op	    2928 B/op	       7 allocs/op
BenchmarkEncodeLargeBinary-10      	  432828	      2508 ns/op	    3968 B/op	       9 allocs/op

Typical output from Debezum:

{
  "payload": {
    "after": {
      "id": 1
    },
    "before": null,
    "op": "c",
    "source": {
      "connector": "mysql",
      "db": "test",
      "file": "mysql-bin.000004",
      "gtid": null,
      "name": "dbserver1",
      "pos": 414547,
      "query": null,
      "row": 0,
      "sequence": null,
      "server_id": 223344,
      "snapshot": "false",
      "table": "tablename",
      "thread": 37,
      "ts_ms": 1701314261000,
      "version": "2.4.0.Final"
    },
    "transaction": null,
    "ts_ms": 1701314261838
  },
  "schema": {
    // ...
    // Schema omitted
  }
}

The output of TiCDC's Debezium format:

{
  "payload": {
    "after": {
      "id": 1
    },
    "before": null,
    "op": "c",
    "source": {
      "cluster_id": "",
      "commit_ts": 445989325844512800,
      "connector": "TiCDC",
      "db": "test",
      "file": "",
      "gtid": null,
      "name": "",
      "pos": 0,
      "query": null,
      "row": 0,
      "server_id": 0,
      "snapshot": "false",
      "table": "tablename",
      "thread": 0,
      "ts_ms": 1701314261797,
      "version": "2.4.0.Final"
    },
    "transaction": null,
    "ts_ms": 1701314270171
  }
}

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

cdc: Support Debezium output format for Kafka sink

Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. contribution This PR is from a community contributor. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Nov 30, 2023
Copy link
Contributor

ti-chi-bot bot commented Nov 30, 2023

Welcome @breezewish!

It looks like this is your first PR to pingcap/tiflow 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tiflow. 😃

Copy link
Contributor

ti-chi-bot bot commented Nov 30, 2023

Hi @breezewish. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Nov 30, 2023
Signed-off-by: Wish <breezewish@outlook.com>
@sre-bot
Copy link

sre-bot commented Nov 30, 2023

CLA assistant check
All committers have signed the CLA.

@@ -416,6 +416,10 @@ var (
"csv decode failed",
errors.RFCCodeText("CDC:ErrCSVDecodeFailed"),
)
ErrDebeziumEncodeFailed = errors.Normalize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simply use ErrEncodeFailed should be ok

Copy link
Member Author

@breezewish breezewish Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that all formats use its own error.

Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Dec 11, 2023
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
Signed-off-by: Wish <breezewish@outlook.com>
@ti-chi-bot ti-chi-bot bot added the lgtm label Dec 12, 2023
Copy link
Contributor

ti-chi-bot bot commented Dec 12, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3AceShowHand, asddongmen

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [3AceShowHand,asddongmen]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 12, 2023
Copy link
Contributor

ti-chi-bot bot commented Dec 12, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-11 03:56:02.637334318 +0000 UTC m=+242053.674561245: ☑️ agreed by asddongmen.
  • 2023-12-12 07:42:17.349744449 +0000 UTC m=+342028.386971376: ☑️ agreed by 3AceShowHand.

@breezewish
Copy link
Member Author

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved contribution This PR is from a community contributor. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. lgtm needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants