This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-9555-02c8e120cf46b77c4988ab977cef35bf1608adcc
in repository https://gitbox.apache.org/repos/asf/texera.git

commit a038371b620f67e9aeb2c067f393f46169ac3331
Author: Meng Wang <[email protected]>
AuthorDate: Mon Nov 23 19:53:20 2026 +0000

    feat(storage): make the per-warehouse catalog cache bounds configurable 
(#9555)
    
    ### What changes were proposed in this PR?
    
    The JVM services cache Iceberg catalog clients one per warehouse,
    bounded at 64 entries and a 60-minute idle expiry (#7539). Both bounds
    were hardcoded; they now come from `storage.conf`, overridable with
    `STORAGE_ICEBERG_CATALOG_CACHE_MAX_SIZE` and
    `STORAGE_ICEBERG_CATALOG_CACHE_IDLE_EXPIRY_MINUTES`. The defaults are
    unchanged, and a value below 1 is refused at startup. The Python worker
    keeps its own catalogs and does not read these.
    
    A computing unit touches the few warehouses of the executions it runs,
    but result-service reads every user's results, so its deployment may
    need a larger bound. Past the bound nothing fails: the least recently
    used client is dropped and rebuilt on its next use, at the cost of a
    round trip to Lakekeeper.
    
    ### Any related issues, documentation, discussions?
    
    Part of #8995. Follows #7539, which bounded the cache.
    
    ### How was this PR tested?
    
    A new `StorageConfigSpec` case pins both defaults, so a renamed key or a
    changed default fails it; raising a default turned it red. Another
    refuses 0 and -1 with a message naming the variable.
    `IcebergCatalogInstanceSpec` passes unchanged, and scalafmt and scalafix
    pass for Config and WorkflowCore.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (claude-opus-5-5)
---
 common/config/src/main/resources/storage.conf      | 13 +++++++++++
 .../texera/common/config/StorageConfig.scala       | 18 ++++++++++++++++
 .../texera/common/config/StorageConfigSpec.scala   | 25 ++++++++++++++++++++++
 .../core/storage/IcebergCatalogInstance.scala      | 10 +++++----
 4 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/common/config/src/main/resources/storage.conf 
b/common/config/src/main/resources/storage.conf
index 45659b776f..ca589bf8de 100644
--- a/common/config/src/main/resources/storage.conf
+++ b/common/config/src/main/resources/storage.conf
@@ -46,6 +46,19 @@ storage {
                 password = "postgres"
                 password = ${?STORAGE_ICEBERG_CATALOG_POSTGRES_PASSWORD}
             }
+
+            # The JVM services cache their catalog clients, one per warehouse 
(#7290). A computing
+            # unit touches few warehouses, but result-service reads every 
user's results, so it may
+            # need a larger max-size. Beyond it, the least recently used 
client is rebuilt on its
+            # next use. Both must be at least 1. The Python worker keeps its 
own catalogs and does
+            # not read these.
+            cache {
+                max-size = 64
+                max-size = ${?STORAGE_ICEBERG_CATALOG_CACHE_MAX_SIZE}
+
+                idle-expiry-minutes = 60
+                idle-expiry-minutes = 
${?STORAGE_ICEBERG_CATALOG_CACHE_IDLE_EXPIRY_MINUTES}
+            }
         }
 
         table {
diff --git 
a/common/config/src/main/scala/org/apache/texera/common/config/StorageConfig.scala
 
b/common/config/src/main/scala/org/apache/texera/common/config/StorageConfig.scala
index 9b9a65b75e..0cdc509451 100644
--- 
a/common/config/src/main/scala/org/apache/texera/common/config/StorageConfig.scala
+++ 
b/common/config/src/main/scala/org/apache/texera/common/config/StorageConfig.scala
@@ -49,6 +49,24 @@ object StorageConfig {
   val icebergPostgresCatalogPassword: String =
     conf.getString("storage.iceberg.catalog.postgres.password")
 
+  // Iceberg catalog cache specifics
+  // 0 would make the cache build a catalog on every call and leave it open 
(Guava evicts it at
+  // once by size, which the cache does not close), and a negative value would 
fail only at the
+  // first catalog access. Fail fast at load time instead, naming the variable 
to fix.
+  private[config] def requireAtLeastOne(value: Int, envVar: String): Int = {
+    require(value >= 1, s"$envVar must be at least 1, got $value")
+    value
+  }
+
+  val icebergCatalogCacheMaxSize: Int = requireAtLeastOne(
+    conf.getInt("storage.iceberg.catalog.cache.max-size"),
+    "STORAGE_ICEBERG_CATALOG_CACHE_MAX_SIZE"
+  )
+  val icebergCatalogCacheIdleExpiryMinutes: Int = requireAtLeastOne(
+    conf.getInt("storage.iceberg.catalog.cache.idle-expiry-minutes"),
+    "STORAGE_ICEBERG_CATALOG_CACHE_IDLE_EXPIRY_MINUTES"
+  )
+
   // Iceberg Table specifics
   val icebergTableResultNamespace: String = 
conf.getString("storage.iceberg.table.result-namespace")
   val icebergTableConsoleMessagesNamespace: String =
diff --git 
a/common/config/src/test/scala/org/apache/texera/common/config/StorageConfigSpec.scala
 
b/common/config/src/test/scala/org/apache/texera/common/config/StorageConfigSpec.scala
index 4c3fef9ef0..56e552e893 100644
--- 
a/common/config/src/test/scala/org/apache/texera/common/config/StorageConfigSpec.scala
+++ 
b/common/config/src/test/scala/org/apache/texera/common/config/StorageConfigSpec.scala
@@ -88,4 +88,29 @@ class StorageConfigSpec extends AnyFlatSpec with Matchers {
       StorageConfig.jupyterTokenSecret shouldBe ""
     }
   }
+
+  "StorageConfig catalog cache settings" should "default to the bounds the 
cache was sized with" in {
+    // Every JVM runs with these unless its deployment overrides them, so a 
slip here would
+    // resize every service's cache. Only assert when neither env override is 
set, since
+    // either would win otherwise.
+    if (
+      sys.env.get("STORAGE_ICEBERG_CATALOG_CACHE_MAX_SIZE").isEmpty &&
+      sys.env.get("STORAGE_ICEBERG_CATALOG_CACHE_IDLE_EXPIRY_MINUTES").isEmpty
+    ) {
+      StorageConfig.icebergCatalogCacheMaxSize shouldBe 64
+      StorageConfig.icebergCatalogCacheIdleExpiryMinutes shouldBe 60
+    }
+  }
+
+  it should "refuse a bound below 1, naming the variable" in {
+    for (value <- Seq(0, -1)) {
+      val error = intercept[IllegalArgumentException] {
+        StorageConfig.requireAtLeastOne(value, 
"STORAGE_ICEBERG_CATALOG_CACHE_MAX_SIZE")
+      }
+      error.getMessage should include(
+        s"STORAGE_ICEBERG_CATALOG_CACHE_MAX_SIZE must be at least 1, got 
$value"
+      )
+    }
+    StorageConfig.requireAtLeastOne(1, 
"STORAGE_ICEBERG_CATALOG_CACHE_MAX_SIZE") shouldBe 1
+  }
 }
diff --git 
a/common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/IcebergCatalogInstance.scala
 
b/common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/IcebergCatalogInstance.scala
index 3e2eabceea..19628d6385 100644
--- 
a/common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/IcebergCatalogInstance.scala
+++ 
b/common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/IcebergCatalogInstance.scala
@@ -67,10 +67,12 @@ import scala.util.Try
   */
 object IcebergCatalogInstance extends LazyLogging {
 
-  // Sizing mirrors HuggingFaceModelResource's bounded-cache precedent: 
generous enough
-  // that eviction never hits a warehouse in active use, small enough to bound 
the JVM.
-  private val CatalogCacheMaxSize = 64L
-  private val CatalogCacheExpireAfterAccess = Duration.ofMinutes(60)
+  // The default sizing mirrors HuggingFaceModelResource's bounded-cache 
precedent: generous
+  // enough that eviction never hits a warehouse in active use, small enough 
to bound the JVM.
+  // A deployment can raise it for a service that touches many warehouses, 
like result-service.
+  private val CatalogCacheMaxSize = 
StorageConfig.icebergCatalogCacheMaxSize.toLong
+  private val CatalogCacheExpireAfterAccess =
+    Duration.ofMinutes(StorageConfig.icebergCatalogCacheIdleExpiryMinutes)
 
   /**
     * Builds a catalog cache with the eviction wiring `getInstance` relies on.

Reply via email to