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

 ##########
 File path: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaWriteTask.scala
 ##########
 @@ -62,16 +61,18 @@ private[kafka010] class KafkaWriteTask(
           }
         }
       }
-      producer.send(record, callback)
+      producer.kafkaProducer.send(record, callback)
     }
   }
 
   def close(): Unit = {
+    // Reduce the producer thread count first, so that in case of a failed 
write,
+    // we do not get an incorrect count.
+    val inUseCount = producer.inUseCount.decrementAndGet()
 
 Review comment:
   This should be after `producer.kafkaProducer.flush()`. Otherwise this 
producer may be closed before `flush`. You can put this line in `finally`  to 
handle failed write.

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

Reply via email to