HeartSaVioR commented on a change in pull request #25760: [SPARK-29054][SS] 
Invalidate Kafka consumer when new delegation token available
URL: https://github.com/apache/spark/pull/25760#discussion_r325532165
 
 

 ##########
 File path: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaDataConsumer.scala
 ##########
 @@ -516,13 +521,41 @@ private[kafka010] class KafkaDataConsumer(
     fetchedData.withNewPoll(records.listIterator, offsetAfterPoll)
   }
 
-  private def getOrRetrieveConsumer(): InternalKafkaConsumer = _consumer match 
{
-    case None =>
-      _consumer = Option(consumerPool.borrowObject(cacheKey, kafkaParams))
-      require(_consumer.isDefined, "borrowing consumer from pool must always 
succeed.")
-      _consumer.get
+  private[kafka010] def getOrRetrieveConsumer(): InternalKafkaConsumer = {
+    if (!_consumer.isDefined) {
+      retrieveConsumer()
+    }
+    ensureConsumerHasLatestToken()
+    _consumer.get
+  }
 
-    case Some(consumer) => consumer
+  private def retrieveConsumer(): Unit = {
+    _consumer = Option(consumerPool.borrowObject(cacheKey, kafkaParams))
+    require(_consumer.isDefined, "borrowing consumer from pool must always 
succeed.")
+  }
+
+  private def ensureConsumerHasLatestToken(): Unit = {
+    require(_consumer.isDefined, "Consumer must be defined")
+    val params = _consumer.get.kafkaParamsWithSecurity
+    if (params.containsKey(SaslConfigs.SASL_JAAS_CONFIG)) {
+      logDebug("Delegation token used by cached consumer, checking if uses the 
latest token.")
+
+      val jaasParams = 
params.get(SaslConfigs.SASL_JAAS_CONFIG).asInstanceOf[String]
+      val clusterConfig = KafkaTokenUtil.findMatchingToken(SparkEnv.get.conf,
 
 Review comment:
   I feel `findMatchingToken` does too many things - that's why it needs tuple 
to  return, while callers seem to use either. Maybe better to split 
`findMatchingToken` into two, same name for token, new name (like 
`findMatchingTokenConf`) for config.
   
   And given we have TokenUtil, why not TokenUtil tells whether cached consumer 
uses fresh delegation token? KafkaDataConsumer seems to handle too many things 
in its own.

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