diff --git a/src/v/pandaproxy/schema_registry/store.h b/src/v/pandaproxy/schema_registry/store.h index f57a411b9edd8..c18d28e5a7df9 100644 --- a/src/v/pandaproxy/schema_registry/store.h +++ b/src/v/pandaproxy/schema_registry/store.h @@ -323,7 +323,7 @@ class store { std::vector 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); } } @@ -333,8 +333,8 @@ class store { bool subject_versions_has_any_of(const std::vector& 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); }); }); } diff --git a/src/v/pandaproxy/schema_registry/test/delete_subject_endpoints.cc b/src/v/pandaproxy/schema_registry/test/delete_subject_endpoints.cc index c98eb0a3ca17e..b4db03bd3e9c9 100644 --- a/src/v/pandaproxy/schema_registry/test/delete_subject_endpoints.cc +++ b/src/v/pandaproxy/schema_registry/test/delete_subject_endpoints.cc @@ -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(), @@ -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); diff --git a/src/v/pandaproxy/schema_registry/test/sharded_store.cc b/src/v/pandaproxy/schema_registry/test/sharded_store.cc index 5ff505709145d..0687ee3f3bdf6 100644 --- a/src/v/pandaproxy/schema_registry/test/sharded_store.cc +++ b/src/v/pandaproxy/schema_registry/test/sharded_store.cc @@ -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) {