-
Notifications
You must be signed in to change notification settings - Fork 596
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(source): parse protobuf into expected struct/array #18419
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
control substitution on | ||
|
||
system ok | ||
rpk topic create 'test-pb-struct' | ||
|
||
|
||
system ok | ||
jq -sR '{"schema":.,"schemaType":"PROTOBUF"}' << EOF | curl -X POST -H 'content-type: application/json' -d @- "${RISEDEV_SCHEMA_REGISTRY_URL}/subjects/test-pb-struct-value/versions" | ||
syntax = "proto3"; | ||
package test; | ||
message User { | ||
int32 id = 1; | ||
Name name = 2; | ||
} | ||
message Name { | ||
string first_name = 1; | ||
string last_name = 2; | ||
} | ||
EOF | ||
|
||
|
||
# create a source with v1 schema | ||
statement ok | ||
create source s with ( | ||
${RISEDEV_KAFKA_WITH_OPTIONS_COMMON}, | ||
topic = 'test-pb-struct') | ||
format plain encode protobuf ( | ||
schema.registry = '${RISEDEV_SCHEMA_REGISTRY_URL}', | ||
message = 'test.User'); | ||
|
||
|
||
# register a v2 schema | ||
system ok | ||
jq -sR '{"schema":.,"schemaType":"PROTOBUF"}' << EOF | curl -X POST -H 'content-type: application/json' -d @- "${RISEDEV_SCHEMA_REGISTRY_URL}/subjects/test-pb-struct-value/versions" | ||
syntax = "proto3"; | ||
package test; | ||
message User { | ||
int32 id = 1; | ||
Name name = 2; | ||
} | ||
message Name { | ||
string first_name = 1; | ||
string last_name = 2; | ||
string middle_name = 3; | ||
} | ||
EOF | ||
|
||
|
||
# trigger recovery | ||
statement ok | ||
recover; | ||
|
||
|
||
sleep 2s | ||
|
||
|
||
# produce a v2 message | ||
statement ok | ||
create sink sk as select | ||
1 as id, | ||
row('Alan', 'Turing', 'Mathison')::struct<first_name varchar, last_name varchar, middle_name varchar> as name | ||
with ( | ||
${RISEDEV_KAFKA_WITH_OPTIONS_COMMON}, | ||
topic = 'test-pb-struct') | ||
format plain encode protobuf ( | ||
schema.registry = '${RISEDEV_SCHEMA_REGISTRY_URL}', | ||
message = 'test.User'); | ||
|
||
|
||
sleep 1s | ||
|
||
|
||
# reading as v1 shall not panic | ||
query IT | ||
select * from s; | ||
---- | ||
1 (Alan,Turing) | ||
Comment on lines
+73
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The panic reproduced on first commit of this PR:
|
||
|
||
|
||
statement ok | ||
drop sink sk; | ||
|
||
|
||
statement ok | ||
drop source s; | ||
|
||
|
||
system ok | ||
curl -X DELETE "${RISEDEV_SCHEMA_REGISTRY_URL}/subjects/test-pb-struct-value" | ||
|
||
|
||
system ok | ||
curl -X DELETE "${RISEDEV_SCHEMA_REGISTRY_URL}/subjects/test-pb-struct-value?permanent=true" | ||
|
||
|
||
system ok | ||
rpk topic delete 'test-pb-struct' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering why it's
recover
test, since it looks more likeschema-change
test to me. During off-line discussion, I found the story is quite complex:This is what schema change is like:
Generally, the parsing process is:
But there are subtleties. i.e., which schema to use to decode the data?
But we can see in both cases, there's a "reader schema" involved. Currently, this is fetched on startup, and the problem comes:
Problem of recovery
Since we don't persist schemaV1, but just fetch the current schema on recovery. (#12982)
It's actually like this:
So we may convert and
dataVN
toRW data
, instead ofdataV1
corresponding toschemaV1
, which is used to generateRW schema
.Therefore, we need to carefully ensure
RW schema
is respected when it's inconsistent fromschemaVN
. (This is what this PR does) Otherwise, we should persistschemaV1
Alternative
As mentioned above, since we already cannot ensure
schemaV1
is present, why not always using "writer schema", i.e., latest schema to decode the data, and then convertdataVN
toRW data
?Although
RW schema
is converted fromschemaV1
, this may be technically possible.However, there's one subtle edge case: it's possible to have protobuf without schema registry, but from file/HTTP. In this case, the schema might get lost and it will be unrecoverable. If we persist
schemaV1
, this can also be handled.Note about
REFRESH SCHEMA
What
REFRESH SCHEMA
does is to evolveRW schema
to a new one corresponding to the latestschemaVN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for elaborating on the issues here on my behalf 🙏