Skip to content

Commit b4a4220

Browse files
committed
fix(topics): clamp default replication factor to broker count
CreateTopic defaulted replicationFactor to 3 in both the topic-create modal and the MCP inspector's "create new topic" flow. On single-broker clusters (local-byoc dev environments, etc.) that rejected the request with "not enough replicas". Clamp the default to min(3, brokersOnline) and fall back to 3 while KafkaInfo is loading.
1 parent 94449f4 commit b4a4220

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

frontend/src/components/pages/mcp-servers/details/remote-mcp-inspector-tab.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
} from 'protogen/redpanda/api/dataplane/v1/topic_pb';
3737
import { MCPServer_State, MCPServer_Tool_ComponentType } from 'protogen/redpanda/api/dataplane/v1alpha3/mcp_pb';
3838
import { useEffect, useRef, useState } from 'react';
39+
import { useGetKafkaInfoQuery } from 'react-query/api/cluster-status';
3940
import {
4041
type MCPStreamProgress,
4142
useGetMCPServerQuery,
@@ -201,6 +202,13 @@ export const RemoteMCPInspectorTab = () => {
201202
hideInternalTopics: true,
202203
});
203204
const { mutateAsync: createTopic } = useCreateTopicMutation();
205+
// Clamp RF to broker count so single-broker clusters (e.g. local-byoc) don't
206+
// fail CreateTopic with "not enough replicas". Fall back to the default if
207+
// the KafkaInfo query hasn't resolved yet.
208+
const { data: kafkaInfo } = useGetKafkaInfoQuery();
209+
const brokersOnline = kafkaInfo?.brokersOnline ?? 0;
210+
const effectiveReplicationFactor =
211+
brokersOnline > 0 ? Math.min(DEFAULT_TOPIC_REPLICATION_FACTOR, brokersOnline) : DEFAULT_TOPIC_REPLICATION_FACTOR;
204212

205213
useEffect(() => {
206214
if (!selectedTool && mcpServerTools?.tools && mcpServerTools.tools.length === 1) {
@@ -564,7 +572,7 @@ export const RemoteMCPInspectorTab = () => {
564572
topic: create(CreateTopicRequest_TopicSchema, {
565573
name: newTopicName,
566574
partitionCount: DEFAULT_TOPIC_PARTITION_COUNT,
567-
replicationFactor: DEFAULT_TOPIC_REPLICATION_FACTOR,
575+
replicationFactor: effectiveReplicationFactor,
568576
configs: [
569577
create(CreateTopicRequest_Topic_ConfigSchema, {
570578
name: 'cleanup.policy',

frontend/src/components/pages/topics/create-topic-modal.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
CreateTopicRequestSchema,
2121
ListTopicsRequestSchema,
2222
} from 'protogen/redpanda/api/dataplane/v1/topic_pb';
23+
import { useGetKafkaInfoQuery } from 'react-query/api/cluster-status';
2324
import { useCreateTopicMutation, useLegacyListTopicsQuery } from 'react-query/api/topic';
2425
import { z } from 'zod';
2526

@@ -44,6 +45,13 @@ export const CreateTopicModal = ({ isOpen, onClose }: CreateTopicModalProps) =>
4445
hideInternalTopics: true,
4546
});
4647
const { mutateAsync: createTopic, isPending: isCreateTopicPending } = useCreateTopicMutation();
48+
// Clamp RF to broker count so single-broker clusters (e.g. local-byoc) don't
49+
// fail CreateTopic with "not enough replicas". Fall back to the default if
50+
// the KafkaInfo query hasn't resolved yet.
51+
const { data: kafkaInfo } = useGetKafkaInfoQuery();
52+
const brokersOnline = kafkaInfo?.brokersOnline ?? 0;
53+
const replicationFactor =
54+
brokersOnline > 0 ? Math.min(DEFAULT_TOPIC_REPLICATION_FACTOR, brokersOnline) : DEFAULT_TOPIC_REPLICATION_FACTOR;
4755

4856
const formOpts = formOptions({
4957
defaultValues: {
@@ -57,7 +65,7 @@ export const CreateTopicModal = ({ isOpen, onClose }: CreateTopicModalProps) =>
5765
topic: create(CreateTopicRequest_TopicSchema, {
5866
name: value.name,
5967
partitionCount: DEFAULT_TOPIC_PARTITION_COUNT,
60-
replicationFactor: DEFAULT_TOPIC_REPLICATION_FACTOR,
68+
replicationFactor,
6169
configs: [
6270
create(CreateTopicRequest_Topic_ConfigSchema, {
6371
name: 'cleanup.policy',

0 commit comments

Comments
 (0)