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

encoding default "null" failed in avro protocol #11994

Closed
wk989898 opened this issue Jan 11, 2025 · 1 comment · Fixed by #11995
Closed

encoding default "null" failed in avro protocol #11994

wk989898 opened this issue Jan 11, 2025 · 1 comment · Fixed by #11995
Labels
affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. area/ticdc Issues or PRs related to TiCDC. severity/critical type/bug The issue is confirmed as a bug.

Comments

@wk989898
Copy link
Collaborator

wk989898 commented Jan 11, 2025

What did you do?

  1. run a changefeed with Avro protocol
  2. run sql
create table t31(
    id int primary key,
    col varchar(255) DEFAULT "null"
);

insert into t31(id) values(2);

What did you expect to see?

No response

What did you see instead?

[ERROR] [schema_registry.go:335] ["GetCachedOrRegister: Could not make goavro codec"] [error="Record \"default.test.t31\" field \"col\": default value ought to encode using field schema: cannot encode binary bytes: expected: string; received: <nil>"]
[ERROR] [avro.go:102] ["AppendRowChangedEvent: avro encoding failed"] [error="[CDC:ErrAvroSchemaAPIError]schema manager API error: Record \"default.test.t31\" field \"col\": default value ought to encode using field schema: cannot encode binary bytes: expected: string; received: <nil>"] [errorVerbose="[CDC:ErrAvroSchemaAPIError]schema manager API error: Record \"default.test.t31\" field \"col\": default value ought to encode using field schema: cannot encode binary bytes: expected: string; received: <nil>\ngithub.com/pingcap/errors.AddStack\n\tgithub.com/pingcap/[email protected]/errors.go:174\ngithub.com/pingcap/errors.(*Error).GenWithStackByArgs\n\tgithub.com/pingcap/[email protected]/normalize.go:164\ngithub.com/pingcap/tiflow/pkg/errors.WrapError\n\tgithub.com/pingcap/tiflow/pkg/errors/helper.go:34\ngithub.com/pingcap/tiflow/pkg/sink/codec/avro.(*schemaManager).GetCachedOrRegister\n\tgithub.com/pingcap/tiflow/pkg/sink/codec/avro/schema_registry.go:336\ngithub.com/pingcap/tiflow/pkg/sink/codec/avro.(*BatchEncoder).avroEncode\n\tgithub.com/pingcap/tiflow/pkg/sink/codec/avro/avro.go:227\ngithub.com/pingcap/tiflow/pkg/sink/codec/avro.(*BatchEncoder).AppendRowChangedEvent\n\tgithub.com/pingcap/tiflow/pkg/sink/codec/avro/avro.go:100\ngithub.com/pingcap/tiflow/pkg/sink/codec.(*encoderGroup).runEncoder\n\tgithub.com/pingcap/tiflow/pkg/sink/codec/encoder_group.go:116\ngithub.com/pingcap/tiflow/pkg/sink/codec.(*encoderGroup).Run.func2\n\tgithub.com/pingcap/tiflow/pkg/sink/codec/encoder_group.go:95\ngolang.org/x/sync/errgroup.(*Group).Go.func1\n\tgolang.org/x/[email protected]/errgroup/errgroup.go:75\nruntime.goexit\n\truntime/asm_amd64.s:1598"]

Versions of the cluster

TiCDC version (execute cdc version):

v7.1.3
@wk989898 wk989898 added area/ticdc Issues or PRs related to TiCDC. type/bug The issue is confirmed as a bug. labels Jan 11, 2025
@wk989898
Copy link
Collaborator Author

wk989898 commented Jan 11, 2025

The root reason is goavro treats string literal "null" as null, but TiCDC doesn't .

// https://stackoverflow.com/questions/22938124/avro-field-default-values
if defaultValue == nil {
field["type"] = []interface{}{"null", avroType}
} else {
field["type"] = []interface{}{avroType, "null"}
}
field["default"] = defaultValue

goavro code:
https://github.com/linkedin/goavro/blob/5ec5a5ee7ec82e16e6e2b438d610e1cab2588393/record.go#L109-L114

@wk989898 wk989898 added affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. labels Jan 11, 2025
@wk989898 wk989898 added needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. severity/moderate severity/critical and removed needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. severity/moderate labels Jan 11, 2025
@ti-chi-bot ti-chi-bot bot closed this as completed in fbd02e7 Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. area/ticdc Issues or PRs related to TiCDC. severity/critical type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants