Skip to content

Commit

Permalink
WIP k/create_topics: iceberg_partition_spec property validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ztlpn committed Jan 21, 2025
1 parent 54cff39 commit 8af772e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/v/kafka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ v_cc_library(
v::bytes
v::rpc
v::cluster
v::iceberg_unresolved_partition_spec
v::kafka_partition_proxy
v::kafka_protocol
v::security
Expand Down
1 change: 1 addition & 0 deletions src/v/kafka/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ redpanda_cc_library(
"//src/v/features",
"//src/v/hashing:jump_consistent",
"//src/v/hashing:xx",
"//src/v/iceberg:unresolved_partition_spec",
"//src/v/kafka/data:partition_proxy",
"//src/v/kafka/protocol",
"//src/v/kafka/protocol:add_offsets_to_txn",
Expand Down
34 changes: 25 additions & 9 deletions src/v/kafka/server/handlers/topics/validators.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#pragma once
#include "config/configuration.h"
#include "iceberg/unresolved_partition_spec.h"
#include "kafka/protocol/schemata/create_topics_request.h"
#include "kafka/protocol/schemata/create_topics_response.h"
#include "kafka/server/handlers/topics/types.h"
Expand Down Expand Up @@ -276,22 +277,37 @@ struct iceberg_config_validator {
static constexpr error_code ec = error_code::invalid_config;

static bool is_valid(const creatable_topic& c) {
auto it = std::find_if(
model::iceberg_mode parsed_mode = model::iceberg_mode::disabled;

auto mode_it = std::find_if(
c.configs.begin(),
c.configs.end(),
[](const createable_topic_config& cfg) {
return cfg.name == topic_property_iceberg_mode;
});
if (it == c.configs.end() || !it->value.has_value()) {
return true;
if (mode_it != c.configs.end() && mode_it->value.has_value()) {
try {
parsed_mode = boost::lexical_cast<model::iceberg_mode>(
mode_it->value.value());
} catch (...) {
return false;
}
}
model::iceberg_mode parsed_mode;
try {
parsed_mode = boost::lexical_cast<model::iceberg_mode>(
it->value.value());
} catch (...) {
return false;

auto pspec_it = std::find_if(
c.configs.begin(),
c.configs.end(),
[](const createable_topic_config& cfg) {
return cfg.name == topic_property_iceberg_partition_spec;
});
if (pspec_it != c.configs.end() && pspec_it->value.has_value()) {
auto parsed = iceberg::unresolved_partition_spec::parse(
pspec_it->value.value());
if (!parsed.has_value()) {
return false;
}
}

// If iceberg is enabled at the cluster level, the topic can
// be created with any override. If it is disabled
// at the cluster level, it cannot be enabled with a topic
Expand Down

0 comments on commit 8af772e

Please sign in to comment.