Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18143#discussion_r119116101
  
    --- Diff: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/CachedKafkaConsumer.scala
 ---
    @@ -310,62 +308,45 @@ private[kafka010] object CachedKafkaConsumer extends 
Logging {
     
       private lazy val cache = {
         val conf = SparkEnv.get.conf
    -    val capacity = conf.getInt("spark.sql.kafkaConsumerCache.capacity", 64)
    -    new ju.LinkedHashMap[CacheKey, CachedKafkaConsumer](capacity, 0.75f, 
true) {
    -      override def removeEldestEntry(
    -        entry: ju.Map.Entry[CacheKey, CachedKafkaConsumer]): Boolean = {
    -        if (entry.getValue.inuse == false && this.size > capacity) {
    -          logWarning(s"KafkaConsumer cache hitting max capacity of 
$capacity, " +
    -            s"removing consumer for ${entry.getKey}")
    -          try {
    -            entry.getValue.close()
    -          } catch {
    -            case e: SparkException =>
    -              logError(s"Error closing earliest Kafka consumer for 
${entry.getKey}", e)
    -          }
    -          true
    -        } else {
    -          false
    +    val capacityConfigString: String = 
"spark.sql.kafkaConsumerCache.capacity"
    +    val capacity = conf.getInt(capacityConfigString, 64)
    +    val duration = 
conf.getTimeAsMs("spark.sql.kafkaConsumerCache.timeout", "10m")
    +    val removalListener = new RemovalListener[CacheKey, 
CachedKafkaConsumer] {
    +      override def onRemoval(n: RemovalNotification[CacheKey, 
CachedKafkaConsumer]): Unit = {
    +        n.getCause match {
    +          case RemovalCause.SIZE =>
    +            logWarning(
    +              s"""
    +                 |Evicting consumer ${n.getKey}, due to size limit 
reached. Capacity: $capacity.
    +                 |This can be configured using $capacityConfigString.
    +                 |"""".stripMargin)
    +          case _ => logDebug(s"Evicting consumer ${n.getKey}, cause: 
${n.getCause}")
    +        }
    +        try {
    +          n.getValue.close()
    +        } catch {
    +          case NonFatal(e) =>
    +            logError(s"Error closing Kafka consumer: ${n.getKey}, evicted 
due to ${n.getCause}", e)
             }
           }
         }
    -  }
    -
    -  def releaseKafkaConsumer(
    -      topic: String,
    -      partition: Int,
    -      kafkaParams: ju.Map[String, Object]): Unit = {
    -    val groupId = 
kafkaParams.get(ConsumerConfig.GROUP_ID_CONFIG).asInstanceOf[String]
    -    val topicPartition = new TopicPartition(topic, partition)
    -    val key = CacheKey(groupId, topicPartition)
     
    -    synchronized {
    -      val consumer = cache.get(key)
    -      if (consumer != null) {
    -        consumer.inuse = false
    -      } else {
    -        logWarning(s"Attempting to release consumer that does not exist")
    -      }
    -    }
    +    val guavaCache: Cache[CacheKey, CachedKafkaConsumer] =
    --- End diff --
    
    Why bother declaring this `val`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to