chia7712 commented on code in PR #19879: URL: https://github.com/apache/kafka/pull/19879#discussion_r2129098691
########## server/src/main/java/org/apache/kafka/server/transaction/AddPartitionsToTxnManager.java: ########## @@ -0,0 +1,352 @@ +/* + * 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.server.transaction; + +import org.apache.kafka.clients.ClientResponse; +import org.apache.kafka.clients.NetworkClient; +import org.apache.kafka.clients.RequestCompletionHandler; +import org.apache.kafka.common.Node; +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.internals.Topic; +import org.apache.kafka.common.message.AddPartitionsToTxnRequestData.AddPartitionsToTxnTopic; +import org.apache.kafka.common.message.AddPartitionsToTxnRequestData.AddPartitionsToTxnTopicCollection; +import org.apache.kafka.common.message.AddPartitionsToTxnRequestData.AddPartitionsToTxnTransaction; +import org.apache.kafka.common.message.AddPartitionsToTxnRequestData.AddPartitionsToTxnTransactionCollection; +import org.apache.kafka.common.message.AddPartitionsToTxnResponseData; +import org.apache.kafka.common.network.ListenerName; +import org.apache.kafka.common.protocol.Errors; +import org.apache.kafka.common.requests.AddPartitionsToTxnRequest; +import org.apache.kafka.common.requests.AddPartitionsToTxnResponse; +import org.apache.kafka.common.requests.MetadataResponse; +import org.apache.kafka.common.utils.Time; +import org.apache.kafka.metadata.MetadataCache; +import org.apache.kafka.server.config.AbstractKafkaConfig; +import org.apache.kafka.server.metrics.KafkaMetricsGroup; +import org.apache.kafka.server.util.InterBrokerSendThread; +import org.apache.kafka.server.util.RequestAndCompletionHandler; + +import com.yammer.metrics.core.Histogram; +import com.yammer.metrics.core.Meter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class AddPartitionsToTxnManager extends InterBrokerSendThread { + + public static final String VERIFICATION_FAILURE_RATE_METRIC_NAME = "VerificationFailureRate"; + public static final String VERIFICATION_TIME_MS_METRIC_NAME = "VerificationTimeMs"; + + @FunctionalInterface + public interface AppendCallback { + void complete(Map<TopicPartition, Errors> partitionErrors); + } + + /** + * An interface which handles the Partition Response based on the Request Version and the exact operation. + */ + @FunctionalInterface + public interface TransactionSupportedOperation { Review Comment: Could you please consider using java enum instead? ```java /** * handles the Partition Response based on the Request Version and the exact operation. */ enum TransactionSupportedOperation { /** * This is the default workflow which maps to cases when the Produce Request Version or the * Txn_offset_commit request was lower than the first version supporting the new Error Class. */ DEFAULT_ERROR(false), /** * This maps to the case when the clients are updated to handle the TransactionAbortableException. */ GENERIC_ERROR_SUPPORTED(false), /** * This allows the partition to be added to the transactions inflight with the Produce and TxnOffsetCommit requests. * Plus the behaviors in genericErrorSupported. */ ADD_PARTITION(true); private final boolean supportsEpochBump; TransactionSupportedOperation(boolean supportsEpochBump) { this.supportsEpochBump = supportsEpochBump; } } ``` -- 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