[bugfix]leader重选时忽略ElectionNotNeededException异常,返回成功

This commit is contained in:
zhaoli
2023-03-23 10:37:10 +08:00
committed by EricZeng
parent d3cc0cb687
commit 9f6882cf0d

View File

@@ -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());
}
}
}