chia7712 commented on code in PR #16022: URL: https://github.com/apache/kafka/pull/16022#discussion_r1639747343
########## clients/src/main/java/org/apache/kafka/common/requests/ShareFetchResponse.java: ########## @@ -0,0 +1,212 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.common.requests; + +import org.apache.kafka.common.Node; +import org.apache.kafka.common.TopicIdPartition; +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.Uuid; +import org.apache.kafka.common.message.ShareFetchResponseData; +import org.apache.kafka.common.protocol.ApiKeys; +import org.apache.kafka.common.protocol.ByteBufferAccessor; +import org.apache.kafka.common.protocol.Errors; +import org.apache.kafka.common.protocol.ObjectSerializationCache; +import org.apache.kafka.common.record.MemoryRecords; +import org.apache.kafka.common.record.Records; + +import java.nio.ByteBuffer; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Iterator; +import java.util.Collections; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + + +/** + * Possible error codes. + * - {@link Errors#GROUP_AUTHORIZATION_FAILED} + * - {@link Errors#TOPIC_AUTHORIZATION_FAILED} + * - {@link Errors#UNKNOWN_TOPIC_OR_PARTITION} + * - {@link Errors#NOT_LEADER_OR_FOLLOWER} + * - {@link Errors#UNKNOWN_TOPIC_ID} + * - {@link Errors#INVALID_RECORD_STATE} + * - {@link Errors#KAFKA_STORAGE_ERROR} + * - {@link Errors#CORRUPT_MESSAGE} + * - {@link Errors#INVALID_REQUEST} + * - {@link Errors#UNKNOWN_SERVER_ERROR} + */ +public class ShareFetchResponse extends AbstractResponse { + + private final ShareFetchResponseData data; + + private volatile LinkedHashMap<TopicIdPartition, ShareFetchResponseData.PartitionData> responseData = null; + + public ShareFetchResponse(ShareFetchResponseData data) { + super(ApiKeys.SHARE_FETCH); + this.data = data; + } + + public Errors error() { + return Errors.forCode(data.errorCode()); + } + + @Override + public ShareFetchResponseData data() { + return data; + } + + @Override + public Map<Errors, Integer> errorCounts() { + HashMap<Errors, Integer> counts = new HashMap<>(); + updateErrorCounts(counts, Errors.forCode(data.errorCode())); + data.responses().forEach( + topic -> topic.partitions().forEach( + partition -> updateErrorCounts(counts, Errors.forCode(partition.errorCode())) + ) + ); + return counts; + } + + public LinkedHashMap<TopicIdPartition, ShareFetchResponseData.PartitionData> responseData(Map<Uuid, String> topicNames) { Review Comment: > I see similar issue in [FetchResponse.java](https://github.com/apache/kafka/blob/888a17760347223614da9243dc3751a18403cfa6/clients/src/main/java/org/apache/kafka/common/requests/FetchResponse.java#L101). yes, I have filed a jira https://issues.apache.org/jira/browse/KAFKA-16684 for it. Also, there is already a PR #15966 > @apoorvmittal10's suggestion works for me. sounds good to me too -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org