Skip to content

add script for metadata management - #1746

Merged
stmatengss merged 3 commits into
mainfrom
v0310_dev
Mar 26, 2026
Merged

add script for metadata management#1746
stmatengss merged 3 commits into
mainfrom
v0310_dev

Conversation

@whybeyoung

Copy link
Copy Markdown
Collaborator

Summary

  • Added mc_meta_cli.py as a Mooncake metadata client management utility to centralize key-management operations.
  • Supports key query, single-key deletion, and remove-all, with RPC-first behavior (rpc_only) by default to avoid hard dependency on the HTTP metadata service.
  • Improved operational usability with a default RPC endpoint, clearer CLI flags, and a usage guide in the script header.

Why

  • Simplifies day-to-day troubleshooting and maintenance by replacing ad-hoc key operations with a single reliable CLI.
  • Reduces failures caused by mixed RPC/HTTP paths and environment differences, improving safety and consistency for metadata operations.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 delivers a dedicated command-line interface to streamline Mooncake metadata management. It consolidates various key operations into a single, reliable tool, enhancing the safety and consistency of metadata interactions by prioritizing RPC-based methods and providing a more user-friendly experience for administrators.

Highlights

  • New Metadata Management Utility: Introduced mc_meta_cli.py, a new command-line interface for managing Mooncake metadata, centralizing key-management operations.
  • Key Operations Supported: The utility supports querying individual keys via HTTP, deleting single keys via RPC, and performing a 'remove-all' operation for all keys via RPC.
  • RPC-First Design: The tool defaults to an RPC-first behavior (rpc_only) for deletion operations, aiming to reduce dependencies on the HTTP metadata service and improve operational consistency.
  • Enhanced Usability: The script includes a usage guide in its header, clearer CLI flags, and a default RPC endpoint, simplifying day-to-day troubleshooting and maintenance.

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

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.

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

Copy link
Copy Markdown
Contributor

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 introduces a new Python CLI tool, mc_meta_cli.py, designed to interact with Mooncake metadata. The tool supports listing all keys from a master HTTP debug API, querying specific keys via an HTTP metadata server, and deleting single or all keys using RPC. The review feedback suggests several improvements, including changing the HTTP response decoding error handling from ignore to replace for better data visibility, returning actual boolean values instead of string literals from query_key_by_http, enhancing type hints for the setup_store function, refactoring magic numbers for buffer sizes into module-level constants for improved maintainability, and making the default master server address more portable by using localhost.

req = urllib.request.Request(url, method="GET")
try:
with urllib.request.urlopen(req, timeout=timeout) as resp:
text = resp.read().decode("utf-8", errors="ignore")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using errors="ignore" during decoding can silently drop malformed characters, potentially hiding issues with the data source. For a CLI tool that displays data, it's often better to use errors="replace" to make it clear that some data was corrupted, without crashing the script.

Suggested change
text = resp.read().decode("utf-8", errors="ignore")
text = resp.read().decode("utf-8", errors="replace")

Comment thread scripts/management/mc_meta_cli.py Outdated
) from exc


def setup_store(args: argparse.Namespace) -> Any:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The return type of this function is Any, which is not very specific. For better type safety and readability, you can use a TYPE_CHECKING block to import MooncakeDistributedStore for type hinting. This avoids runtime import issues while providing static type checkers with the necessary information.

  1. Add the following at the top of the file with other imports:
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mooncake.store import MooncakeDistributedStore
  1. Then, change this function's signature to use the specific type:
Suggested change
def setup_store(args: argparse.Namespace) -> Any:
def setup_store(args: argparse.Namespace) -> "MooncakeDistributedStore":

Comment on lines +127 to +129
if args.local_buffer_size == 128 * 1024 * 1024:
args.local_buffer_size = 0
if args.global_segment_size == 512 * 1024 * 1024:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

These magic numbers for buffer sizes are also used as defaults in build_parser. To avoid duplication and improve maintainability, you should define them as constants at the module level and use them in both places. This will prevent potential bugs if the default values are changed in one place but not the other.

For example, you could add this at the top of your file:

# Constants for memory sizes
MIB = 1024 * 1024
DEFAULT_LOCAL_BUFFER_SIZE = 128 * MIB
DEFAULT_GLOBAL_SEGMENT_SIZE = 512 * MIB
Suggested change
if args.local_buffer_size == 128 * 1024 * 1024:
args.local_buffer_size = 0
if args.global_segment_size == 512 * 1024 * 1024:
if args.local_buffer_size == DEFAULT_LOCAL_BUFFER_SIZE:
args.local_buffer_size = 0
if args.global_segment_size == DEFAULT_GLOBAL_SEGMENT_SIZE:

Comment thread scripts/management/mc_meta_cli.py Outdated
Comment on lines +183 to +192
"--global-segment-size",
type=int,
default=512 * 1024 * 1024,
help="store.setup global_segment_size for RPC delete.",
)
parser.add_argument(
"--local-buffer-size",
type=int,
default=128 * 1024 * 1024,
help="store.setup local_buffer_size for RPC delete.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To complement the change in tune_rpc_only_memory, use the newly defined constants for the default values here. This improves readability and ensures consistency.

    parser.add_argument(
        "--global-segment-size",
        type=int,
        default=DEFAULT_GLOBAL_SEGMENT_SIZE,
        help="store.setup global_segment_size for RPC delete.",
    )
    parser.add_argument(
        "--local-buffer-size",
        type=int,
        default=DEFAULT_LOCAL_BUFFER_SIZE,
        help="store.setup local_buffer_size for RPC delete.",
    )

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@alogfans
alogfans requested a review from ykwd March 26, 2026 01:39
stmatengss and others added 2 commits March 26, 2026 13:16
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@stmatengss
stmatengss merged commit fad70b9 into main Mar 26, 2026
14 of 15 checks passed
whn09 pushed a commit to whn09/Mooncake that referenced this pull request Apr 4, 2026
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@zhyncs
zhyncs deleted the v0310_dev branch April 30, 2026 08:36
A-Liuhao pushed a commit to A-Liuhao/Mooncake that referenced this pull request Jun 25, 2026
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants