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


##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/KafkaWriter.java:
##########
@@ -142,18 +143,23 @@ class KafkaWriter<IN>
                         sinkInitContext.getTaskInfo().getIndexOfThisSubtask(),
                         
sinkInitContext.getTaskInfo().getNumberOfParallelSubtasks(),
                         kafkaProducerConfig);
+        this.schemaContext = schemaContext;
+
+        initFlinkMetrics();
+    }
+
+    protected final void openSchema() {

Review Comment:
   Both constructor Javadocs still say a failing open throws from the 
constructor; that belongs on `initialize()` now.



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/KafkaWriter.java:
##########
@@ -201,13 +207,30 @@ public List<KafkaWriterState> snapshotState(long 
checkpointId) throws IOExceptio
     public void close() throws Exception {
         markClosed();
         LOG.debug("Closing writer with {}", currentProducer);
-        closeAll(currentProducer);
-        checkState(
-                currentProducer.isClosed(), "Could not close current producer 
" + currentProducer);
-        currentProducer = null;
+        Exception failure = null;
+        try {
+            closeAll(currentProducer, recordSerializer::close);
+            checkState(

Review Comment:
   With open in `initialize()`, a failing open now reaches this `close()` 
without a producer, so users get a suppressed NullPointerException here and 
from `abortCurrentProducer`. A null check on `currentProducer` in both places 
fixes it.



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/KafkaRecordSerializationSchema.java:
##########
@@ -53,6 +53,13 @@ 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, which includes a writer whose initialization 
failed, so it may follow a
+     * failed {@link #open}. Calling it on an already closed schema must have 
no effect.

Review Comment:
   I'd drop this sentence: the writer closes the schema once per attempt and 
Flink never closes the writer twice.



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