Skip to content

Conversation

@jac0626
Copy link
Collaborator

@jac0626 jac0626 commented Jan 9, 2026

  • Global Singleton: Replaced instance-level caches with a thread-safe GlobalSchemaCache
  • Key Isolation: Added {endpoint}/{db}/{collection} keying for multi-cluster/multi-db support.
  • LRU Eviction: Implemented LRU logic with a 4096 capacity.
  • Efficiency: Reduced redundant describe_collection calls across client instances.
  • Verified: 96 tests passed (including 13 new cache tests).
    see [Bug]: Implement Global Thread-Safe Schema Cache with Eviction Policy #3186

@sre-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jac0626
To complete the pull request process, please assign czs007 after the PR has been reviewed.
You can assign the PR to them by writing /assign @czs007 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

@gemini-code-assist
Copy link

Summary of Changes

Hello @jac0626, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a fundamental refactoring of the schema caching mechanism within the pymilvus gRPC handlers. By transitioning from localized, instance-bound caches to a global, thread-safe, and LRU-managed schema cache, the change aims to enhance the client's efficiency and scalability. This centralized approach prevents repetitive schema fetches, particularly beneficial in multi-threaded or multi-client environments, while also providing clear isolation for different Milvus instances and databases.

Highlights

  • Global Singleton Cache: Replaced instance-level schema caches in gRPC handlers with a single, thread-safe GlobalSchemaCache.
  • Multi-Tenant Keying: Implemented a robust keying strategy ({endpoint}/{db}/{collection}) to ensure proper isolation and support for multiple Milvus clusters and databases.
  • LRU Eviction: Integrated an LRU (Least Recently Used) eviction policy with a capacity of 4096 entries to manage cache size efficiently.
  • Efficiency Improvement: Significantly reduced redundant describe_collection calls across client instances, leading to improved performance.
  • Comprehensive Testing: Added 13 new dedicated tests for the caching mechanism, contributing to a total of 96 passing tests.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mergify mergify bot added the needs-dco label Jan 9, 2026
@jac0626 jac0626 force-pushed the feature/global-schema-cache branch from 8ca419f to b531314 Compare January 9, 2026 10:02
@mergify mergify bot added dco-passed and removed needs-dco labels Jan 9, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively refactors the schema caching mechanism by introducing a thread-safe, global LRU cache. This is a significant improvement that will reduce redundant describe_collection calls and enhance efficiency. The implementation of the GlobalSchemaCache singleton is solid, and the accompanying tests are comprehensive. I've provided a few suggestions to further refine the implementation for better performance and readability, such as using a more appropriate lock and simplifying some of the cache interaction patterns.

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 85.13514% with 11 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@5d377b2). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pymilvus/client/async_grpc_handler.py 15.38% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3188   +/-   ##
=========================================
  Coverage          ?   46.95%           
=========================================
  Files             ?       69           
  Lines             ?    14860           
  Branches          ?        0           
=========================================
  Hits              ?     6977           
  Misses            ?     7883           
  Partials          ?        0           

☔ 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 Jan 9, 2026
Signed-off-by: silas.jiang <[email protected]>
@jac0626 jac0626 force-pushed the feature/global-schema-cache branch from c8fde69 to f65061f Compare January 9, 2026 10:13
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.

I think a popular library cachetools can help alot.

Signed-off-by: silas.jiang <[email protected]>
@jac0626
Copy link
Collaborator Author

jac0626 commented Jan 12, 2026

I think a popular library cachetools can help alot.

cachetools

done

pyproject.toml Outdated
"pandas>=1.2.4",
"numpy<1.25.0;python_version<='3.8'",
"cachetools>=5.0.0,<6.0.0;python_version<='3.8'", # Python 3.8 compatibility
"cachetools>=5.0.0;python_version>='3.9'", # Python 3.9+ can use latest
Copy link
Contributor

Choose a reason for hiding this comment

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

The second is redundent, see numpy for reference.

I think the first might be unnecessary too, because packages often maintain supported python ranges, and pip should be able to resolve it to the correct highest-version for python3.8.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Signed-off-by: silas.jiang <[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.

3 participants