Skip to content

fix: retry on REPLICATE_VIOLATION for global cluster region switch#3285

Merged
sre-ci-robot merged 2 commits intomilvus-io:masterfrom
huanghaoyuanhhy:fix/global-cluster-replicate-violation-retry
Mar 3, 2026
Merged

fix: retry on REPLICATE_VIOLATION for global cluster region switch#3285
sre-ci-robot merged 2 commits intomilvus-io:masterfrom
huanghaoyuanhhy:fix/global-cluster-replicate-violation-retry

Conversation

@huanghaoyuanhhy
Copy link
Contributor

Summary

  • When a Global Cluster switches its primary region, write operations to the old primary (now secondary) fail with STREAMING_CODE_REPLICATE_VIOLATION
  • Previously this MilvusException was not handled in the retry decorator, so writes failed for up to 5 minutes until the background TopologyRefresher (300s interval) detected the change
  • Add _handle_global_routing_error() in GrpcHandler to detect REPLICATE_VIOLATION and trigger immediate topology refresh
  • Hook it into the retry_on_rpc_failure decorator's MilvusException branch (both sync and async) so the operation retries automatically after refresh

Test plan

  • Deploy a Global Cluster on Zilliz Cloud (UAT)
  • Run continuous insert + search loop
  • Switch primary region in console
  • Before fix: INSERT fails with REPLICATE_VIOLATION for ~5 minutes until background refresh
  • After fix: INSERT auto-recovers in ~10 seconds (topology refresh + retry backoff)
  • Unit tests for _handle_global_routing_error (4 new tests, all passing)

@sre-ci-robot
Copy link

Welcome @huanghaoyuanhhy! It looks like this is your first PR to milvus-io/pymilvus 🎉

@XuanYang-cn
Copy link
Contributor

/assign @bigsheeper

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.81%. Comparing base (2277a72) to head (fd6323b).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3285      +/-   ##
==========================================
+ Coverage   76.68%   76.81%   +0.13%     
==========================================
  Files          63       63              
  Lines       13235    13244       +9     
==========================================
+ Hits        10149    10174      +25     
+ Misses       3086     3070      -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

When a Global Cluster switches its primary region, write operations to
the old primary fail with STREAMING_CODE_REPLICATE_VIOLATION. Previously
this error was not handled in the retry decorator, causing writes to
fail for up to 5 minutes until the background topology refresher ran.

Add _handle_global_routing_error() to detect REPLICATE_VIOLATION and
trigger an immediate topology refresh with retry, enabling automatic
recovery in seconds instead of minutes.

Signed-off-by: huanghaoyuanhhy <[email protected]>
@huanghaoyuanhhy huanghaoyuanhhy force-pushed the fix/global-cluster-replicate-violation-retry branch from e543d13 to a7844f7 Compare March 3, 2026 04:01
@bigsheeper
Copy link
Contributor

/lgtm

@sre-ci-robot sre-ci-robot removed the lgtm label Mar 3, 2026
@huanghaoyuanhhy
Copy link
Contributor Author

Fixed the review comment and lint issues. Verified locally with make lint - all checks passed.

@mergify mergify bot added the ci-passed label Mar 3, 2026
Copy link
Contributor

@XuanYang-cn XuanYang-cn left a comment

Choose a reason for hiding this comment

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

/lgtm

@sre-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: huanghaoyuanhhy, XuanYang-cn

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

@sre-ci-robot sre-ci-robot merged commit 4d607f3 into milvus-io:master Mar 3, 2026
13 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 3, 2026
…3285)

## Summary
- When a Global Cluster switches its primary region, write operations to
the old primary (now secondary) fail with
`STREAMING_CODE_REPLICATE_VIOLATION`
- Previously this `MilvusException` was not handled in the retry
decorator, so writes failed for up to 5 minutes until the background
`TopologyRefresher` (300s interval) detected the change
- Add `_handle_global_routing_error()` in `GrpcHandler` to detect
`REPLICATE_VIOLATION` and trigger immediate topology refresh
- Hook it into the `retry_on_rpc_failure` decorator's `MilvusException`
branch (both sync and async) so the operation retries automatically
after refresh

## Test plan
- [x] Deploy a Global Cluster on Zilliz Cloud (UAT)
- [x] Run continuous insert + search loop
- [x] Switch primary region in console
- [x] **Before fix**: INSERT fails with `REPLICATE_VIOLATION` for ~5
minutes until background refresh
- [x] **After fix**: INSERT auto-recovers in ~10 seconds (topology
refresh + retry backoff)
- [x] Unit tests for `_handle_global_routing_error` (4 new tests, all
passing)

---------

Signed-off-by: huanghaoyuanhhy <[email protected]>
(cherry picked from commit 4d607f3)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@pymilvus-bot
Copy link
Collaborator

Backport Created
Hi @huanghaoyuanhhy, Backport PR for 2.6 has been created: #3298

(cc @bigsheeper @XuanYang-cn)

sre-ci-robot pushed a commit that referenced this pull request Mar 3, 2026
…egion switch (#3285) (#3298)

Backport of #3285 to `2.6`.

Signed-off-by: huanghaoyuanhhy <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: huanghaoyuanhhy <[email protected]>
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.

5 participants