MartijnVisser commented on code in PR #355:
URL: 
https://github.com/apache/flink-connector-kafka/pull/355#discussion_r4687154663


##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/KafkaWriter.java:
##########
@@ -201,7 +201,7 @@ public List<KafkaWriterState> snapshotState(long 
checkpointId) throws IOExceptio
     public void close() throws Exception {
         markClosed();
         LOG.debug("Closing writer with {}", currentProducer);
-        closeAll(currentProducer);
+        closeAll(currentProducer, recordSerializer::close);

Review Comment:
   `ExactlyOnceKafkaWriter` still opens the serializer again in its 
constructor, so exactly-once gets two opens per close. Please drop that one in 
its own commit.



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/KafkaRecordSerializationSchema.java:
##########
@@ -53,6 +53,12 @@ default void open(
             SerializationSchema.InitializationContext context, 
KafkaSinkContext sinkContext)
             throws Exception {}
 
+    /**
+     * Closes this schema and releases any resources acquired in {@link 
#open}. It is called when
+     * the writer is closed. Calling it on an already closed schema must have 
no effect.

Review Comment:
   I think `open` belongs at the start of `initialize()`. Today a constructor 
failure after it, such as a duplicate transactional id prefix, leaves the 
schema open on every restart. This Javadoc can then say `close` may follow a 
failed `open`.



##########
flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/sink/KafkaWriterITCase.java:
##########
@@ -120,6 +122,27 @@ public void 
testIncreasingRecordBasedCounters(DeliveryGuarantee guarantee) throw
         }
     }
 
+    @ParameterizedTest
+    @EnumSource(
+            value = DeliveryGuarantee.class,
+            names = {"AT_LEAST_ONCE", "EXACTLY_ONCE"})
+    public void testRecordSerializerIsClosedWithWriter(DeliveryGuarantee 
guarantee)
+            throws Exception {
+        final AtomicInteger closeCalls = new AtomicInteger();
+        final KafkaRecordSerializationSchema<Integer> delegate = new 
IntegerRecordSerializer(topic);
+        final KafkaWriter<Integer> writer =
+                createWriter(
+                        builder ->
+                                builder.setDeliveryGuarantee(guarantee)
+                                        .setRecordSerializer(
+                                                new 
ClosingRecordSerializer(delegate, closeCalls)),

Review Comment:
   This doesn't compile: the adjuster gets a `KafkaSinkBuilder<?>`. A cast to 
`KafkaSinkBuilder<Integer>` fixes it. Please count opens here as well. 
`spotless:check` also fails on this file.



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