-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: hello command not return information of pika version #2989
base: unstable
Are you sure you want to change the base?
fix: hello command not return information of pika version #2989
Conversation
WalkthroughThe pull request modifies the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/pika_admin.cc (2)
3390-3392
: Consider storing the version string once, rather than declaring and formatting multiple times.
Currently, the version string is formatted here and then reformatted at line 3398 with the same data. Eliminating repetition could make the code more maintainable and less error-prone.
3398-3398
: Avoid redundant version formatting.
This line repeats the exactsnprintf
call performed at line 3391. Refactor to reuse the previously assigned version string to avoid potential inconsistencies and duplication.// Remove the repeated snprintf if version is already set - snprintf(version, sizeof(version), "%d.%d.%d", PIKA_MAJOR, PIKA_MINOR, PIKA_PATCH);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/pika_admin.cc
(1 hunks)
🔇 Additional comments (1)
src/pika_admin.cc (1)
3395-3395
: Good addition of the "version" field to the HELLO response.
Including the version information fulfills the PR's objective and helps clients identify Pika's version.
b236d72
to
eb476ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
src/pika_admin.cc (1)
Line range hint
3408-3419
: Improve error handling for unknown roles.The default case for role handling only logs the error but continues execution. Consider returning an error response to the client.
default: LOG(INFO) << "unknown role" << host_role << " client ip:port " << conn->ip_port(); - return; + res_.SetRes(CmdRes::kErrOther, "Internal error: unknown server role"); + return;
🧹 Nitpick comments (5)
src/pika_admin.cc (5)
3390-3392
: Consider using a version constant or config value.The version string is constructed using hardcoded version numbers. Consider using version constants or configuration values for better maintainability.
- snprintf(version, sizeof(version), "%d.%d.%d", PIKA_MAJOR, PIKA_MINOR, PIKA_PATCH); + const std::string version = GetVersionString(); // Use a helper function that reads from constants/config
3395-3396
: Fix indentation for consistency.The field-value pairs have inconsistent indentation.
std::vector<storage::FieldValue> fvs{ {"server", "redis"}, - {"version", version} + {"version", version} };
Line range hint
3475-3481
: Add unit documentation for disk space check.The disk space comparison uses bytes but the error message doesn't specify units. Consider adding unit information for clarity.
uint64_t free_size = disk_info.f_bsize * disk_info.f_bfree; if (free_size < least_free_size) { - res_.SetRes(CmdRes::kErrOther, "The available disk capacity is insufficient"); + res_.SetRes(CmdRes::kErrOther, + "The available disk capacity is insufficient. Required: " + + std::to_string(least_free_size/1024/1024) + "MB, Available: " + + std::to_string(free_size/1024/1024) + "MB"); return; }
Line range hint
3482-3499
: Consider refactoring background error handling for better readability.The background error handling logic could be extracted into a separate method for better readability and reusability.
+ bool HandleBackgroundErrors(const std::shared_ptr<DB>& db) { + std::map<int, uint64_t> background_errors; + db->DBLockShared(); + db->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_BACKGROUND_ERRORS, &background_errors); + db->DBUnlockShared(); + + for (const auto& item : background_errors) { + if (item.second != 0) { + rocksdb::Status s = db->storage()->GetDBByIndex(item.first)->Resume(); + if (!s.ok()) { + return false; + } + } + } + return true; + } // In Do() method: for (const auto& db_item : g_pika_server->GetDB()) { if (!db_item.second) { continue; } db_item.second->SetBinlogIoErrorrelieve(); - background_errors_.clear(); - db_item.second->DBLockShared(); - db_item.second->storage()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_BACKGROUND_ERRORS, &background_errors_); - db_item.second->DBUnlockShared(); - for (const auto& item : background_errors_) { - if (item.second != 0) { - rocksdb::Status s = db_item.second->storage()->GetDBByIndex(item.first)->Resume(); - if (!s.ok()) { - res_.SetRes(CmdRes::kErrOther, "The restore operation failed."); - } - } - } + if (!HandleBackgroundErrors(db_item.second)) { + res_.SetRes(CmdRes::kErrOther, "The restore operation failed for DB: " + db_item.first); + return; + } }
Line range hint
3644-3677
: Improve error handling and messages in CacheCmd.The error handling could be improved with more specific error messages and better default case handling.
switch (condition_) { case kCLEAR_DB: g_pika_server->ClearCacheDbAsync(db_); res_.SetRes(CmdRes::kOk); break; case kCLEAR_HITRATIO: g_pika_server->ClearHitRatio(db_); res_.SetRes(CmdRes::kOk); break; case kDEL_KEYS: db_->cache()->Del(keys_); res_.SetRes(CmdRes::kOk); break; case kRANDOM_KEY: s_ = db_->cache()->RandomKey(&key); if (!s_.ok()) { - res_.AppendStringLen(-1); + res_.SetRes(CmdRes::kErrOther, "Failed to get random key: " + s_.ToString()); } else { res_.AppendStringLen(key.size()); res_.AppendContent(key); } break; default: - res_.SetRes(CmdRes::kErrOther, "Unknown cmd"); + res_.SetRes(CmdRes::kErrOther, "Unknown cache operation"); break; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/pika_admin.cc
(1 hunks)
🔇 Additional comments (1)
src/pika_admin.cc (1)
Line range hint
3678-4037
: LGTM! Well-structured command documentation implementation.The CommandCmd implementation shows good:
- Separation of concerns with different encodable types
- Error handling for unknown commands
- Proper command documentation structure
fix #2957 spring boot 3.x 连接pika报错 Version must not be null
hello cmmand 输出增加pika verison信息,避免某些连接需要读取verison信息,但是pika没有输出所导致的错误。
输出由:
变更为:
Summary by CodeRabbit