Skip to content

feat: add LRU eviction to CollectionTsCache and cache capacity controls - #644

Merged
sre-ci-robot merged 1 commit into
milvus-io:masterfrom
yhmo:feat/cache-capacity-lru
Nov 23, 2026
Merged

sre-ci-robot merged 1 commit into
milvus-io:masterfrom
yhmo:feat/cache-capacity-lru

Conversation

@yhmo

@yhmo yhmo commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Make the collection timestamp cache a bounded LRU (default 4096, matching pymilvus) and expose a single API to tune both in-process cache capacities.

  • CollectionTsCache is now a size-bounded LRU: default capacity 4096 (shared kCollectionCacheDefaultCapacity constant with SchemaCache), constructor capacity, SetCapacity/Capacity, recency tracking on get/set, and LRU eviction when full (Move/Copy transfer too).
  • SchemaCache gains SetCapacity/Capacity so the bound can change at runtime; shrinking evicts immediately.
  • New public header milvus/utils/CacheConfig.h with CacheConfig::SetCapacity(size_t) setting both cache bounds under a shared lock and CacheConfig::GetCapacity() reading the schema cache capacity (0 is rejected with INVALID_ARGUMENT). CacheConfig.h and FP16.h are now exposed through the aggregate MilvusClientV2.h.
  • Tests: new TestCacheConfig.cpp for the public API, TsCache LRU-eviction/shrink/transfer-at-capacity/concurrent-set-get tests, SchemaCache shrink test; the former no-limit DoesNotEvictSessionTimestamps case now asserts LRU behavior.

Verified: full ut suite passes, clang-format clean.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 08:06
@sre-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: yhmo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@mergify

mergify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

Comment thread test/ut/utils/TestCache.cpp Resolved
Comment thread src/include/milvus/utils/CacheConfig.h Resolved
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch 2 times, most recently from 658a691 to 133ac85 Compare November 18, 2026 08:48
Comment thread test/ut/utils/TestCollectionTsCache.cpp Resolved
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from 133ac85 to 641e723 Compare November 18, 2026 09:20
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.47%. Comparing base (a0592aa) to head (bfc34e5).
⚠️ Report is 186 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #644       +/-   ##
===========================================
+ Coverage   53.47%   89.47%   +36.00%     
===========================================
  Files          52      451      +399     
  Lines        4432    18989    +14557     
  Branches        0     2114     +2114     
===========================================
+ Hits         2370    16991    +14621     
+ Misses       2062     1995       -67     
- Partials        0        3        +3     
Files with missing lines Coverage Δ
src/impl/utils/CacheConfig.cpp 100.00% <100.00%> (ø)
src/impl/utils/cache/CollectionTsCache.cpp 98.87% <100.00%> (ø)
src/impl/utils/cache/CollectionTsCache.h 100.00% <100.00%> (ø)
src/impl/utils/cache/SchemaCache.cpp 93.61% <100.00%> (ø)
src/impl/utils/cache/SchemaCache.h 100.00% <ø> (ø)
src/include/milvus/MilvusClientV2.h 33.33% <ø> (ø)

... and 462 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/include/milvus/MilvusClientV2.h Resolved
Comment thread test/ut/utils/TestCollectionTsCache.cpp Resolved
@yhmo

yhmo commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Review summary

Overall this is a coherent, well-tested change: CollectionTsCache becomes a bounded LRU (default 4096, mirroring pymilvus's CacheRegion.DEFAULT_CAPACITY), SchemaCache gains runtime capacity controls, and the new milvus::Cache facade is correctly exposed through the aggregate header. I traced the LRU math, the lock/atomic design, and the callers (DqlUtils SESSION/ts fallback, move/copy/rename paths) and found no correctness bug; the SESSION-consistency trade-off beyond 4096 keys, the O(n) min_element eviction, and the duplicated LRU machinery were already raised and dispositioned in the resolved self-review threads, so I did not repost them.

Two Low, non-blocking notes were posted inline:

  • src/include/milvus/MilvusClientV2.h:28 — the unrelated milvus/utils/FP16.h aggregate-header include widens the public surface in a cache-tuning PR.
  • test/ut/utils/TestCollectionTsCache.cpp:92 — the new default_capacity = 4096 boundary itself has no regression test now that DoesNotEvictSessionTimestamps was replaced with explicit small-capacity tests.

@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from 641e723 to a9f43a9 Compare November 20, 2026 04:52
@mergify mergify Bot added the ci-passed label Nov 20, 2026
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from a9f43a9 to ddb4339 Compare November 20, 2026 07:53
@mergify mergify Bot removed the ci-passed label Nov 20, 2026
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from ddb4339 to b09e805 Compare November 20, 2026 08:04
Comment thread src/impl/utils/CacheConfig.cpp Resolved
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from b09e805 to f4e2a2e Compare November 20, 2026 08:53
Comment thread test/ut/utils/TestSchemaCache.cpp Resolved
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from b1769a3 to 10189e0 Compare November 20, 2026 09:48
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from 10189e0 to 8af3d21 Compare November 20, 2026 10:06
Comment thread src/include/milvus/utils/CacheConfig.h Resolved
Comment thread src/include/milvus/utils/CacheConfig.h Resolved
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from 8af3d21 to 144d46b Compare November 20, 2026 10:31
Comment thread src/impl/utils/CacheConfig.cpp Resolved
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch 2 times, most recently from 1f38c19 to 5eb730d Compare November 23, 2026 02:55
@mergify mergify Bot added the ci-passed label Nov 23, 2026
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from 5eb730d to f1e2f87 Compare November 23, 2026 04:23
@mergify mergify Bot removed the ci-passed label Nov 23, 2026
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from f1e2f87 to 141b245 Compare November 23, 2026 04:30

@yhmo yhmo left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finalizing the pending review that carries the resolved PR-description naming thread so new review comments can be posted.

Comment thread src/include/milvus/utils/CacheConfig.h Resolved
Comment thread test/ut/utils/TestCollectionTsCache.cpp Resolved
Comment thread src/impl/utils/CacheConfig.cpp Resolved
@mergify mergify Bot added the ci-passed label Nov 23, 2026
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from 141b245 to b2566cc Compare November 23, 2026 06:19
@mergify mergify Bot added ci-passed and removed ci-passed labels Nov 23, 2026
@yhmo
yhmo force-pushed the feat/cache-capacity-lru branch from b2566cc to bfc34e5 Compare November 23, 2026 07:26
@mergify mergify Bot removed the ci-passed label Nov 23, 2026
@mergify mergify Bot added the ci-passed label Nov 23, 2026
@yhmo yhmo added the lgtm label Nov 23, 2026
@sre-ci-robot
sre-ci-robot merged commit bed7ca5 into milvus-io:master Nov 23, 2026
13 checks passed
@yhmo
yhmo deleted the feat/cache-capacity-lru branch November 23, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants