Class ExternalSourceCacheService
java.lang.Object
org.elasticsearch.xpack.esql.datasources.cache.ExternalSourceCacheService
- All Implemented Interfaces:
Closeable,AutoCloseable
Coordinator-only, in-memory cache service for external source metadata.
Maintains two independent caches:
- Schema cache (20% of budget, 5m TTL) — shared across users
- Listing cache (80% of budget, 30s TTL) — isolated by credential hash
setExpireAfterWrite for the initial implementation.
Lazy TTL with ETag revalidation is deferred to a follow-up PR.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclearAll()voidclose()getOrComputeListing(ListingCacheKey key, CacheLoader<ListingCacheKey, FileList> loader) Returns a cached file listing or stores the provided one.Returns a cached schema entry or computes it via the loader.Returns a cached schema entry, ornullon a miss (or when the cache is disabled).booleanvoidputSchema(SchemaCacheKey key, SchemaCacheEntry entry) Stores a schema entry.voidReconciles already-merged data-node-captured source stats into the schema cache.voidCoordinator-side entry point.voidsetEnabled(boolean enabled)
-
Constructor Details
-
ExternalSourceCacheService
-
-
Method Details
-
getOrComputeSchema
public SchemaCacheEntry getOrComputeSchema(SchemaCacheKey key, CacheLoader<SchemaCacheKey, SchemaCacheEntry> loader) throws ExceptionReturns a cached schema entry or computes it via the loader. The loader is only invoked on a cache miss. When the cache is disabled, the loader is called directly (bypassing the cache).- Throws:
Exception
-
getSchemaIfPresent
Returns a cached schema entry, ornullon a miss (or when the cache is disabled). UnlikegetOrComputeSchema(org.elasticsearch.xpack.esql.datasources.cache.SchemaCacheKey, org.elasticsearch.common.cache.CacheLoader<org.elasticsearch.xpack.esql.datasources.cache.SchemaCacheKey, org.elasticsearch.xpack.esql.datasources.cache.SchemaCacheEntry>), this never invokes a loader — it is the peek half of the async resolve path, which fetches on a miss without holding an executor thread and then stores the result viaputSchema(org.elasticsearch.xpack.esql.datasources.cache.SchemaCacheKey, org.elasticsearch.xpack.esql.datasources.cache.SchemaCacheEntry). This trades strict thundering-herd coalescing (two concurrent misses for the same key may both fetch) for the ability to resolve asynchronously. -
putSchema
Stores a schema entry. No-op when the cache is disabled. Pairs withgetSchemaIfPresent(org.elasticsearch.xpack.esql.datasources.cache.SchemaCacheKey). -
getOrComputeListing
public FileList getOrComputeListing(ListingCacheKey key, CacheLoader<ListingCacheKey, FileList> loader) throws ExceptionReturns a cached file listing or stores the provided one. The loader is only invoked on a cache miss. When the cache is disabled, the loader is called directly (bypassing the cache).- Throws:
Exception
-
reconcileSourceStatsFromContributions
public void reconcileSourceStatsFromContributions(Map<String, List<Map<String, Object>>> contributionsPerFile) Coordinator-side entry point. Takes theDriverCompletionInfo.capturedSourceMetadatapayload — raw per-file contribution lists shipped back from every data node — merges each list viaSourceStatisticsSerializer.mergeStatistics(Parquet's existing multi-row- group merge algorithm), then enriches the matchingSchemaCacheEntryso the next query's planning-time lookup short-circuits on the merged stats. -
reconcileSourceStats
Reconciles already-merged data-node-captured source stats into the schema cache. For each(path, mergedStats)entry, finds the cachedSchemaCacheEntrywhose location and mtime match and replaces it with a new entry whosesafeMetadatafolds in the merged_stats.*keys. Entries with no cache match are ignored (the warm path will just trigger a fresh metadata() call on the next query). -
setEnabled
public void setEnabled(boolean enabled) -
isEnabled
public boolean isEnabled() -
clearAll
public void clearAll() -
usageStats
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-