Repository navigation
Conversation
4dd684a to
b457a3e
Compare
b457a3e to
a288076
Compare
Expose `Session::set_index_cache_capacity` and `Session::set_metadata_cache_capacity`, plus their Python equivalents, so an application managing several sessions can bound their combined memory without dropping or recreating them. `QuickCacheBackend` now tracks its capacity atomically and trims both the ordinary and priority tiers when shrunk; backends that cannot resize (such as moka) report `NotSupported`. Closes lance-format#10137
a3ee069 to
dcd0cd9
Compare
|
Rebased onto One behaviour change worth calling out: my previous version made
Verification on this branch:
The diff is now limited to |
`LanceCache` skips the deep-size traversal while a backend reports itself size-blind, which lets a disabled cache insert without paying for a measurement it would discard. Resizing the capacity at runtime breaks that premise: an insertion that started while the cache was disabled can reach admission after the growth, and it would then be charged its key footprint alone, so the grown budget can never reclaim the payload it holds. Keep the traversal skipped while the cache is disabled, and have the quick backend refuse any insertion whose size was never measured. The check runs after the write is recorded but before admission, so it never consults the current capacity: an insertion racing a growth observes whatever capacity is current at that instant, and a zero size proves the value was not measured either way. Callers still get their value; it is simply not retained, and a disabled cache keeps reporting the attempt as a rejected write. Two tests cover it. One races an oversized insertion against a capacity growth and then re-inserts the same value to show the rejection is about the missing size rather than the resize. The other drives the backend directly at zero and non-zero capacity through both the insert and load paths, so a pre-insertion check that trusted the capacity it observed would fail.
dcd0cd9 to
1df1af1
Compare
|
Follow-up on the gate request-changes: the grow-from-zero accounting failure is fixed in
Coverage:
Local verification: |
Xuanwo
left a comment
There was a problem hiding this comment.
Approved for squash merge at 76ab9a8. All 46 check runs are terminal (45 success; Arrow ordering compatibility skipped because its detector found no dependency, fixture, or exercised-crate change), all 14 workflow runs are successful, and the format-spec vote gate reports success. The latest Gatekeeper review on this head recommends approval, and the three prior discussion threads are resolved. The session cache capacity API, priority-eviction accounting, and disabled-cache sizing shortcut match the accepted scope.
Summary
Exposes the caches' capacity as a runtime knob through the session API, so an application that manages several sessions can bound their combined memory without dropping or recreating them:
CacheBackend::set_capacity(default:NotSupported), implemented byQuickCacheBackend.LanceCache::set_capacity.Session::set_index_cache_capacityandSession::set_metadata_cache_capacity, in Rust and Python (lance.Session).Shrinking evicts down to the new budget immediately: the quick cache trims its shards, and a cache in priority-admission mode trims its priority tier (lowest priority, then oldest). Priority-tier evictions are reported through the same size-removal counters as ordinary cache evictions. Growing only raises the budget; evicted entries reload on demand. Clones of a session share the cache, so every handle observes the new capacity.
Backends that cannot resize after construction (such as moka) return
NotSupported/ValueErrorrather than silently ignoring the request.Resizing also has to keep byte accounting honest.
LanceCacheskips the deep-size traversal while a backend reports itself size-blind, so an insertion that started on a disabled cache can reach admission after the cache grew.QuickCacheBackendtherefore refuses any insertion whose size is zero — the value was never measured — instead of charging it its key footprint alone. The check runs before admission and never consults the current capacity, so a resize racing the insertion cannot slip an unmeasured value through. Callers still get their value; it is simply not retained, and a disabled cache keeps reporting the attempt as a rejected write.Closes #10137.
Test plan
Validated on the integrated tree after merging
main(12ca831a):cargo test --profile ci -p lance-core --lib cache::— new tests cover shrink eviction and reported limits, priority-tier trimming (including exactly one size-removal and its byte weight),PriorityEntriesbudget trimming, an insertion racing a capacity growth, and unmeasured insertions being refused at any capacity.cargo test --profile ci -p lance --lib session::— new tests resize both caches, observe the change through a session clone, and report unsupported backends.cargo clippy --profile ci --all --tests --benches -- -D warnings,cargo fmt --all -- --check.make install && make buildfrompython/, thenuv run pytest python/tests/test_session.py— new tests evict resident entries by shrinking to zero, re-admit them after growing, and reject unsupported backends.uv run make lintfrompython/.