fapaul commented on code in PR #154:
URL: 
https://github.com/apache/flink-connector-kafka/pull/154#discussion_r1967898094


##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/ExactlyOnceKafkaWriter.java:
##########
@@ -53,7 +56,14 @@
  */
 class ExactlyOnceKafkaWriter<IN> extends KafkaWriter<IN> {
     private static final Logger LOG = 
LoggerFactory.getLogger(ExactlyOnceKafkaWriter.class);
+    /**
+     * Prefix for the transactional id. Must be unique across all sinks 
writing to the same broker.
+     */
     private final String transactionalIdPrefix;
+    /** Strategy to abort lingering transactions from previous executions. */

Review Comment:
   Nit: `during writer initialization.`



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/ExactlyOnceKafkaWriter.java:
##########
@@ -224,13 +243,32 @@ private void abortLingeringTransactions(
             }
         }
 
-        try (TransactionAborter transactionAborter =
-                new TransactionAborter(
-                        kafkaSinkContext.getParallelInstanceId(),
-                        kafkaSinkContext.getNumberOfParallelInstances(),
-                        id -> producerPool.getTransactionalProducer(id, 
startCheckpointId),
-                        producerPool::recycle)) {
-            transactionAborter.abortLingeringTransactions(prefixesToAbort, 
startCheckpointId);
-        }
+        LOG.info(
+                "Aborting lingering transactions with prefixes {} using {}",
+                prefixesToAbort,
+                transactionAbortStrategy);
+        TransactionAbortStrategyContextImpl context =
+                getTransactionAbortStrategyContext(startCheckpointId, 
prefixesToAbort);
+        transactionAbortStrategy.abortTransactions(context);
+    }
+
+    private TransactionAbortStrategyContextImpl 
getTransactionAbortStrategyContext(
+            long startCheckpointId, List<String> prefixesToAbort) {
+        TransactionAbortStrategyImpl.TransactionAborter aborter =
+                transactionalId -> {
+                    FlinkKafkaInternalProducer<byte[], byte[]> producer =
+                            
producerPool.getTransactionalProducer(transactionalId, 0);
+                    LOG.debug("Aborting transaction {}", transactionalId);

Review Comment:
   Shouldn't we do any operation on the transaction here e.g. abort/init? Can 
you add a comment what is happening?



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/ExactlyOnceKafkaWriter.java:
##########
@@ -136,13 +158,10 @@ public void initialize() {
     }
 
     private FlinkKafkaInternalProducer<byte[], byte[]> startTransaction(long 
checkpointId) {
+        namingContext.setNextCheckpointId(checkpointId);
         FlinkKafkaInternalProducer<byte[], byte[]> producer =
-                producerPool.getTransactionalProducer(
-                        TransactionalIdFactory.buildTransactionalId(
-                                transactionalIdPrefix,
-                                kafkaSinkContext.getParallelInstanceId(),
-                                checkpointId),
-                        checkpointId);
+                
transactionNamingStrategy.getTransactionalProducer(namingContext);
+        namingContext.setLastCheckpointId(checkpointId);

Review Comment:
   This looks strange. Why do we expose `setNextCheckpointId` and 
`setLastCheckpointId` if both methods are always used together? Is the 
interleaving of the producer creation necessary?



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/TransactionAbortStrategy.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.flink.connector.kafka.sink;
+
+import org.apache.flink.annotation.PublicEvolving;
+import 
org.apache.flink.connector.kafka.sink.internal.TransactionAbortStrategyImpl;
+
+/**
+ * The strategy to abort a transactions left by ungraceful job termination, 
which is the usual case
+ * for failures in Flink. On start of the sink, the strategy will be used to 
abort any ongoing
+ * transactions left open while cautiously avoid to abort transactions that 
are still trying to
+ * commit.
+ */
+@PublicEvolving
+public enum TransactionAbortStrategy {

Review Comment:
   Why do we need want to have `TransactionAbortStrategy` and 
`TransactionNamingStrategy` aren't there dependencies between the two enums?



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