feat: add ConnectionManager to replace connections singleton for MilvusClient#3283
Open
XuanYang-cn wants to merge 1 commit intomilvus-io:masterfrom
Open
feat: add ConnectionManager to replace connections singleton for MilvusClient#3283XuanYang-cn wants to merge 1 commit intomilvus-io:masterfrom
XuanYang-cn wants to merge 1 commit intomilvus-io:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: XuanYang-cn The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3283 +/- ##
==========================================
+ Coverage 76.46% 77.10% +0.63%
==========================================
Files 63 64 +1
Lines 13321 13575 +254
==========================================
+ Hits 10186 10467 +281
+ Misses 3135 3108 -27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…usClient Introduce a new ConnectionManager component that provides connection pooling, lifecycle management, and strategy-based connection handling for MilvusClient, bypassing the legacy `connections` singleton. Key features: - Strategy pattern: RegularStrategy for direct connections, GlobalStrategy for global cluster topology discovery & primary routing - Connection deduplication by address|token key (shared mode) - Dedicated connection mode for isolated connections - Health check on idle connections (>30s): gRPC state + GetVersion probe - UNAVAILABLE error recovery via strategy.on_unavailable() -> bool - Split-lock pattern (sync) to avoid holding lock during network I/O - Fully async chain for AsyncConnectionManager (asyncio.Lock, async error callbacks, async recovery with ensure_channel_ready) - _GlobalStrategyMixin extracts shared topology logic for sync/async - Background TopologyRefresher for global clusters (5min interval) - Error callback chain: retry decorator -> handler._on_rpc_error -> ConnectionManager.handle_error -> _recover Integration: - MilvusClient.__init__ uses ConnectionManager.get_or_create() - AsyncMilvusClient uses deferred _connect() via __aenter__ - db_name is per-client via CallContext, not per-handler - Both clients register as WeakSet references on shared connections Also includes: - Design docs in docs/plans/ with template and README - Comprehensive test suite (132 tests, 100% coverage on connection_manager.py) - Removes dead code: GlobalStub class (superseded by GlobalStrategy), ConnectionConfig.secure field (never consumed by handlers) Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: yangxuan <[email protected]>
c748d9f to
820d123
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ConnectionManagercomponent with strategy pattern (RegularStrategy/GlobalStrategy) that provides connection pooling, lifecycle management, and UNAVAILABLE error recovery forMilvusClient, bypassing the legacyconnectionssingletonMilvusClientandAsyncMilvusClientto useConnectionManager/AsyncConnectionManagerwith shared connection deduplication byaddress|token, health checks on idle connections, and per-clientdb_nameviaCallContextconnection_manager.py) and design documentation indocs/plans/Design
See pymilvus-002-connection-manager-design.md for full design doc.
Key Architecture Decisions
RegularStrategyfor direct connections,GlobalStrategyfor global cluster topology discovery & primary routing via_GlobalStrategyMixinon_unavailable() -> bool: Strategies decide whether recovery is needed;ConnectionManager._recover()is shared logicon_unavailable()network I/O, re-acquired and re-verified before_recover()AsyncConnectionManagerusesasyncio.Lock, async error callbacks, and awaitsensure_channel_ready()on recoveryaddress|tokenkey;db_nameis per-client viaBaseMilvusClient._generate_call_context()Test plan
ConnectionConfig.from_uri()parsing (various URI formats, overrides, invalid schemes)RegularStrategyandGlobalStrategy_GlobalStrategyMixinedge casesMilvusClientandAsyncMilvusClientintegration withConnectionManagerconnection_manager.py🤖 Generated with Claude Code