gaborgsomogyi commented on a change in pull request #19096: [SPARK-21869][SS] A
cached Kafka producer should not be closed if any task is using it - adds inuse
tracking.
URL: https://github.com/apache/spark/pull/19096#discussion_r266888173
##########
File path:
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaStreamingWrite.scala
##########
@@ -103,20 +103,18 @@ class KafkaStreamDataWriter(
// Send is asynchronous, but we can't commit until all rows are actually
in Kafka.
// This requires flushing and then checking that no callbacks produced
errors.
// We also check for errors before to fail as soon as possible - the check
is cheap.
- checkForErrors()
- producer.flush()
- checkForErrors()
+ close()
KafkaWriterCommitMessage
}
- def abort(): Unit = {}
+ def abort(): Unit = {
+ close()
+ }
- def close(): Unit = {
+ private def close(): Unit = {
+ checkForErrors()
+ producer.flush()
checkForErrors()
- if (producer != null) {
Review comment:
I think this null check has significant meaning. Let's consider the
following example:
* Task aquires a producer
* `dataWriter.write` called
* `dataWriter.commit` called which decrements `inUseCount`
* Random exception thrown
* `dataWriter.abort` called which decrements `inUseCount` again
Having null check and setting null after released would solve double release.
The same applies to `KafkaWriteTask.scala`.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]