From be8d1d31d03692f199364dbbb71f7cd2a6910b7f Mon Sep 17 00:00:00 2001 From: Karol Sobczak Date: Sun, 19 Mar 2023 11:57:37 +0100 Subject: [PATCH] Make hive.metastore-stats-cache-ttl >= to hive.metastore-cache-ttl Some deployments might had hive.metastore-cache-ttl already set. https://github.com/trinodb/trino/pull/15811 introduced new config hive.metastore-stats-cache-ttl which could be lower (by default) for such deployments. However, hive.metastore-cache-ttl should take precedense over hive.metastore-stats-cache-ttl as it's more generic (affects whole metastore cache). --- .../metastore/cache/SharedHiveMetastoreCache.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/cache/SharedHiveMetastoreCache.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/cache/SharedHiveMetastoreCache.java index a1994e447726..c008af2d5aa7 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/cache/SharedHiveMetastoreCache.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/cache/SharedHiveMetastoreCache.java @@ -78,8 +78,14 @@ public SharedHiveMetastoreCache( // Disable caching on workers, because there currently is no way to invalidate such a cache. // Note: while we could skip CachingHiveMetastoreModule altogether on workers, we retain it so that catalog // configuration can remain identical for all nodes, making cluster configuration easier. - boolean metadataCacheEnabled = config.getMetastoreCacheTtl().toMillis() > 0; - boolean statsCacheEnabled = config.getStatsCacheTtl().toMillis() > 0; + Duration metastoreCacheTtl = config.getMetastoreCacheTtl(); + Duration statsCacheTtl = config.getStatsCacheTtl(); + if (metastoreCacheTtl.compareTo(statsCacheTtl) > 0) { + statsCacheTtl = metastoreCacheTtl; + } + + boolean metadataCacheEnabled = metastoreCacheTtl.toMillis() > 0; + boolean statsCacheEnabled = statsCacheTtl.toMillis() > 0; enabled = (metadataCacheEnabled || statsCacheEnabled) && nodeManager.getCurrentNode().isCoordinator() && config.getMetastoreCacheMaximumSize() > 0; @@ -87,8 +93,8 @@ public SharedHiveMetastoreCache( cachingMetastoreBuilder = CachingHiveMetastore.builder() .metadataCacheEnabled(metadataCacheEnabled) .statsCacheEnabled(statsCacheEnabled) - .cacheTtl(config.getMetastoreCacheTtl()) - .statsCacheTtl(config.getStatsCacheTtl()) + .cacheTtl(metastoreCacheTtl) + .statsCacheTtl(statsCacheTtl) .refreshInterval(config.getMetastoreRefreshInterval()) .maximumSize(config.getMetastoreCacheMaximumSize()) .partitionCacheEnabled(config.isPartitionCacheEnabled());