Skip to content

fix: support explicit db_name in snapshot APIs for cross-database operations#3295

Open
zhuwenxing wants to merge 1 commit intomilvus-io:masterfrom
zhuwenxing:fix-snapshot-db-name
Open

fix: support explicit db_name in snapshot APIs for cross-database operations#3295
zhuwenxing wants to merge 1 commit intomilvus-io:masterfrom
zhuwenxing:fix-snapshot-db-name

Conversation

@zhuwenxing
Copy link
Contributor

Summary

  • Add explicit db_name parameter to 4 snapshot APIs (create_snapshot, list_snapshots, restore_snapshot, list_restore_snapshot_jobs) across all layers (Prepare, GrpcHandler, AsyncGrpcHandler, MilvusClient, AsyncMilvusClient)
  • The db_name is now populated in the protobuf request body, enabling cross-database snapshot operations (e.g., restore a snapshot from db_a into db_b)
  • This complements fix: pass database context in all snapshot APIs #3292 which added gRPC metadata context — now db_name is sent via both proto body and metadata header

Why both proto body and metadata?

Path When it works
Proto body db_name When user passes explicit db_name parameter (cross-db operations)
Metadata header dbname (via CallContext) When user omits db_name, falls back to client's self._db_name via DatabaseInterceptor

Affected APIs

API db_name in proto body
create_snapshot added
list_snapshots added
restore_snapshot added
list_restore_snapshot_jobs added

Example: cross-database restore

client_a = MilvusClient(uri="...", db_name="db_a")
# Create snapshot in db_a
client_a.create_snapshot(collection_name="my_col", snapshot_name="snap1")

# Restore to a different database
client_a.restore_snapshot(
    snapshot_name="snap1",
    collection_name="restored_col",
    db_name="db_b",  # explicit target database
)

Test plan

  • Unit tests: 29 snapshot tests pass (including 4 new cross-db tests)
  • Integration tests: 36 scenarios pass against Milvus master (338bac3), covering:
    • 3 databases with different collections/snapshots
    • create_snapshot with explicit db_name from default-db client
    • list_snapshots per database with db_name filter
    • Cross-db restore: db_adb_b, db_adb_c (empty db)
    • Same-db restore: db_bdb_b
    • Same-db restore without explicit db_name (uses client's db via metadata)
    • Data isolation verification across all 3 databases

@sre-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zhuwenxing
To complete the pull request process, please assign longjiquan after the PR has been reviewed.
You can assign the PR to them by writing /assign @longjiquan in a comment when ready.

The full list of commands accepted by this bot can be found 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

…s-database operations

Signed-off-by: zhuwenxing <wenxing.zhu@zilliz.com>
@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.79%. Comparing base (5147d51) to head (d226f92).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3295   +/-   ##
=======================================
  Coverage   76.79%   76.79%           
=======================================
  Files          63       63           
  Lines       13236    13236           
=======================================
  Hits        10164    10164           
  Misses       3072     3072           

☔ 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.

@mergify mergify bot added the ci-passed label Feb 26, 2026
@zhuwenxing
Copy link
Contributor Author

/assign @weiliu1031
/assign @tedxu

@XuanYang-cn
Copy link
Contributor

I think two db_names might not work in Milvus, the API in pymilvus is explicitly designed to omit db_name to reduce the complexity, that all(at least majority) API doesn't need db_name.

@XuanYang-cn
Copy link
Contributor

This is a good catch though, APIs are not aligned with each other on how to pass in db_name. For now, we tends to set the db_name in interceptors only.

@XuanYang-cn
Copy link
Contributor

/hold

@XuanYang-cn
Copy link
Contributor

snapshot will be bind with collection_name and the API will be redesigned soon. Let's make db_name in PyMIlvus consists with other APIs.

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