Skip to content

Commit

Permalink
cluster: forbid disabling internal topics/partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ztlpn committed Nov 28, 2023
1 parent b441e63 commit b1449fe
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/v/cluster/errc.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum class errc : int16_t {
trackable_keys_limit_exceeded,
topic_disabled,
partition_disabled,
invalid_partition_operation,
};
struct errc_category final : public std::error_category {
const char* name() const noexcept final { return "cluster::errc"; }
Expand Down Expand Up @@ -220,6 +221,8 @@ struct errc_category final : public std::error_category {
return "Topic disabled by user";
case errc::partition_disabled:
return "Partition disabled by user";
case errc::invalid_partition_operation:
return "Invalid partition operation";
}
return "cluster::errc::unknown";
}
Expand Down
4 changes: 4 additions & 0 deletions src/v/cluster/topics_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,10 @@ ss::future<std::error_code> topics_frontend::set_topic_partitions_disabled(
co_return errc::feature_disabled;
}

if (!model::is_user_topic(ns_tp)) {
co_return errc::invalid_partition_operation;
}

auto r = co_await stm_linearizable_barrier(timeout);
if (!r) {
co_return r.error();
Expand Down
1 change: 1 addition & 0 deletions src/v/kafka/server/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ constexpr error_code map_topic_error_code(cluster::errc code) {
case cluster::errc::transform_invalid_update:
case cluster::errc::transform_invalid_source:
case cluster::errc::trackable_keys_limit_exceeded:
case cluster::errc::invalid_partition_operation:
break;
}
return error_code::unknown_server_error;
Expand Down
1 change: 1 addition & 0 deletions src/v/redpanda/admin/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,7 @@ ss::future<> admin_server::throw_on_error(
case cluster::errc::transform_invalid_environment:
case cluster::errc::source_topic_not_exists:
case cluster::errc::source_topic_still_in_use:
case cluster::errc::invalid_partition_operation:
throw ss::httpd::bad_request_exception(
fmt::format("{}", ec.message()));
default:
Expand Down
8 changes: 8 additions & 0 deletions tests/rptest/tests/recovery_mode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import dataclasses

from ducktape.utils.util import wait_until
from requests.exceptions import HTTPError

from rptest.tests.redpanda_test import RedpandaTest
from rptest.services.redpanda import RESTART_LOG_ALLOW_LIST
Expand Down Expand Up @@ -240,6 +241,13 @@ def test_apis(self):
rpk = RpkTool(self.redpanda)
admin = Admin(self.redpanda)

try:
admin.set_partitions_disabled(ns="redpanda", topic="controller")
except HTTPError as e:
assert e.response.status_code == 400
else:
assert False, "disabling internal topics should fail"

topics = ["mytopic1", "mytopic2", "mytopic3", "mytopic4"]
for topic in topics:
rpk.create_topic(topic, partitions=3, replicas=3)
Expand Down

0 comments on commit b1449fe

Please sign in to comment.