From 7f99c095c2ceb2d09b0e490fa138a68fac849bba Mon Sep 17 00:00:00 2001 From: Lincong Li Date: Thu, 11 Feb 2021 11:16:57 -0800 Subject: [PATCH] Remove redundant logic to calculate the minimum number of partition before creating new KMF topics (#341) --- src/main/java/com/linkedin/xinfra/monitor/common/Utils.java | 2 +- .../monitor/services/MultiClusterTopicManagementService.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/linkedin/xinfra/monitor/common/Utils.java b/src/main/java/com/linkedin/xinfra/monitor/common/Utils.java index dbd20ab1..8c5aeffc 100644 --- a/src/main/java/com/linkedin/xinfra/monitor/common/Utils.java +++ b/src/main/java/com/linkedin/xinfra/monitor/common/Utils.java @@ -169,7 +169,7 @@ public static int createTopicIfNotExists(String topic, short replicationFactor, throws ExecutionException, InterruptedException { try { if (adminClient.listTopics().names().get().contains(topic)) { - LOG.info("AdminClient indicates that {} already exists in the cluster. Topic config: {}", topic, topicConfig); + LOG.info("AdminClient indicates that topic {} already exists in the cluster. Topic config: {}", topic, topicConfig); return getPartitionNumForTopic(adminClient, topic); } int brokerCount = Utils.getBrokerCount(adminClient); diff --git a/src/main/java/com/linkedin/xinfra/monitor/services/MultiClusterTopicManagementService.java b/src/main/java/com/linkedin/xinfra/monitor/services/MultiClusterTopicManagementService.java index e1ad2f4d..dca1eb65 100644 --- a/src/main/java/com/linkedin/xinfra/monitor/services/MultiClusterTopicManagementService.java +++ b/src/main/java/com/linkedin/xinfra/monitor/services/MultiClusterTopicManagementService.java @@ -310,9 +310,7 @@ void maybeCreateTopic() throws Exception { "Refer to config: {}", _topic, _zkConnect, TopicManagementServiceConfig.TOPIC_CREATION_ENABLED_CONFIG); return; } - int brokerCount = _adminClient.describeCluster().nodes().get().size(); - int numPartitions = Math.max((int) Math.ceil(brokerCount * _minPartitionsToBrokersRatio), minPartitionNum()); - NewTopic newTopic = new NewTopic(_topic, numPartitions, (short) _replicationFactor); + NewTopic newTopic = new NewTopic(_topic, minPartitionNum(), (short) _replicationFactor); newTopic.configs((Map) _topicProperties); _topicFactory.createTopicIfNotExist(_topic, (short) _replicationFactor, _minPartitionsToBrokersRatio, _topicProperties, _adminClient);