[Store]: Adapted for snapshot functionality and added testing.#1337
Conversation
- Support DISK and LOCAL_DISK replica types in snapshot/restore - Add allocator_names to preserve allocator ordering - Add client_local_disk_segment_ snapshot/restore support - Add client_by_name_ reconstruction on restore
- Add test base class for snapshot/restore verification - Port tests from master_service_test.cpp for snapshot/restore verification - Port tests from master_service_ssd_test.cpp for SSD snapshot/restore verification - Sort unordered_map keys before serialization for deterministic snapshots
Summary of ChangesHello @yangdao479, 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 significantly upgrades the MasterService's snapshot and restore capabilities by introducing an extensible storage backend abstraction. It resolves existing issues, adds crucial configuration options, and establishes a robust testing methodology to guarantee the reliability of state persistence and recovery for the Mooncake Store. Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request significantly enhances the snapshot and restore functionality by abstracting the storage backend, which is a great step towards supporting different storage systems like S3. The introduction of a local file backend and the associated tests are well-implemented. I particularly appreciate the critical fixes for deterministic serialization by sorting keys in unordered maps before processing; this is crucial for snapshot consistency and debuggability. The overall changes are of high quality and the testing strategy is comprehensive. I have a couple of suggestions to further improve robustness and performance.
| inline SnapshotBackendType ParseSnapshotBackendType(const std::string& type_str) { | ||
| #ifdef HAVE_AWS_SDK | ||
| if (type_str == "s3" || type_str == "S3") { | ||
| return SnapshotBackendType::S3; | ||
| } | ||
| #else | ||
| if (type_str == "s3" || type_str == "S3") { | ||
| throw std::invalid_argument( | ||
| "S3 backend requested but AWS SDK is not available. " | ||
| "Please rebuild with HAVE_AWS_SDK or use 'local' backend."); | ||
| } | ||
| #endif | ||
| return SnapshotBackendType::LOCAL_FILE; // Default to local file | ||
| } |
There was a problem hiding this comment.
The current implementation of ParseSnapshotBackendType is a bit too permissive. Any value other than "s3" or "S3" will default to LOCAL_FILE, which could hide configuration typos (e.g., "s4"). It's better to be stricter and explicitly handle known values, throwing an exception for any unknown type to prevent silent failures. The suggestion below allows an empty string to default to LOCAL_FILE for robustness, but will fail loudly for other invalid inputs.
inline SnapshotBackendType ParseSnapshotBackendType(const std::string& type_str) {
#ifdef HAVE_AWS_SDK
if (type_str == "s3" || type_str == "S3") {
return SnapshotBackendType::S3;
}
#else
if (type_str == "s3" || type_str == "S3") {
throw std::invalid_argument(
"S3 backend requested but AWS SDK is not available. "
"Please rebuild with HAVE_AWS_SDK or use 'local' backend.");
}
#endif
if (!type_str.empty() && type_str != "local" && type_str != "LOCAL") {
throw std::invalid_argument("Invalid snapshot backend type: '" + type_str + "'. Supported types are 'local' and 's3'.");
}
return SnapshotBackendType::LOCAL_FILE; // Default to local file for "local" or empty string
}| for (const auto& name : saved_allocator_names) { | ||
| for (auto& pair : segment_manager_->mounted_segments_) { | ||
| MountedSegment& mounted_segment = pair.second; | ||
| if (mounted_segment.status == SegmentStatus::OK && | ||
| if (mounted_segment.segment.name == name && | ||
| mounted_segment.status == SegmentStatus::OK && | ||
| mounted_segment.buf_allocator) { | ||
| // 添加到allocator_manager_ | ||
| segment_manager_->allocator_manager_.addAllocator( | ||
| mounted_segment.segment.name, mounted_segment.buf_allocator); | ||
| name, mounted_segment.buf_allocator); | ||
| break; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This nested loop for restoring allocators has a time complexity of O(N*M), where N is the number of saved allocator names and M is the number of mounted segments. This could be inefficient if there are many segments. You can optimize this by first creating a map from segment name to MountedSegment for an efficient O(1) lookup inside the loop, which would bring the total complexity down to O(N+M).
// Build a map from segment name to MountedSegment for efficient lookup.
std::unordered_map<std::string, MountedSegment*> name_to_segment;
for (auto& pair : segment_manager_->mounted_segments_) {
name_to_segment[pair.second.segment.name] = &pair.second;
}
// 按保存的原始顺序添加 allocator
for (const auto& name : saved_allocator_names) {
auto it = name_to_segment.find(name);
if (it != name_to_segment.end()) {
MountedSegment* mounted_segment = it->second;
if (mounted_segment->status == SegmentStatus::OK && mounted_segment->buf_allocator) {
segment_manager_->allocator_manager_.addAllocator(
name, mounted_segment->buf_allocator);
}
}
}|
|
||
| tl::expected<void, SerializationError> Serializer<Replica>::serialize( | ||
| const Replica &replica, const SegmentView &segment_view, MsgpackPacker &packer) { | ||
| // 统一使用数组结构打包Replica |
Description
This PR enhances the snapshot/restore functionality for MasterService and adds tests.
Type of Change
How Has This Been Tested?
Checklist