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

Fix handling of JSON columns (#3643) #3653

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #3643

What problem does this PR solve?

Closes #3624

What is changed and how it works?

When inserting valid JSON into a column of the json type this happens:

panic: interface conversion: interface {} is string, not json.BinaryJSON

goroutine 1228 [running]:
github.com/pingcap/ticdc/cdc/sink/codec.columnToAvroNativeData(0xc003f93bc0, 0xc000e14cb0, 0xc0027471c8, 0x2, 0xc00197a1a8, 0xd, 0x0, 0x0)
	github.com/pingcap/ticdc/cdc/sink/codec/avro.go:479 +0x19c5
github.com/pingcap/ticdc/cdc/sink/codec.rowToAvroNativeData(0xc00274e1f0, 0x2, 0x2, 0xc000e14cb0, 0x4, 0xc002747190, 0xc, 0x37)
	github.com/pingcap/ticdc/cdc/sink/codec/avro.go:274 +0xa8
github.com/pingcap/ticdc/cdc/sink/codec.avroEncode(0xc003f93bf0, 0xc0026817c0, 0x5f5736086ec0002, 0xc00274e1f0, 0x2, 0x2, 0xc000e14cb0, 0xc0044ef560, 0xc0044ef570, 0x3a071e8)
	github.com/pingcap/ticdc/cdc/sink/codec/avro.go:197 +0x191
github.com/pingcap/ticdc/cdc/sink/codec.(*AvroEventBatchEncoder).AppendRowChangedEvent(0xc002615200, 0xc001b52280, 0x0, 0x0, 0x3)
	github.com/pingcap/ticdc/cdc/sink/codec/avro.go:94 +0x830
github.com/pingcap/ticdc/cdc/sink.(*mqSink).runWorker(0xc0018fc280, 0x3a34708, 0xc0018aa1c0, 0x2, 0x0, 0x0)
	github.com/pingcap/ticdc/cdc/sink/mq.go:345 +0x3f1
github.com/pingcap/ticdc/cdc/sink.(*mqSink).run.func1(0x0, 0x0)
	github.com/pingcap/ticdc/cdc/sink/mq.go:275 +0x46
golang.org/x/sync/errgroup.(*Group).Go.func1(0xc0026151d0, 0xc002941400)
	golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:57 +0x59
created by golang.org/x/sync/errgroup.(*Group).Go
	golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:54 +0x66

The Value seems to be a string instead of json.BinaryJSON as the error indicates

(dlv) print col
*github.com/pingcap/ticdc/cdc/model.Column {
	Name: "json_payload",
	Type: 245,
	Flag: BinaryFlag|NullableFlag (65),
	Value: interface {}(string) "{\"foo\": \"bar\"}",}

Manual test

Setup a test environment:

tiup playground v5.2.2 --tiflash 0 --without-monitor=false
./bin/cdc server
curl --silent --output docker-compose.yml https://raw.githubusercontent.com/confluentinc/cp-all-in-one/6.2.0-post/cp-all-in-one-community/docker-compose.yml
sudo docker-compose up -d
./bin/cdc cli changefeed create --no-confirm --changefeed-id="simple-replication-task" --sort-engine="unified" --sink-uri="kafka://127.0.0.1:9092/cdc-test?protocol=avro&kafka-version=2.8.0" --log-level debug --opts registry="http://127.0.0.1:8081"

Create a table and insert some JSON:

CREATE TABLE `sample_table` (
  `id` bigint(20) unsigned primary key NOT NULL AUTO_INCREMENT,
  `json_payload` json DEFAULT NULL
);
INSERT INTO sample_table(json_payload) VALUES(NULL);
INSERT INTO sample_table(json_payload) VALUES(JSON_OBJECT('foo', 'bar'));
SELECT * FROM sample_table;

Start an Avro Console Consumer:

sudo docker-compose exec schema-registry /bin/sh
kafka-avro-console-consumer  --topic cdc-test --from-beginning --bootstrap-server broker:29092

Output:

{"id":"\t","json_payload":{"string":"{\"foo\": \"bar\"}"}}

Check List

Tests

  • Manual test (add detailed scripts or steps below)

Related changes

  • Need to cherry-pick to the release branch

Release note

The Avro sink was updated to handle JSON columns

@ti-chi-bot
Copy link
Member Author

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/cherry-pick-not-approved release-note Denotes a PR that will be considered when it comes time to generate release notes. component/sink Sink component. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug. type/cherry-pick-for-release-5.2 This PR is cherry-picked to release-5.2 from a source PR. labels Nov 29, 2021
@ti-chi-bot
Copy link
Member Author

@dveeden: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

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 ti-community-infra/tichi repository.

@nongfushanquan nongfushanquan added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Dec 3, 2021
@amyangfei amyangfei added this to the v5.2.4 milestone Dec 8, 2021
@amyangfei
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member Author

This pull request has been accepted and is ready to merge.

Commit hash: e189e50

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 8, 2021
@ti-chi-bot
Copy link
Member Author

@ti-chi-bot: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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 ti-community-infra/tichi repository.

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (release-5.2@07f1965). Click here to learn what that means.
The diff coverage is n/a.

@@               Coverage Diff                @@
##             release-5.2      #3653   +/-   ##
================================================
  Coverage               ?   54.0674%           
================================================
  Files                  ?        192           
  Lines                  ?      21549           
  Branches               ?          0           
================================================
  Hits                   ?      11651           
  Misses                 ?       8805           
  Partials               ?       1093           

@ti-chi-bot ti-chi-bot merged commit 632f53e into pingcap:release-5.2 Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Cherry pick PR approved by release team. component/sink Sink component. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug. type/cherry-pick-for-release-5.2 This PR is cherry-picked to release-5.2 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants