Skip to content

Commit

Permalink
cluster: extract allocation_node::is_internal_topic
Browse files Browse the repository at this point in the history
Pure refactor. Extract for reuse in the next commit.
  • Loading branch information
pgellert committed Dec 4, 2024
1 parent cccb53d commit 4b4f6a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/v/cluster/scheduling/allocation_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,26 @@ allocation_node::allocation_node(
});
}

bool allocation_node::is_full(
const model::ntp& ntp, bool will_add_allocation) const {
// Internal topics are excluded from checks to prevent allocation failures
// when creating them. This is okay because they are fairly small in number
// compared to kafka user topic partitions.
bool allocation_node::is_internal_topic(
const config::binding<std::vector<ss::sstring>>& internal_kafka_topics,
model::topic_namespace_view ntp) {
auto is_internal_ns = ntp.ns == model::redpanda_ns
|| ntp.ns == model::kafka_internal_namespace;
if (is_internal_ns) {
return false;
return true;
}
const auto& internal_topics = _internal_kafka_topics();
auto is_internal_topic = ntp.ns == model::kafka_namespace
&& std::any_of(
internal_topics.cbegin(),
internal_topics.cend(),
[&ntp](const ss::sstring& topic) {
return topic == ntp.tp.topic();
});
const auto& internal_topics = internal_kafka_topics();
return ntp.ns == model::kafka_namespace
&& std::any_of(
internal_topics.cbegin(),
internal_topics.cend(),
[&ntp](const ss::sstring& topic) { return topic == ntp.tp; });
}

bool allocation_node::is_full(
const model::ntp& ntp, bool will_add_allocation) const {
auto is_internal_topic = allocation_node::is_internal_topic(
_internal_kafka_topics, model::topic_namespace_view{ntp});

auto count = _allocated_partitions;
if (will_add_allocation) {
Expand Down
7 changes: 7 additions & 0 deletions src/v/cluster/scheduling/allocation_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ class allocation_node {
}
bool is_full(const model::ntp&, bool will_add_allocation) const;

// Internal topics are excluded from checks to prevent allocation failures
// when creating them. This is okay because they are fairly small in number
// compared to kafka user topic partitions.
static bool is_internal_topic(
const config::binding<std::vector<ss::sstring>>& internal_kafka_topics,
model::topic_namespace_view ntp);

private:
friend allocation_state;

Expand Down

0 comments on commit 4b4f6a2

Please sign in to comment.