hachikuji commented on code in PR #12206:
URL: https://github.com/apache/kafka/pull/12206#discussion_r891613523
##########
clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java:
##########
@@ -4321,6 +4328,94 @@ void handleFailure(Throwable throwable) {
return new UpdateFeaturesResult(new HashMap<>(updateFutures));
}
+ @Override
+ public DescribeMetadataQuorumResult
describeMetadataQuorum(DescribeMetadataQuorumOptions options) {
+ NodeProvider provider = new LeastLoadedNodeProvider();
+
+ final KafkaFutureImpl<QuorumInfo> future = new KafkaFutureImpl<>();
+ final long now = time.milliseconds();
+ final Call call = new Call(
+ "describeMetadataQuorum", calcDeadlineMs(now,
options.timeoutMs()), provider) {
+
+ private QuorumInfo createQuorumResult(final
DescribeQuorumResponseData.PartitionData partition) {
+ List<QuorumInfo.ReplicaState> voters = new ArrayList<>();
+ List<QuorumInfo.ReplicaState> observers = new ArrayList<>();
+ partition.currentVoters().forEach(v -> {
+ voters.add(new QuorumInfo.ReplicaState(v.replicaId(),
+ v.logEndOffset(),
+ OptionalLong.of(v.lastFetchTimestamp()),
+ OptionalLong.of(v.lastCaughtUpTimestamp())));
+ });
+ partition.observers().forEach(o -> {
+ observers.add(new QuorumInfo.ReplicaState(o.replicaId(),
+ o.logEndOffset(),
+ OptionalLong.of(o.lastFetchTimestamp()),
+ OptionalLong.of(o.lastCaughtUpTimestamp())));
+ });
+ QuorumInfo info = new QuorumInfo(partition.leaderId(), voters,
observers);
+ return info;
+ }
+
+ @Override
+ DescribeQuorumRequest.Builder createRequest(int timeoutMs) {
+ return new Builder(DescribeQuorumRequest.singletonRequest(
+ new TopicPartition(METADATA_TOPIC_NAME,
METADATA_TOPIC_PARTITION.partition())));
+ }
+
+ @Override
+ void handleResponse(AbstractResponse response) {
+ final DescribeQuorumResponse quorumResponse =
(DescribeQuorumResponse) response;
+ try {
+ if (quorumResponse.data().errorCode() !=
Errors.NONE.code()) {
+ throw
Errors.forCode(quorumResponse.data().errorCode()).exception();
+ }
+ if (quorumResponse.data().topics().size() > 1) {
+ String msg = String.format("DescribeMetadataQuorum
received {} topics when 1 was expected",
+ quorumResponse.data().topics().size());
+ log.debug(msg);
+ throw new UnknownServerException(msg);
+ }
+ DescribeQuorumResponseData.TopicData topic =
quorumResponse.data().topics().get(0);
+ if (!topic.topicName().equals(METADATA_TOPIC_NAME)) {
+ String msg = String.format("DescribeMetadataQuorum
received a topic with name {} when {} was expected",
+ topic.topicName(), METADATA_TOPIC_NAME);
+ log.debug(msg);
+ throw new UnknownServerException(msg);
+ }
+ if (topic.partitions().size() > 1) {
+ String msg = String.format("DescribeMetadataQuorum
received a topic {} with {} partitions when 1 was expected",
+ topic.topicName(), topic.partitions().size());
+ log.debug(msg);
+ throw new UnknownServerException(msg);
+ }
+ DescribeQuorumResponseData.PartitionData partition =
topic.partitions().get(0);
+ if (partition.partitionIndex() !=
METADATA_TOPIC_PARTITION.partition()) {
+ String msg = String.format("DescribeMetadataQuorum
received a single partition with index {} when {} was expected",
+ partition.partitionIndex(),
METADATA_TOPIC_PARTITION.partition());
+ log.debug(msg);
+ throw new UnknownServerException(msg);
+ }
+ if (partition.errorCode() != Errors.NONE.code()) {
+ throw
Errors.forCode(partition.errorCode()).exception();
+ }
+ future.complete(createQuorumResult(partition));
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
Review Comment:
`UnknownServerException` extends `KafkaException`, which extends
`RuntimeException`. So I think all the errors that we are raising above get
re-thrown in the previous `catch`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]