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

changefeedccl: fix bug with avro encoding and zero-scale decimal cols #118815

Merged
merged 1 commit into from Feb 6, 2024

Conversation

andyyang890
Copy link
Collaborator

@andyyang890 andyyang890 commented Feb 6, 2024

This patch fixes a bug where creating a changefeed that targeted
tables with a DECIMAL(n) column (i.e. zero-scale DECIMAL column),
format='avro', and diff would cause a panic.

The cause of this panic was the fact that the third-party goavro
library we use expected the JSON encoding of the schema to have
a numeric scale field for decimal types, but we omitted this
field whenever it was zero (using omitempty), which led to a
runtime type assertion failure. We've updated the field to a pointer
type in our type definition so that we can distinguish between an
unset value and a zero value.

Fixes #118647

Release note (enterprise change): Fixed a bug where creating a
changefeed that targeted tables with a DECIMAL(n) column
(i.e. zero-scale DECIMAL column), format='avro', and diff
would cause a panic.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@andyyang890
Copy link
Collaborator Author

An alternative idea would be to either submit a patch to goavro directly (seems like it hasn't been updated in 2 years so not sure if that's feasible) or fork it and patch it in our own fork.

Copy link
Contributor

@jayshrivastava jayshrivastava left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andyyang890, @nicktrav, @rharding6373, and @wenyihu6)


pkg/ccl/changefeedccl/avro.go line 78 at r1 (raw file):

	SchemaType  avroSchemaType `json:"type"`
	LogicalType string         `json:"logicalType"`
	Precision   int            `json:"precision,omitempty"`

Looks like tests are failing due to precision 0 and scale 0 being included when they shouldn't. Maybe we need to do this https://stackoverflow.com/questions/38486564/unmarshal-marshal-json-with-int-set-to-0-does-not-seem-to-work

This patch fixes a bug where creating a changefeed that targeted
tables with a `DECIMAL(n)` column (i.e. zero-scale `DECIMAL` column),
`format='avro'`, and `diff` would cause a panic.

The cause of this panic was the fact that the third-party `goavro`
library we use expected the JSON encoding of the schema to have
a numeric `scale` field for decimal types, but we omitted this
field whenever it was zero (using `omitempty`), which led to a
runtime type assertion failure. We've updated the field to a pointer
type in our type definition so that we can distinguish between an
unset value and a zero value.

Release note (enterprise change): Fixed a bug where creating a
changefeed that targeted tables with a `DECIMAL(n)` column
(i.e. zero-scale `DECIMAL` column), `format='avro'`, and `diff`
would cause a panic.
Copy link
Collaborator Author

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jayshrivastava, @nicktrav, @rharding6373, and @wenyihu6)


pkg/ccl/changefeedccl/avro.go line 78 at r1 (raw file):

Previously, jayshrivastava (Jayant) wrote…

Looks like tests are failing due to precision 0 and scale 0 being included when they shouldn't. Maybe we need to do this https://stackoverflow.com/questions/38486564/unmarshal-marshal-json-with-int-set-to-0-does-not-seem-to-work

Done. Thanks for the pointer (no pun intended).

@andyyang890 andyyang890 added backport-23.1.x Flags PRs that need to be backported to 23.1 backport-23.2.x Flags PRs that need to be backported to 23.2. labels Feb 6, 2024
Copy link
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

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

:lgtm: Good find!

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @jayshrivastava, @nicktrav, and @wenyihu6)

@andyyang890
Copy link
Collaborator Author

TFTRs!

bors r=jayshrivastava,rharding6373

@craig
Copy link
Contributor

craig bot commented Feb 6, 2024

Build succeeded:

@craig craig bot merged commit 17f1eac into cockroachdb:master Feb 6, 2024
9 of 10 checks passed
Copy link

blathers-crl bot commented Feb 6, 2024

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 907aaa6 to blathers/backport-release-23.1-118815: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@andyyang890
Copy link
Collaborator Author

blathers backport 23.2.1-rc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1 backport-23.2.x Flags PRs that need to be backported to 23.2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

changefeedccl: node crash after altering a table with an avro changefeed
4 participants