Skip to content

Commit

Permalink
Merge pull request #24107 from oleiman/euse/core-8102/schema-validati…
Browse files Browse the repository at this point in the history
…on-sanctions-alter-followup

[CORE-8102] Separate key and value schema ID validation sanctions
  • Loading branch information
oleiman authored Nov 14, 2024
2 parents 39638eb + 2856989 commit 6924b5b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/v/cluster/topics_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,24 @@ std::vector<std::string_view> get_enterprise_features(
features.emplace_back("tiered storage");
}

constexpr auto schema_id_validation_enabled =
static constexpr auto key_schema_id_validation_enabled =
[](const cluster::topic_properties& pp) -> bool {
return pp.record_key_schema_id_validation.value_or(false)
|| pp.record_key_schema_id_validation_compat.value_or(false)
|| pp.record_value_schema_id_validation.value_or(false)
|| pp.record_key_schema_id_validation_compat.value_or(false);
};

static constexpr auto value_schema_id_validation_enabled =
[](const cluster::topic_properties& pp) -> bool {
return pp.record_value_schema_id_validation.value_or(false)
|| pp.record_value_schema_id_validation_compat.value_or(false);
};

static constexpr auto schema_id_validation_enabled =
[](const cluster::topic_properties& pp) -> bool {
return key_schema_id_validation_enabled(pp)
|| value_schema_id_validation_enabled(pp);
};

constexpr auto unset_or_unchanged =
[](
const reflection::is_std_optional auto& curr,
Expand Down Expand Up @@ -152,8 +162,9 @@ std::vector<std::string_view> get_enterprise_features(
};

if (
(schema_id_validation_enabled(properties)
< schema_id_validation_enabled(updated_properties))
((key_schema_id_validation_enabled(properties)
< key_schema_id_validation_enabled(updated_properties))
|| (value_schema_id_validation_enabled(properties) < value_schema_id_validation_enabled(updated_properties)))
|| (schema_id_validation_enabled(updated_properties) && sns_modified())) {
features.emplace_back("schema id validation");
}
Expand Down
34 changes: 34 additions & 0 deletions src/v/kafka/server/tests/alter_config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,40 @@ FIXTURE_TEST(test_unlicensed_alter_configs, alter_config_test_fixture) {
},
failure);

const auto key_validation = props_t{
with(kafka::topic_property_record_key_schema_id_validation, true),
};
test_cases.emplace_back(
"set_value_after_key",
key_validation,
alter_props_t{{set(
kafka::topic_property_record_value_schema_id_validation_compat,
true)}},
failure);
test_cases.emplace_back(
"unset_key",
key_validation,
alter_props_t{{set(
kafka::topic_property_record_key_schema_id_validation, false)}},
success);

const auto value_validation = props_t{
with(kafka::topic_property_record_value_schema_id_validation, true),
};
test_cases.emplace_back(
"set_key_after_value",
value_validation,
alter_props_t{{set(
kafka::topic_property_record_key_schema_id_validation_compat,
true)}},
failure);
test_cases.emplace_back(
"unset_value",
value_validation,
alter_props_t{{set(
kafka::topic_property_record_value_schema_id_validation, false)}},
success);

const auto validation_with_strat = props_t{
with(kafka::topic_property_record_key_schema_id_validation, true),
with(kafka::topic_property_record_value_schema_id_validation, true),
Expand Down

0 comments on commit 6924b5b

Please sign in to comment.