gaborgsomogyi commented on a change in pull request #26470: [SPARK-27042][SS] 
Invalidate cached Kafka producer in case of task retry
URL: https://github.com/apache/spark/pull/26470#discussion_r346469913
 
 

 ##########
 File path: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/CachedKafkaProducer.scala
 ##########
 @@ -93,6 +93,10 @@ private[kafka010] object CachedKafkaProducer extends 
Logging {
         .setAuthenticationConfigIfNeeded()
         .build()
     val key = toCacheKey(updatedKafkaParams)
+    if (TaskContext.get != null && TaskContext.get.attemptNumber >= 1) {
 
 Review comment:
   To answer the question1: Yes, job 2 can use job 1 created producers in the 
same JVM. Such case another task retry is needed to recover in the following 
way:
   * job 2 task 1 attempt 0 runs with producer 1 and fails
   * job 2 task 1 attempt 1 runs with producer 3 (this would invalidate 
producer 1 and 2 if not used)
   
   If I consider the use-case this would mean 2 jobs must write the same 
`TopicPartition` at the same time. Until now I haven't seen use-cases where the 
exact same topic would be used by 2 different job (of course this doesn't mean 
it's not done).
   
   To answer the question2: Kafka consumers and producers doesn't provide any 
kind of self healing.
   
   I think I have to take some time to check the other way because I've similar 
fear what @HeartSaVioR mentioned (horror complicated code with catch blocks all 
the places where producer touched). The general fear what I have with the 
invalidation from exception side is the following: if the code is leaking and 
doesn't catch one single exception then the task may not heal itself.
   

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