sjhajharia commented on code in PR #22576:
URL: https://github.com/apache/kafka/pull/22576#discussion_r3454217550


##########
transaction-coordinator/src/main/java/org/apache/kafka/coordinator/transaction/TxnMarkerQueue.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.coordinator.transaction;
+
+import org.apache.kafka.common.Node;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.function.BiConsumer;
+
+public class TxnMarkerQueue {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(TxnMarkerQueue.class);
+
+    // keep track of the requests per txn topic partition so we can easily 
clear the queue
+    // during partition emigration
+    private final ConcurrentHashMap<Integer, 
BlockingQueue<PendingCompleteTxnAndMarkerEntry>> markersPerTxnTopicPartition =
+        new ConcurrentHashMap<>();
+
+    private volatile Node destination;
+
+    public TxnMarkerQueue(Node destination) {
+        this.destination = destination;
+    }
+
+    public Node destination() {
+        return destination;
+    }
+
+    public void setDestination(Node destination) {
+        this.destination = destination;
+    }
+
+    public Optional<BlockingQueue<PendingCompleteTxnAndMarkerEntry>> 
removeMarkersForTxnTopicPartition(int partition) {
+        return 
Optional.ofNullable(markersPerTxnTopicPartition.remove(partition));
+    }
+
+    public void addMarkers(int txnTopicPartition, 
PendingCompleteTxnAndMarkerEntry pendingCompleteTxnAndMarker) {
+        BlockingQueue<PendingCompleteTxnAndMarkerEntry> queue = 
markersPerTxnTopicPartition.computeIfAbsent(txnTopicPartition, partition -> {
+            // Note that this may get called more than once if threads have a 
close race while adding new queue.

Review Comment:
   Thanks for the same. Addressed the same in the next commit.



-- 
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]

Reply via email to