99
1010#include " kafka/server/handlers/metadata.h"
1111
12+ #include " cluster/members_table.h"
1213#include " cluster/metadata_cache.h"
1314#include " cluster/topics_frontend.h"
1415#include " cluster/types.h"
2021#include " kafka/protocol/types.h"
2122#include " kafka/server/errors.h"
2223#include " kafka/server/fwd.h"
24+ #include " kafka/server/group_initializer.h"
2325#include " kafka/server/handlers/describe_cluster.h"
2426#include " kafka/server/handlers/details/leader_epoch.h"
2527#include " kafka/server/handlers/details/security.h"
2628#include " kafka/server/handlers/topics/topic_utils.h"
29+ #include " kafka/server/handlers/topics/types.h"
2730#include " kafka/server/response.h"
2831#include " model/errc.h"
2932#include " model/metadata.h"
3033#include " model/namespace.h"
3134#include " model/timeout_clock.h"
3235#include " random/generators.h"
3336#include " security/acl.h"
37+ #include " security/audit/audit_log_topic.h"
3438
3539#include < seastar/core/coroutine.hh>
3640#include < seastar/core/future-util.hh>
@@ -206,6 +210,49 @@ metadata_response::topic make_topic_response_from_topic_metadata(
206210}
207211
208212namespace {
213+ // / Internal topics requested by name are created with their owning
214+ // / subsystem's configuration rather than cluster defaults, mirroring Apache
215+ // / Kafka's special-casing of internal topics during metadata-driven topic
216+ // / auto-creation.
217+ cluster::topic_configuration
218+ autocreate_topic_configuration (request_context& ctx, model::topic topic) {
219+ if (topic == model::kafka_consumer_offsets_topic) {
220+ return consumer_offsets_topic_configuration (
221+ model::kafka_consumer_offsets_nt,
222+ cluster::internal_topic_replication (
223+ ctx.metadata_cache ().node_count ()));
224+ }
225+ if (topic == model::schema_registry_internal_tp.topic ) {
226+ return schema_registry_topic_configuration (
227+ cluster::internal_topic_replication (
228+ ctx.metadata_cache ().node_count ()));
229+ }
230+ if (topic == model::kafka_audit_logging_topic) {
231+ auto replication_factor
232+ = config::shard_local_cfg ().audit_log_replication_factor ().value_or (
233+ cluster::internal_topic_replication (
234+ ctx.metadata_cache ().node_count ()));
235+ cluster::topic_configuration cfg{
236+ model::kafka_namespace,
237+ std::move (topic),
238+ config::shard_local_cfg ().audit_log_num_partitions (),
239+ replication_factor};
240+ cfg.properties = security::audit::audit_log_topic_properties ();
241+ return cfg;
242+ }
243+ // default topic configuration
244+ cluster::topic_configuration cfg{
245+ model::kafka_namespace,
246+ std::move (topic),
247+ config::shard_local_cfg ().default_topic_partitions (),
248+ config::shard_local_cfg ().default_topic_replication ()};
249+ // Need to respect the default_redpanda_storage_mode when autocreating a
250+ // topic.
251+ cfg.properties .storage_mode
252+ = config::shard_local_cfg ().default_redpanda_storage_mode ();
253+ return cfg;
254+ }
255+
209256ss::future<metadata_response::topic> create_topic (
210257 request_context& ctx,
211258 model::topic topic,
@@ -221,20 +268,10 @@ ss::future<metadata_response::topic> create_topic(
221268 t.error_code = error_code::broker_not_available;
222269 co_return t;
223270 }
224- // default topic configuration
225- cluster::topic_configuration cfg{
226- model::kafka_namespace,
227- topic,
228- config::shard_local_cfg ().default_topic_partitions (),
229- config::shard_local_cfg ().default_topic_replication ()};
230- // Need to respect the default_redpanda_storage_mode when autocreating a
231- // topic.
232- cfg.properties .storage_mode
233- = config::shard_local_cfg ().default_redpanda_storage_mode ();
234271 auto tout = config::shard_local_cfg ().internal_rpc_request_timeout_ms ();
235272 try {
236273 auto res = co_await ctx.topics_frontend ().autocreate_topics (
237- {std::move (cfg )}, tout);
274+ {autocreate_topic_configuration (ctx, topic )}, tout);
238275 vassert (res.size () == 1 , " expected single result" );
239276 // error, neither success nor topic exists
240277 if (!(res[0 ].ec == cluster::errc::success
@@ -251,10 +288,11 @@ ss::future<metadata_response::topic> create_topic(
251288 ctx.controller_api (),
252289 tout + model::timeout_clock::now ());
253290
254- auto tp_md = ctx.metadata_cache ().get_topic_metadata (res[0 ].tp_ns );
291+ auto tp_md = ctx.metadata_cache ().get_topic_metadata (
292+ model::topic_namespace_view (model::kafka_namespace, topic));
255293 if (!tp_md) {
256294 metadata_response::topic t;
257- t.name = std::move (res[ 0 ]. tp_ns . tp );
295+ t.name = std::move (topic );
258296 t.error_code = error_code::invalid_topic_exception;
259297 co_return t;
260298 }
0 commit comments