Skip to content

remote redis dependency#2109

Open
jinke446 wants to merge 1 commit into
kvcache-ai:mainfrom
jinke446:remove_redis_depend
Open

remote redis dependency#2109
jinke446 wants to merge 1 commit into
kvcache-ai:mainfrom
jinke446:remove_redis_depend

Conversation

@jinke446
Copy link
Copy Markdown
Contributor

@jinke446 jinke446 commented May 15, 2026

Description

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake EP (mooncake-ep)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • PyTorch Backend (mooncake-pg)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Other

How Has This Been Tested?

Checklist

  • I have performed a self-review of my own code.
  • I have formatted my own code using ./scripts/code_format.sh before submitting.
  • I have updated the documentation.
  • I have added tests to prove my changes are effective.

Copy link
Copy Markdown
Contributor

@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 refactors the handling of Redis configuration by moving the retrieval of credentials and database indices from the transfer engine's initialization logic directly into the MetaStore factory. It removes several overloaded constructors and configuration parameters in favor of environment variables (MC_REDIS_PASSWORD, MC_REDIS_USERNAME, and MC_REDIS_DB_INDEX). Feedback was provided regarding the new environment variable parsing logic in metastore.cpp, specifically pointing out incorrect defaulting behavior for the database index, contradictory error handling where the code returns a null pointer despite logging a fallback to a default value, and general redundancy in the implementation.

Comment on lines +55 to +77
int redis_db_index_config = 0;
const char* env_db_index = std::getenv("MC_REDIS_DB_INDEX");
if (env_db_index && *env_db_index) {
try {
redis_db_index_config = std::stoi(env_db_index);
} catch (const std::exception& e) {
LOG(WARNING) << "Invalid REDIS_DB_INDEX environment variable: "
<< env_db_index;
return nullptr;
}
}

// Validate redis_db_index range (0-255)
uint8_t db_index = REDIS_DEFAULT_DB_INDEX;
if (redis_db_index_config >= 0 &&
redis_db_index_config <= REDIS_MAX_DB_INDEX) {
db_index = static_cast<uint8_t>(redis_db_index_config);
} else {
LOG(WARNING) << "Invalid Redis DB index: " << redis_db_index_config
<< ", using default "
<< static_cast<int>(REDIS_DEFAULT_DB_INDEX);
return nullptr;
}
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.

high

The logic for processing MC_REDIS_DB_INDEX has several issues:

  1. Incorrect Defaulting: redis_db_index_config is initialized to 0 (line 55). If the environment variable is missing, the range check (lines 69-71) will succeed (since 0 is a valid index), and db_index will be set to 0, potentially overwriting REDIS_DEFAULT_DB_INDEX if it is non-zero.
  2. Contradictory Error Handling: The log message in the else block (lines 73-75) claims that the default value will be used, but the function then returns nullptr (line 76), which will trigger a fatal error later in the execution flow.
  3. Redundancy: The logic can be simplified by directly parsing the environment variable into the target variable with proper validation.
        uint8_t db_index = REDIS_DEFAULT_DB_INDEX;
        const char* env_db_index = std::getenv("MC_REDIS_DB_INDEX");
        if (env_db_index && *env_db_index) {
            try {
                int val = std::stoi(env_db_index);
                if (val >= 0 && val <= REDIS_MAX_DB_INDEX) {
                    db_index = static_cast<uint8_t>(val);
                } else {
                    LOG(WARNING) << "Redis DB index out of range: " << val;
                    return nullptr;
                }
            } catch (const std::exception& e) {
                LOG(WARNING) << "Invalid REDIS_DB_INDEX environment variable: " << env_db_index;
                return nullptr;
            }
        }

@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!

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.

2 participants