Skip to content

Commit

Permalink
sr/protobuf: Compatibility check: ONEOF_FIELD_REMOVED
Browse files Browse the repository at this point in the history
Signed-off-by: Oren Leiman <oren.leiman@redpanda.com>
  • Loading branch information
oleiman authored and pgellert committed Aug 8, 2024
1 parent ef09c89 commit cfd74f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/v/pandaproxy/schema_registry/protobuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ struct compatibility_checker {
}
}

for (int i = 0; i < writer->real_oneof_decl_count(); ++i) {
auto w = writer->oneof_decl(i);
if (!check_compatible(reader, w)) {
return false;
}
}

for (int i = 0; i < reader->real_oneof_decl_count(); ++i) {
auto r = reader->oneof_decl(i);
if (!check_compatible(r, writer)) {
Expand Down Expand Up @@ -539,6 +546,25 @@ struct compatibility_checker {
return true;
}

bool check_compatible(
const pb::Descriptor* reader, const pb::OneofDescriptor* writer) {
// If the oneof in question doesn't appear in the reader descriptor,
// then we don't need to account for any difference in fields.
if (!reader->FindOneofByName(writer->name())) {
return true;
}

for (int i = 0; i < writer->field_count(); ++i) {
auto w = writer->field(i);
auto r = reader->FindFieldByNumber(w->number());

if (!r || !r->real_containing_oneof()) {
return false;
}
}
return true;
}

bool check_compatible(
const pb::OneofDescriptor* reader, const pb::Descriptor* writer) {
// NOTE(oren): if a oneof disappears altogether, that doesn't cause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,10 @@ SEASTAR_THREAD_TEST_CASE(
R"(syntax = "proto3"; message Simple { int32 id = 1; int32 new_id = 2; })",
R"(syntax = "proto3"; message Simple { oneof wrapper { int32 id = 1; int32 new_id = 2; } })"));
}

SEASTAR_THREAD_TEST_CASE(test_protobuf_compatibility_oneof_field_removed) {
BOOST_REQUIRE(!check_compatible(
pps::compatibility_level::forward,
R"(syntax = "proto3"; message Simple { oneof wrapper { int32 id = 1; int32 new_id = 2; } })",
R"(syntax = "proto3"; message Simple { oneof wrapper { int32 id = 1; } })"));
}

0 comments on commit cfd74f7

Please sign in to comment.