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_r326375872
##########
File path:
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaDataConsumer.scala
##########
@@ -516,13 +521,39 @@ 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()
+ }
+ if (!isConsumerUsingCurrentToken) {
+ logDebug("Cached consumer uses and old delegation token, invalidating.")
+ releaseConsumer()
+ consumerPool.invalidateKey(cacheKey)
+ fetchedDataPool.invalidate(cacheKey)
+ retrieveConsumer()
+ }
+ _consumer.get
+ }
+
+ private def retrieveConsumer(): Unit = {
+ _consumer = Option(consumerPool.borrowObject(cacheKey, kafkaParams))
+ require(_consumer.isDefined, "borrowing consumer from pool must always
succeed.")
+ }
- case Some(consumer) => consumer
+ private def isConsumerUsingCurrentToken: Boolean = {
Review comment:
I'm still feeling that this method (maybe excluding first line of `require`)
could be moved to KafkaTestUtil so that KafkaDataConsumer doesn't need to know
about the details of how delegation token works. Either passing `_consumer.get`
or `_consumer.get.kafkaParamsWithSecurity` as parameter of method.
But I would be OK if others are feeling it's OK to leave it as it is.
----------------------------------------------------------------
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]