All four DataFusion analytics caches (footer metadata, statistics,
column-index, offset-index) previously each had their own eviction
policy trait, stats shape, and per-type match arms in the cache
manager and FFI layer. This made plugging in a new eviction policy
(e.g. S3-FIFO) a four-place change.
This unifies the interfaces without changing any policy or behavior:
- One generic EvictionPolicy<K> trait replaces CachePolicy (string
keys) and ScopedEvictionPolicy (typed keys). LRU/LFU/FIFO all
implement it; a new policy is one impl + one enum variant.
- New cache::unified module: CacheKind (parses the Java type string
once, carries the per-kind policy validity rules in one place) and
ManagedCache (stats/limits/clear/remove-file/contains-file), with
a shared CacheStats snapshot struct.
- CustomCacheManager becomes a CacheKind-keyed registry of
Arc<dyn ManagedCache>; clear/limit/memory/contains/remove
operations dispatch uniformly instead of matching per type.
df_cache_manager_update_size_limit now accepts all four kinds.
- FifoPolicy drops its UnsafeCell for an uncontended parking_lot
Mutex, so it is safe as a shared trait object.
Query-path get/put stays on each cache's typed API — only the
management plane is unified. No settings, eviction behavior, or
FFI signatures change.
Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
Description
Unifies the interfaces of all four DataFusion analytics-backend caches (footer metadata, statistics, column-index, offset-index) so a future eviction-policy change is a one-place plug-in — without changing any eviction policy or behavior, and without adding any new dependency (no foyer).
Previously each cache had its own eviction trait, stats shape, and per-type match arms in the cache manager and FFI layer, so introducing a new policy (e.g. S3-FIFO) meant touching four places.
1. One eviction-policy trait
EvictionPolicy<K>replaces the two previous traits (CachePolicywith hardcodedStringkeys for the statistics cache, andScopedEvictionPolicy<K>private toBoundedCache).LruPolicy,LfuPolicy, andFifoPolicyall implement it; the eviction protocol is unified onnext_victim()(pop one candidate), so the statistics cache's batchselect_for_evictionAPI is gone.FifoPolicymoves fromcache_store.rsintoeviction_policy.rsand swaps itsUnsafeCellfor an uncontendedparking_lot::Mutexso it is sound as a shared trait object.Adding a new policy = one trait impl + one
CacheEvictionPolicyvariant.2. New
cache/unified.rs— the management planeCacheKind— closed enum for the four cache types. Parses the Java FFI type string once, andvalidate_policy()centralizes the per-cache validity rules that used to be scattered as match-arm guards indf_create_cache(statistics = LRU/LFU, CI/OI = FIFO-only, metadata = accepted but not forwarded).ManagedCache— the uniform lifecycle/observability surface (stats,set_limit,clear,reset_counters,remove_file,contains_file) with a sharedCacheStatssnapshot. All four caches implement it; the process-global CI/OI singletons via zero-sized handles.Query-path get/put intentionally stays on each cache's typed API — the key/value shapes differ per cache and erasing them would cost hot-path performance for no management benefit.
3. Registry-based
CustomCacheManagerThe manager now holds a
CacheKind → Arc<dyn ManagedCache>registry;clear_cache_type,get_memory_consumed_by_type,contains_file_by_type,remove_files, and the ~10 per-cache stat accessors collapse into registry dispatch.df_create_cacheanddf_cache_manager_update_size_limitroute viaCacheKind::parse; the latter now accepts all four kinds (previously METADATA/STATISTICS only). The separate CI/OI limit FFIs are unchanged.Non-changes
CacheTypeenum.clear_cache_type("COLUMN_INDEX")now clears only CI instead of both CI+OI (the Java caller clears both via the same path, so nothing user-visible changes).Related Issues
Interface-unification slice of #22282 (which additionally swapped the implementations to foyer + S3-FIFO); this PR does only the unification so policy changes can land separately.
Check List
cargo test --lib: 1273 passed; rustfmt + clippy clean on touched files; plugincompileJava/compileTestJava/testpass.--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.