[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677090585



##
File path: core/src/main/scala/org/apache/spark/storage/BlockManagerId.scala
##
@@ -136,11 +136,14 @@ private[spark] object BlockManagerId {
* The max cache size is hardcoded to 1, since the size of a 
BlockManagerId
* object is about 48B, the total memory cost should be below 1MB which is 
feasible.
*/
-  val blockManagerIdCache = CacheBuilder.newBuilder()
-.maximumSize(1)
-.build(new CacheLoader[BlockManagerId, BlockManagerId]() {
-  override def load(id: BlockManagerId) = id
-})
+  val blockManagerIdCache = {

Review comment:
   7b360a7 revert this change




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677090543



##
File path: core/src/main/scala/org/apache/spark/rdd/ReliableCheckpointRDD.scala
##
@@ -84,16 +84,18 @@ private[spark] class ReliableCheckpointRDD[T: ClassTag](
   }
 
   // Cache of preferred locations of checkpointed files.
-  @transient private[spark] lazy val cachedPreferredLocations = 
CacheBuilder.newBuilder()
-.expireAfterWrite(
-  SparkEnv.get.conf.get(CACHE_CHECKPOINT_PREFERRED_LOCS_EXPIRE_TIME).get,
-  TimeUnit.MINUTES)
-.build(
-  new CacheLoader[Partition, Seq[String]]() {
-override def load(split: Partition): Seq[String] = {
-  getPartitionBlockLocations(split)
-}
-  })
+  @transient private[spark] lazy val cachedPreferredLocations = {
+val builder = Caffeine.newBuilder()
+  .expireAfterWrite(
+SparkEnv.get.conf.get(CACHE_CHECKPOINT_PREFERRED_LOCS_EXPIRE_TIME).get,
+TimeUnit.MINUTES)
+val loader = new CacheLoader[Partition, Seq[String]]() {
+  override def load(split: Partition): Seq[String] = {
+getPartitionBlockLocations(split)
+  }
+}
+builder.build[Partition, Seq[String]](loader)

Review comment:
   7b360a7 revert this change




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677087470



##
File path: core/src/main/scala/org/apache/spark/storage/BlockManagerId.scala
##
@@ -136,11 +136,14 @@ private[spark] object BlockManagerId {
* The max cache size is hardcoded to 1, since the size of a 
BlockManagerId
* object is about 48B, the total memory cost should be below 1MB which is 
feasible.
*/
-  val blockManagerIdCache = CacheBuilder.newBuilder()
-.maximumSize(1)
-.build(new CacheLoader[BlockManagerId, BlockManagerId]() {
-  override def load(id: BlockManagerId) = id
-})
+  val blockManagerIdCache = {

Review comment:
   Similar to `getPartitionBlockLocations `, it cannot be compiled with 
`.build[BlockManagerId, BlockManagerId](identity)`




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677087470



##
File path: core/src/main/scala/org/apache/spark/storage/BlockManagerId.scala
##
@@ -136,11 +136,14 @@ private[spark] object BlockManagerId {
* The max cache size is hardcoded to 1, since the size of a 
BlockManagerId
* object is about 48B, the total memory cost should be below 1MB which is 
feasible.
*/
-  val blockManagerIdCache = CacheBuilder.newBuilder()
-.maximumSize(1)
-.build(new CacheLoader[BlockManagerId, BlockManagerId]() {
-  override def load(id: BlockManagerId) = id
-})
+  val blockManagerIdCache = {

Review comment:
   Similar to XXX, it cannot be compiled with `.build[BlockManagerId, 
BlockManagerId](identity)`




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677087215



##
File path: core/src/main/scala/org/apache/spark/rdd/ReliableCheckpointRDD.scala
##
@@ -84,16 +84,18 @@ private[spark] class ReliableCheckpointRDD[T: ClassTag](
   }
 
   // Cache of preferred locations of checkpointed files.
-  @transient private[spark] lazy val cachedPreferredLocations = 
CacheBuilder.newBuilder()
-.expireAfterWrite(
-  SparkEnv.get.conf.get(CACHE_CHECKPOINT_PREFERRED_LOCS_EXPIRE_TIME).get,
-  TimeUnit.MINUTES)
-.build(
-  new CacheLoader[Partition, Seq[String]]() {
-override def load(split: Partition): Seq[String] = {
-  getPartitionBlockLocations(split)
-}
-  })
+  @transient private[spark] lazy val cachedPreferredLocations = {
+val builder = Caffeine.newBuilder()
+  .expireAfterWrite(
+SparkEnv.get.conf.get(CACHE_CHECKPOINT_PREFERRED_LOCS_EXPIRE_TIME).get,
+TimeUnit.MINUTES)
+val loader = new CacheLoader[Partition, Seq[String]]() {
+  override def load(split: Partition): Seq[String] = {
+getPartitionBlockLocations(split)
+  }
+}
+builder.build[Partition, Seq[String]](loader)

Review comment:
   Then try to use `(partition: Partition) => 
getPartitionBlockLocations(partition)`, the error message same as 
`getPartitionBlockLocations(_) `




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677086519



##
File path: core/src/main/scala/org/apache/spark/rdd/ReliableCheckpointRDD.scala
##
@@ -84,16 +84,18 @@ private[spark] class ReliableCheckpointRDD[T: ClassTag](
   }
 
   // Cache of preferred locations of checkpointed files.
-  @transient private[spark] lazy val cachedPreferredLocations = 
CacheBuilder.newBuilder()
-.expireAfterWrite(
-  SparkEnv.get.conf.get(CACHE_CHECKPOINT_PREFERRED_LOCS_EXPIRE_TIME).get,
-  TimeUnit.MINUTES)
-.build(
-  new CacheLoader[Partition, Seq[String]]() {
-override def load(split: Partition): Seq[String] = {
-  getPartitionBlockLocations(split)
-}
-  })
+  @transient private[spark] lazy val cachedPreferredLocations = {
+val builder = Caffeine.newBuilder()
+  .expireAfterWrite(
+SparkEnv.get.conf.get(CACHE_CHECKPOINT_PREFERRED_LOCS_EXPIRE_TIME).get,
+TimeUnit.MINUTES)
+val loader = new CacheLoader[Partition, Seq[String]]() {
+  override def load(split: Partition): Seq[String] = {
+getPartitionBlockLocations(split)
+  }
+}
+builder.build[Partition, Seq[String]](loader)

Review comment:
   1. Try to use `builder.build[Partition, 
Seq[String]](getPartitionBlockLocations)`
   The compile errors as follows:
   ```
   [ERROR] 
/spark-mine/core/src/main/scala/org/apache/spark/rdd/ReliableCheckpointRDD.scala:92:
 missing argument list for method getPartitionBlockLocations in class 
ReliableCheckpointRDD
   Unapplied methods are only converted to functions when a function type is 
expected.
   You can make this conversion explicit by writing `getPartitionBlockLocations 
_` or `getPartitionBlockLocations(_)` instead of `getPartitionBlockLocations`.
   ```
   
   2. Then try to use  `getPartitionBlockLocations(_)` and 
`getPartitionBlockLocations _`
   
   The compile errors as follows:
   ```
   [ERROR] 
/spark-mine/core/src/main/scala/org/apache/spark/rdd/ReliableCheckpointRDD.scala:92:
 overloaded method value build with alternatives:
 (x$1: com.github.benmanes.caffeine.cache.CacheLoader[_ >: 
org.apache.spark.Partition, 
Seq[String]])com.github.benmanes.caffeine.cache.LoadingCache[org.apache.spark.Partition,Seq[String]]
 
 
()com.github.benmanes.caffeine.cache.Cache[org.apache.spark.Partition,Seq[String]]
cannot be applied to (org.apache.spark.Partition => Seq[String])
   ```




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677081396



##
File path: core/src/main/scala/org/apache/spark/storage/BlockManagerId.scala
##
@@ -136,11 +136,14 @@ private[spark] object BlockManagerId {
* The max cache size is hardcoded to 1, since the size of a 
BlockManagerId
* object is about 48B, the total memory cost should be below 1MB which is 
feasible.
*/
-  val blockManagerIdCache = CacheBuilder.newBuilder()
-.maximumSize(1)
-.build(new CacheLoader[BlockManagerId, BlockManagerId]() {
-  override def load(id: BlockManagerId) = id
-})
+  val blockManagerIdCache = {

Review comment:
   I didn't realize that usage, my Scala level was too poor, thx ~




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677083154



##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
##
@@ -159,19 +160,22 @@ class SessionCatalog(
   }
 
   private val tableRelationCache: Cache[QualifiedTableName, LogicalPlan] = {
-var builder = CacheBuilder.newBuilder()
+var builder = Caffeine.newBuilder()
   .maximumSize(cacheSize)
 
 if (cacheTTL > 0) {
   builder = builder.expireAfterWrite(cacheTTL, TimeUnit.SECONDS)
 }
-
-builder.build[QualifiedTableName, LogicalPlan]()
+// Wrapping as CaffeinatedGuava to be compatible with

Review comment:
   done

##
File path: pom.xml
##
@@ -492,6 +492,11 @@
 ${guava.version}
 provided
   
+  
+com.github.ben-manes.caffeine
+caffeine
+2.9.1

Review comment:
   done

##
File path: core/src/test/scala/org/apache/spark/LocalCacheBenchmark.scala
##
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark
+
+import java.util.concurrent.Callable
+
+import scala.concurrent.duration.Duration
+import scala.util.Random
+
+import com.github.benmanes.caffeine.cache.{CacheLoader => CaffeineCacheLoader, 
Caffeine}
+import com.google.common.cache.{CacheBuilder, CacheLoader}
+
+import org.apache.spark.benchmark.{Benchmark, BenchmarkBase}
+import org.apache.spark.util.ThreadUtils
+
+
+
+/**
+ * Benchmark for Guava Cache vs Caffeine.
+ * To run this benchmark:
+ * {{{
+ *   1. without sbt:
+ *  bin/spark-submit --class  --jars 
+ *   2. build/sbt "core/test:runMain "
+ *   3. generate result:
+ *  SPARK_GENERATE_BENCHMARK_FILES=1 build/sbt "core/test:runMain "
+ *  Results will be written to "benchmarks/KryoBenchmark-results.txt".

Review comment:
   done

##
File path: core/src/test/scala/org/apache/spark/LocalCacheBenchmark.scala
##
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark
+
+import java.util.concurrent.Callable
+
+import scala.concurrent.duration.Duration
+import scala.util.Random
+
+import com.github.benmanes.caffeine.cache.{CacheLoader => CaffeineCacheLoader, 
Caffeine}
+import com.google.common.cache.{CacheBuilder, CacheLoader}
+
+import org.apache.spark.benchmark.{Benchmark, BenchmarkBase}
+import org.apache.spark.util.ThreadUtils
+
+

Review comment:
   done




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677082323



##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
##
@@ -159,19 +160,22 @@ class SessionCatalog(
   }
 
   private val tableRelationCache: Cache[QualifiedTableName, LogicalPlan] = {
-var builder = CacheBuilder.newBuilder()
+var builder = Caffeine.newBuilder()
   .maximumSize(cacheSize)
 
 if (cacheTTL > 0) {
   builder = builder.expireAfterWrite(cacheTTL, TimeUnit.SECONDS)
 }
-
-builder.build[QualifiedTableName, LogicalPlan]()
+// Wrapping as CaffeinatedGuava to be compatible with
+// the get(key, valueLoader) API of Guava cache
+builder.build()
   }
 
   /** This method provides a way to get a cached plan. */
   def getCachedPlan(t: QualifiedTableName, c: Callable[LogicalPlan]): 
LogicalPlan = {
-tableRelationCache.get(t, c)
+tableRelationCache.get(t, new JFunction[QualifiedTableName, LogicalPlan] {

Review comment:
   d69df8e fixed these comments. The change of here need to see if it can 
be compiled
   


##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
##
@@ -159,19 +160,22 @@ class SessionCatalog(
   }
 
   private val tableRelationCache: Cache[QualifiedTableName, LogicalPlan] = {
-var builder = CacheBuilder.newBuilder()
+var builder = Caffeine.newBuilder()
   .maximumSize(cacheSize)
 
 if (cacheTTL > 0) {
   builder = builder.expireAfterWrite(cacheTTL, TimeUnit.SECONDS)
 }
-
-builder.build[QualifiedTableName, LogicalPlan]()
+// Wrapping as CaffeinatedGuava to be compatible with
+// the get(key, valueLoader) API of Guava cache
+builder.build()
   }
 
   /** This method provides a way to get a cached plan. */
   def getCachedPlan(t: QualifiedTableName, c: Callable[LogicalPlan]): 
LogicalPlan = {
-tableRelationCache.get(t, c)
+tableRelationCache.get(t, new JFunction[QualifiedTableName, LogicalPlan] {

Review comment:
   d69df8e fixed these comments. The change of there need to see if it can 
be compiled
   





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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677081396



##
File path: core/src/main/scala/org/apache/spark/storage/BlockManagerId.scala
##
@@ -136,11 +136,14 @@ private[spark] object BlockManagerId {
* The max cache size is hardcoded to 1, since the size of a 
BlockManagerId
* object is about 48B, the total memory cost should be below 1MB which is 
feasible.
*/
-  val blockManagerIdCache = CacheBuilder.newBuilder()
-.maximumSize(1)
-.build(new CacheLoader[BlockManagerId, BlockManagerId]() {
-  override def load(id: BlockManagerId) = id
-})
+  val blockManagerIdCache = {

Review comment:
   I didn't realize that usage, my Scala level was too poor, thx ~




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-26 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r677078674



##
File path: 
core/src/main/scala/org/apache/spark/deploy/history/ApplicationCache.scala
##
@@ -62,21 +61,28 @@ private[history] class ApplicationCache(
 
 /**
  * Removal event notifies the provider to detach the UI.
- * @param rm removal notification
+ * @param key removal key
+ * @param value removal value
+ * @param cause the reason why a `CacheEntry` was removed, it should
+ *  always be `SIZE` because `appCache` configured with
+ *  `maximumSize` eviction strategy
  */
-override def onRemoval(rm: RemovalNotification[CacheKey, CacheEntry]): 
Unit = {
+override def onRemoval(key: CacheKey, value: CacheEntry,
+cause: RemovalCause): Unit = {

Review comment:
   ok ~ It doesn't look exceeds 100 characters ~ 




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-08 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r50648



##
File path: 
core/src/main/scala/org/apache/spark/deploy/history/ApplicationCache.scala
##
@@ -62,21 +61,25 @@ private[history] class ApplicationCache(
 
 /**
  * Removal event notifies the provider to detach the UI.
- * @param rm removal notification
+ * @param key removal key
+ * @param value removal value
  */
-override def onRemoval(rm: RemovalNotification[CacheKey, CacheEntry]): 
Unit = {
+override def onRemoval(key: CacheKey, value: CacheEntry,
+cause: RemovalCause): Unit = {
   metrics.evictionCount.inc()
-  val key = rm.getKey
-  logDebug(s"Evicting entry ${key}")
-  operations.detachSparkUI(key.appId, key.attemptId, 
rm.getValue().loadedUI.ui)
+  logDebug(s"Evicting entry $key")
+  operations.detachSparkUI(key.appId, key.attemptId, value.loadedUI.ui)
 }
   }
 
   private val appCache: LoadingCache[CacheKey, CacheEntry] = {
-CacheBuilder.newBuilder()
-.maximumSize(retainedApplications)
-.removalListener(removalListener)
-.build(appLoader)
+val builder = Caffeine.newBuilder()
+  .maximumSize(retainedApplications)
+  .removalListener(removalListener)
+  // SPARK-34309: Use custom Executor to compatible with
+  // the data eviction behavior of Guava cache
+  .executor((command: Runnable) => command.run())

Review comment:
   Yes, it's a compromise for compatibility with old behaviour at present.  
In the future, I will optimize this behaviour through other pr.




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-08 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r73952



##
File path: 
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/ExternalShuffleBlockResolver.java
##
@@ -315,7 +301,7 @@ private ManagedBuffer getSortBasedShuffleBlockData(
   "shuffle_" + shuffleId + "_" + mapId + "_0.data"),
 shuffleIndexRecord.getOffset(),
 shuffleIndexRecord.getLength());
-} catch (ExecutionException e) {
+} catch (CompletionException e) {

Review comment:
   @holdenk `testFetchWrongExecutor` and `testFetchNonexistent` in 
`ExternalBlockHandlerSuite` already cover this.




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-08 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r59227



##
File path: 
core/src/main/scala/org/apache/spark/deploy/history/ApplicationCache.scala
##
@@ -62,21 +61,25 @@ private[history] class ApplicationCache(
 
 /**
  * Removal event notifies the provider to detach the UI.
- * @param rm removal notification
+ * @param key removal key
+ * @param value removal value
  */
-override def onRemoval(rm: RemovalNotification[CacheKey, CacheEntry]): 
Unit = {
+override def onRemoval(key: CacheKey, value: CacheEntry,
+cause: RemovalCause): Unit = {

Review comment:
   done




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-08 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r50648



##
File path: 
core/src/main/scala/org/apache/spark/deploy/history/ApplicationCache.scala
##
@@ -62,21 +61,25 @@ private[history] class ApplicationCache(
 
 /**
  * Removal event notifies the provider to detach the UI.
- * @param rm removal notification
+ * @param key removal key
+ * @param value removal value
  */
-override def onRemoval(rm: RemovalNotification[CacheKey, CacheEntry]): 
Unit = {
+override def onRemoval(key: CacheKey, value: CacheEntry,
+cause: RemovalCause): Unit = {
   metrics.evictionCount.inc()
-  val key = rm.getKey
-  logDebug(s"Evicting entry ${key}")
-  operations.detachSparkUI(key.appId, key.attemptId, 
rm.getValue().loadedUI.ui)
+  logDebug(s"Evicting entry $key")
+  operations.detachSparkUI(key.appId, key.attemptId, value.loadedUI.ui)
 }
   }
 
   private val appCache: LoadingCache[CacheKey, CacheEntry] = {
-CacheBuilder.newBuilder()
-.maximumSize(retainedApplications)
-.removalListener(removalListener)
-.build(appLoader)
+val builder = Caffeine.newBuilder()
+  .maximumSize(retainedApplications)
+  .removalListener(removalListener)
+  // SPARK-34309: Use custom Executor to compatible with
+  // the data eviction behavior of Guava cache
+  .executor((command: Runnable) => command.run())

Review comment:
   Yes, it's a compromise for compatibility with old behaviour at present.  
In the future, I will optimize this problem through other pr.




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-08 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r42523



##
File path: 
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/ExternalShuffleBlockResolver.java
##
@@ -315,7 +301,7 @@ private ManagedBuffer getSortBasedShuffleBlockData(
   "shuffle_" + shuffleId + "_" + mapId + "_0.data"),
 shuffleIndexRecord.getOffset(),
 shuffleIndexRecord.getLength());
-} catch (ExecutionException e) {
+} catch (CompletionException e) {

Review comment:
   > Do we have test coverage for this?
   
   Because the `ExecutionException (now is CompletionException)` is re-throw as 
`RuntimeException`, I need to further check whether it is covered by existing 
test case

##
File path: 
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/ExternalShuffleBlockResolver.java
##
@@ -315,7 +301,7 @@ private ManagedBuffer getSortBasedShuffleBlockData(
   "shuffle_" + shuffleId + "_" + mapId + "_0.data"),
 shuffleIndexRecord.getOffset(),
 shuffleIndexRecord.getLength());
-} catch (ExecutionException e) {
+} catch (CompletionException e) {

Review comment:
   > Do we have test coverage for this?
   
   The `ExecutionException (now is CompletionException)` is re-throw as 
`RuntimeException`, I need to further check whether it is covered by existing 
test case




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-07-08 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r39201



##
File path: 
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/ExternalShuffleBlockResolver.java
##
@@ -315,7 +301,7 @@ private ManagedBuffer getSortBasedShuffleBlockData(
   "shuffle_" + shuffleId + "_" + mapId + "_0.data"),
 shuffleIndexRecord.getOffset(),
 shuffleIndexRecord.getLength());
-} catch (ExecutionException e) {
+} catch (CompletionException e) {

Review comment:
   > Can you tell me why we needed to change the exception? Is this just 
what Caffeine throws instead? 
   
   `com.github.benmanes.caffeine.cache.LoadingCache#get` method throw 
`CompletionException` if a checked exception was thrown while loading the value.
   
   `com.google.common.cache.LoadingCache#get` method throw `ExecutionException` 
if a checked exception was thrown while loading the value.
   
   So the exception type here has changed.




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-06-30 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r661986787



##
File path: common/network-shuffle/pom.xml
##
@@ -58,6 +58,14 @@
   slf4j-api
   provided
 
+
+  com.github.ben-manes.caffeine
+  caffeine
+
+
+  com.github.ben-manes.caffeine
+  guava
+

Review comment:
   @holdenk @ben-manes  All the dependencies related to 
`com.github.ben-manes.caffeine: guava` have been removed.
   
   If all test passed , I will try to upgrade caffeine from 2.9.0 to 2.9.1 in 
this pr




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-06-29 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r659767914



##
File path: common/network-shuffle/pom.xml
##
@@ -58,6 +58,14 @@
   slf4j-api
   provided
 
+
+  com.github.ben-manes.caffeine
+  caffeine
+
+
+  com.github.ben-manes.caffeine
+  guava
+

Review comment:
   Yes, I'm trying to get rid of the dependence on 
`com.github.ben-manes.caffeine:guava` in this way

##
File path: core/src/test/scala/org/apache/spark/executor/ExecutorSuite.scala
##
@@ -452,7 +452,8 @@ class ExecutorSuite extends SparkFunSuite
 }
   }
 
-  test("SPARK-33587: isFatalError") {
+  // TODO: will fix it later.

Review comment:
   ignore this case temporarily due to the difference between guava and 
caffeine, will fix it later




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-06-28 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r660260370



##
File path: core/src/test/scala/org/apache/spark/executor/ExecutorSuite.scala
##
@@ -452,7 +452,8 @@ class ExecutorSuite extends SparkFunSuite
 }
   }
 
-  test("SPARK-33587: isFatalError") {
+  // TODO: will fix it later.

Review comment:
   ignore this case temporarily due to the difference between guava and 
caffeine, will fix it later




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-06-28 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r659767914



##
File path: common/network-shuffle/pom.xml
##
@@ -58,6 +58,14 @@
   slf4j-api
   provided
 
+
+  com.github.ben-manes.caffeine
+  caffeine
+
+
+  com.github.ben-manes.caffeine
+  guava
+

Review comment:
   Yes, I'm trying to get rid of the dependence on 
`com.github.ben-manes.caffeine:guava` in this way




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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



[GitHub] [spark] LuciferYang commented on a change in pull request #31517: [SPARK-34309][BUILD][CORE][SQL][K8S]Use Caffeine instead of Guava Cache

2021-06-27 Thread GitBox


LuciferYang commented on a change in pull request #31517:
URL: https://github.com/apache/spark/pull/31517#discussion_r659495725



##
File path: common/network-shuffle/pom.xml
##
@@ -58,6 +58,14 @@
   slf4j-api
   provided
 
+
+  com.github.ben-manes.caffeine
+  caffeine
+
+
+  com.github.ben-manes.caffeine
+  guava
+

Review comment:
   This is a good idea, but there are some interface differences between 
Caffeine and Guava Cache, and spark just uses these interfaces. For example, 
`SessionCatalog` uses `V get(K key, Callable valueLoader)` method 
only define in Guava Cache API




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

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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