Skip to content

Commit

Permalink
schema_registry/store: Soft-deleted sub-ver are not references
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Pope <ben@redpanda.com>
  • Loading branch information
BenPope committed Jun 5, 2023
1 parent 8789740 commit 38c3b01
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/v/pandaproxy/schema_registry/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class store {
std::vector<schema_id> has_ids;
for (const auto& s : _subjects) {
for (const auto& r : s.second.versions) {
if (absl::c_binary_search(ids, r.id)) {
if (!r.deleted && absl::c_binary_search(ids, r.id)) {
has_ids.push_back(r.id);
}
}
Expand All @@ -333,8 +333,8 @@ class store {

bool subject_versions_has_any_of(const std::vector<schema_id>& ids) {
return absl::c_any_of(_subjects, [&ids](const auto& s) {
return absl::c_any_of(s.second.versions, [&ids](const auto& v) {
return absl::c_binary_search(ids, v.id);
return absl::c_any_of(s.second.versions, [&ids, &s](const auto& v) {
return !s.second.deleted && absl::c_binary_search(ids, v.id);
});
});
}
Expand Down
21 changes: 2 additions & 19 deletions src/v/pandaproxy/schema_registry/test/delete_subject_endpoints.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ FIXTURE_TEST(test_delete_referenced_subject, pandaproxy_test_fixture) {
}

{
info("Delete subject int-key, expect failure 42206");
info("Delete subject int-key, expect failure 42206 (still referenced)");
auto res = delete_subject(client, pps::subject{"int-key"});
BOOST_REQUIRE_EQUAL(
res.headers.result(),
Expand All @@ -193,24 +193,7 @@ FIXTURE_TEST(test_delete_referenced_subject, pandaproxy_test_fixture) {
}

{
info("Delete subject int-key");
auto res = delete_subject(client, pps::subject{"int-key"});
BOOST_REQUIRE_EQUAL(
res.headers.result(),
boost::beast::http::status::unprocessable_entity);
BOOST_REQUIRE_EQUAL(get_body_error_code(res.body), 42206);
}

{
info("Permanantly delete subject reference-key");
auto res = delete_subject(
client, pps::subject{"reference-key"}, pps::permanent_delete::yes);
BOOST_REQUIRE_EQUAL(
res.headers.result(), boost::beast::http::status::ok);
}

{
info("Delete subject int-key");
info("Delete subject int-key (not referenced - soft deleted)");
auto res = delete_subject(client, pps::subject{"int-key"});
BOOST_REQUIRE_EQUAL(
res.headers.result(), boost::beast::http::status::ok);
Expand Down
20 changes: 20 additions & 0 deletions src/v/pandaproxy/schema_registry/test/sharded_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ SEASTAR_THREAD_TEST_CASE(test_sharded_store_referenced_by) {
BOOST_REQUIRE(
store.is_referenced(pps::subject{"simple.proto"}, pps::schema_version{1})
.get());

// soft delete subject
store
.upsert(
pps::seq_marker{
std::nullopt, std::nullopt, ver1, pps::seq_marker_key_type::schema},
importing_schema,
pps::schema_id{2},
ver1,
pps::is_deleted::yes)
.get();

// Soft-deleted should not partake in reference calculations
BOOST_REQUIRE(
store.referenced_by(pps::subject{"simple.proto"}, pps::schema_version{1})
.get()
.empty());
BOOST_REQUIRE(
!store.is_referenced(pps::subject{"simple.proto"}, pps::schema_version{1})
.get());
}

SEASTAR_THREAD_TEST_CASE(test_sharded_store_find_unordered) {
Expand Down

0 comments on commit 38c3b01

Please sign in to comment.