Skip to content

Commit

Permalink
schema_registry: Clear config if last version deleted
Browse files Browse the repository at this point in the history
When the last version is soft-deleted, the config should be cleared.

Signed-off-by: Ben Pope <ben@redpanda.com>
  • Loading branch information
BenPope committed Jun 24, 2024
1 parent c8a0a6e commit d97925d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/v/pandaproxy/schema_registry/seq_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,13 @@ ss::future<std::optional<bool>> seq_writer::do_delete_subject_version(
batch_builder rb(write_at, sub);
rb(std::move(key), std::move(value));

{
// Clear config if this is a delete of the last version
auto vec = co_await _store.get_versions(sub, include_deleted::no);
if (vec.size() == 1 && vec.front() == version) {
rb(co_await _store.get_subject_config_written_at(sub));
}
}
if (co_await produce_and_apply(write_at, std::move(rb).build())) {
co_return true;
} else {
Expand Down
58 changes: 58 additions & 0 deletions tests/rptest/tests/schema_registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,64 @@ def test_delete_subject_bug(self):
assert result_raw.status_code == requests.codes.ok, f'Code: {result_raw.status_code}'
assert result_raw.json() == [3, 4], f"Json: {result_raw.json()}"

@cluster(num_nodes=3)
def test_delete_subject_last_clears_config(self):
topic = 'foo'

self.logger.debug("Set subject config - NONE")
result_raw = self._set_config_subject(subject=f"{topic}-key",
data=json.dumps(
{"compatibility": "NONE"}),
auth=self.super_auth)
assert result_raw.status_code == requests.codes.ok

self.logger.debug(f"Register a schema against a subject")
schema_1_data = json.dumps({"schema": schema1_def})
schema_3_data = json.dumps({"schema": schema3_def})

self.logger.debug("Posting schema 1 as a subject key")
result_raw = self._post_subjects_subject_versions(
subject=f"{topic}-key", data=schema_1_data, auth=self.super_auth)
self.logger.debug(result_raw)
assert result_raw.status_code == requests.codes.ok

self.logger.debug("Get subject config - should be overriden")
result_raw = self._get_config_subject(subject=f"{topic}-key",
auth=self.super_auth)
assert result_raw.json()["compatibilityLevel"] == "NONE"

self.logger.debug("Soft delete subject 1 version 1")
result_raw = self._delete_subject_version(subject=f"{topic}-key",
version=1,
auth=self.super_auth)
assert result_raw.status_code == requests.codes.ok, f'Code: {result_raw.status_code}'
assert result_raw.json() == 1, f"Json: {result_raw.json()}"

self.logger.debug("Get subject config - should fail")
result_raw = self._get_config_subject(subject=f"{topic}-key",
auth=self.super_auth)
assert result_raw.status_code == requests.codes.not_found
assert result_raw.json()["error_code"] == 40408

self.logger.debug("Posting schema 1 as a subject key")
result_raw = self._post_subjects_subject_versions(
subject=f"{topic}-key", data=schema_1_data, auth=self.super_auth)
self.logger.debug(result_raw)
assert result_raw.status_code == requests.codes.ok

self.logger.debug(
"Posting incompatible schema 3 as a subject key - expect conflict")
result_raw = self._post_subjects_subject_versions(
subject=f"{topic}-key", data=schema_3_data, auth=self.super_auth)
self.logger.debug(result_raw)
assert result_raw.status_code == requests.codes.conflict

self.logger.debug("Get subject config - should fail")
result_raw = self._get_config_subject(subject=f"{topic}-key",
auth=self.super_auth)
assert result_raw.status_code == requests.codes.not_found
assert result_raw.json()["error_code"] == 40408


class SchemaRegistryTest(SchemaRegistryTestMethods):
"""
Expand Down

0 comments on commit d97925d

Please sign in to comment.