Skip to content

Commit 6c091d7

Browse files
sunxiaojianAbyss-lord
authored andcommittedFeb 6, 2025
[apache#6270] (Improvement) unified cache framework (apache#6271)
### What changes were proposed in this pull request? Unified cache framework ### Why are the changes needed? Fix: apache#6270 ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? N/A
1 parent 953a66e commit 6c091d7

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed
 

‎spark-connector/spark-common/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ val scalaCollectionCompatVersion: String = libs.versions.scala.collection.compat
4040
dependencies {
4141
implementation(project(":catalogs:catalog-common"))
4242
implementation(libs.guava)
43+
implementation(libs.caffeine)
4344

4445
compileOnly(project(":clients:client-java-runtime", configuration = "shadow"))
4546
compileOnly("org.apache.iceberg:iceberg-spark-runtime-${sparkMajorVersion}_$scalaVersion:$icebergVersion")

‎spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/GravitinoCatalogManager.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
*/
1919
package org.apache.gravitino.spark.connector.catalog;
2020

21+
import com.github.benmanes.caffeine.cache.Cache;
22+
import com.github.benmanes.caffeine.cache.Caffeine;
2123
import com.google.common.base.Preconditions;
2224
import com.google.common.base.Supplier;
23-
import com.google.common.cache.Cache;
24-
import com.google.common.cache.CacheBuilder;
2525
import java.util.Arrays;
2626
import java.util.Map;
27-
import java.util.concurrent.ExecutionException;
2827
import org.apache.gravitino.Catalog;
2928
import org.apache.gravitino.client.GravitinoClient;
3029
import org.slf4j.Logger;
@@ -42,7 +41,7 @@ public class GravitinoCatalogManager {
4241
private GravitinoCatalogManager(Supplier<GravitinoClient> clientBuilder) {
4342
this.gravitinoClient = clientBuilder.get();
4443
// Will not evict catalog by default
45-
this.gravitinoCatalogs = CacheBuilder.newBuilder().build();
44+
this.gravitinoCatalogs = Caffeine.newBuilder().build();
4645
}
4746

4847
public static GravitinoCatalogManager create(Supplier<GravitinoClient> clientBuilder) {
@@ -69,8 +68,8 @@ public void close() {
6968

7069
public Catalog getGravitinoCatalogInfo(String name) {
7170
try {
72-
return gravitinoCatalogs.get(name, () -> loadCatalog(name));
73-
} catch (ExecutionException e) {
71+
return gravitinoCatalogs.get(name, catalogName -> loadCatalog(catalogName));
72+
} catch (Exception e) {
7473
LOG.error(String.format("Load catalog %s failed", name), e);
7574
throw new RuntimeException(e);
7675
}

‎spark-connector/v3.3/spark-runtime/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tasks.withType<ShadowJar>(ShadowJar::class.java) {
5151
relocate("com.google", "org.apache.gravitino.shaded.com.google")
5252
relocate("google", "org.apache.gravitino.shaded.google")
5353
relocate("org.apache.hc", "org.apache.gravitino.shaded.org.apache.hc")
54+
relocate("com.github.benmanes.caffeine", "org.apache.gravitino.shaded.com.github.benmanes.caffeine")
5455
}
5556

5657
publishing {

‎spark-connector/v3.4/spark-runtime/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tasks.withType<ShadowJar>(ShadowJar::class.java) {
5151
relocate("com.google", "org.apache.gravitino.shaded.com.google")
5252
relocate("google", "org.apache.gravitino.shaded.google")
5353
relocate("org.apache.hc", "org.apache.gravitino.shaded.org.apache.hc")
54+
relocate("com.github.benmanes.caffeine", "org.apache.gravitino.shaded.com.github.benmanes.caffeine")
5455
}
5556

5657
publishing {

‎spark-connector/v3.5/spark-runtime/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ tasks.withType<ShadowJar>(ShadowJar::class.java) {
5151
relocate("com.google", "org.apache.gravitino.shaded.com.google")
5252
relocate("google", "org.apache.gravitino.shaded.google")
5353
relocate("org.apache.hc", "org.apache.gravitino.shaded.org.apache.hc")
54+
relocate("com.github.benmanes.caffeine", "org.apache.gravitino.shaded.com.github.benmanes.caffeine")
5455
}
5556

5657
publishing {

0 commit comments

Comments
 (0)
Failed to load comments.