[Enhancement] Add config to disable statistics cache lazy refresh by default (backport #62518) (#62573)

Co-authored-by: stephen <91597003+stephen-shelby@users.noreply.github.com>
This commit is contained in:
mergify[bot] 2025-09-01 15:17:38 +08:00 committed by GitHub
parent 95b4145579
commit dacc9100f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View File

@ -2127,7 +2127,7 @@ public class Config extends ConfigBase {
* The size of the thread-pool which will be used to refresh statistic caches
*/
@ConfField
public static int statistic_cache_thread_pool_size = 10;
public static int statistic_cache_thread_pool_size = 5;
@ConfField
public static int slot_manager_response_thread_pool_size = 16;
@ -2150,6 +2150,9 @@ public class Config extends ConfigBase {
@ConfField(mutable = true)
public static long statistic_update_interval_sec = 24L * 60L * 60L;
@ConfField(mutable = true)
public static boolean enable_statistic_cache_refresh_after_write = false;
@ConfField(mutable = true)
public static long statistic_collect_too_many_version_sleep = 600000; // 10min
/**

View File

@ -720,12 +720,17 @@ public class CachedStatisticStorage implements StatisticStorage, MemoryTrackable
}
private <K, V> AsyncLoadingCache<K, V> createAsyncLoadingCache(AsyncCacheLoader<K, V> cacheLoader) {
return Caffeine.newBuilder()
Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder()
.expireAfterWrite(Config.statistic_update_interval_sec * 2, TimeUnit.SECONDS)
.refreshAfterWrite(Config.statistic_update_interval_sec, TimeUnit.SECONDS)
.maximumSize(Config.statistic_cache_columns)
.executor(statsCacheRefresherExecutor)
.buildAsync(cacheLoader);
.executor(statsCacheRefresherExecutor);
// Only enable refreshAfterWrite if the config is enabled
if (Config.enable_statistic_cache_refresh_after_write) {
cacheBuilder.refreshAfterWrite(Config.statistic_update_interval_sec, TimeUnit.SECONDS);
}
return cacheBuilder.buildAsync(cacheLoader);
}
}