Github user srowen commented on a diff in the pull request: https://github.com/apache/spark/pull/18143#discussion_r119073041 --- Diff: external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/CachedKafkaConsumer.scala --- @@ -311,61 +311,40 @@ 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 duration = conf.getTimeAsMs("spark.sql.kafkaConsumerCache.timeout", "10m") + val removalListener = new RemovalListener[CacheKey, CachedKafkaConsumer] { + override def onRemoval(n: RemovalNotification[CacheKey, CachedKafkaConsumer]): Unit = { + val logMsg: String = s"Evicting consumer ${n.getKey}, cause: ${n.getCause}" + n.getCause match { + case RemovalCause.SIZE => logWarning(logMsg) --- End diff -- Why is removing for size a warning? You probably want different messages then, and, if so, should put the pattern string in the invocation. Otherwise you're always constructing the message even in the common path where the debug message is ignored
--- 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