From 9f6882cf0d8b971b48f58af8846a2d1a2d4abcb9 Mon Sep 17 00:00:00 2001 From: zhaoli Date: Thu, 23 Mar 2023 10:37:10 +0800 Subject: [PATCH] =?UTF-8?q?[bugfix]leader=E9=87=8D=E9=80=89=E6=97=B6?= =?UTF-8?q?=E5=BF=BD=E7=95=A5ElectionNotNeededException=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=EF=BC=8C=E8=BF=94=E5=9B=9E=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/partition/impl/OpPartitionServiceImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/km-core/src/main/java/com/xiaojukeji/know/streaming/km/core/service/partition/impl/OpPartitionServiceImpl.java b/km-core/src/main/java/com/xiaojukeji/know/streaming/km/core/service/partition/impl/OpPartitionServiceImpl.java index 838ac594..8fafdec5 100644 --- a/km-core/src/main/java/com/xiaojukeji/know/streaming/km/core/service/partition/impl/OpPartitionServiceImpl.java +++ b/km-core/src/main/java/com/xiaojukeji/know/streaming/km/core/service/partition/impl/OpPartitionServiceImpl.java @@ -19,6 +19,7 @@ import org.apache.kafka.clients.admin.ElectLeadersOptions; import org.apache.kafka.clients.admin.ElectLeadersResult; import org.apache.kafka.common.ElectionType; import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.errors.ElectionNotNeededException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import scala.jdk.javaapi.CollectionConverters; @@ -108,12 +109,17 @@ public class OpPartitionServiceImpl extends BaseKafkaVersionControlService imple return Result.buildSuc(); } catch (Exception e) { + if(e.getCause() instanceof ElectionNotNeededException) { + // ignore ElectionNotNeededException + return Result.buildSuc(); + } + LOGGER.error( "method=preferredReplicaElectionByKafkaClient||clusterPhyId={}||errMsg=exception", partitionParam.getClusterPhyId(), e ); - return Result.buildFromRSAndMsg(ResultStatus.ZK_OPERATE_FAILED, e.getMessage()); + return Result.buildFromRSAndMsg(ResultStatus.KAFKA_OPERATE_FAILED, e.getMessage()); } } }