-
Notifications
You must be signed in to change notification settings - Fork 518
fix: recovery from crash during optimization #246
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
Open
zhourrr
wants to merge
5
commits into
main
Choose a base branch
from
feat/more_ut
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,106 @@ | ||||||
| // Copyright 2025-present the zvec project | ||||||
| // | ||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| // you may not use this file except in compliance with the License. | ||||||
| // You may obtain a copy of the License at | ||||||
| // | ||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| // | ||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| // See the License for the specific language governing permissions and | ||||||
| // limitations under the License. | ||||||
|
|
||||||
|
|
||||||
| #include <unistd.h> | ||||||
| #include <filesystem> | ||||||
| #include <zvec/db/collection.h> | ||||||
| #include <zvec/db/options.h> | ||||||
| #include "zvec/ailego/logger/logger.h" | ||||||
|
|
||||||
|
|
||||||
| struct Config { | ||||||
| std::string path; | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
| bool ParseArgs(int argc, char **argv, Config &config) { | ||||||
| for (int i = 1; i < argc; i++) { | ||||||
| std::string arg = argv[i]; | ||||||
|
|
||||||
| if (arg == "--path" && i + 1 < argc) { | ||||||
| config.path = argv[++i]; | ||||||
| } else if (arg == "--help" || arg == "-h") { | ||||||
| return false; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Validate required arguments | ||||||
| if (config.path.empty()) { | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| void PrintUsage(const char *program) { | ||||||
| std::cout << "Usage: " << program << " --path <collection_path>" << std::endl; | ||||||
| std::cout << std::endl; | ||||||
| std::cout << "Arguments:" << std::endl; | ||||||
| std::cout << " --path Path to the collection (required)" | ||||||
| << std::endl; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| int main(int argc, char **argv) { | ||||||
| Config config; | ||||||
|
|
||||||
| // Parse arguments | ||||||
| if (!ParseArgs(argc, argv, config)) { | ||||||
| PrintUsage(argv[0]); | ||||||
| return 1; | ||||||
| } | ||||||
|
|
||||||
| try { | ||||||
| std::filesystem::path cwd = std::filesystem::current_path(); | ||||||
| std::cout << "[collection_optimizer] Current Working Directory: " | ||||||
| << cwd.string() << std::endl; | ||||||
| } catch (const std::filesystem::filesystem_error &e) { | ||||||
| std::cout << "[collection_optimizer] Failed to get the current working " | ||||||
| "directory: " | ||||||
| << e.what() << std::endl; | ||||||
| } | ||||||
|
|
||||||
| std::cout << "Configuration:" << std::endl; | ||||||
| std::cout << " Path: " << config.path << std::endl; | ||||||
| std::cout << std::endl; | ||||||
|
|
||||||
| auto result = | ||||||
| zvec::Collection::Open(config.path, zvec::CollectionOptions{false, true}); | ||||||
| if (!result) { | ||||||
| LOG_ERROR("Failed to open collection[%s]: %s", config.path.c_str(), | ||||||
| result.error().c_str()); | ||||||
| return -1; | ||||||
| } | ||||||
|
|
||||||
| auto collection = result.value(); | ||||||
| std::cout << "Collection[" << config.path.c_str() << "] opened successfully" | ||||||
| << std::endl; | ||||||
|
|
||||||
| // Print initial stats | ||||||
| std::cout << "Initial stats: " << collection->Stats()->to_string_formatted() | ||||||
| << std::endl; | ||||||
|
|
||||||
| auto s = collection->Optimize(); | ||||||
| if (s.ok()) { | ||||||
| std::cout << "Optimize completed successfully" << std::endl; | ||||||
| // Print final stats | ||||||
| std::cout << "Final stats: " << collection->Stats()->to_string_formatted(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The final stats line has no
Suggested change
|
||||||
| return 0; | ||||||
| } else { | ||||||
| std::cout << "Optimize failed: " << s.message() << std::endl; | ||||||
| return 1; | ||||||
| } | ||||||
| } | ||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
CollectionOptionsmismatch with test configurationThe test file
optimize_recovery_test.cccreates and reopens the collection withzvec::CollectionOptions{false, true, 256 * 1024}(a max-doc-per-segment limit of256 * 1024), but thecollection_optimizerbinary opens the same on-disk collection with onlyzvec::CollectionOptions{false, true}(no segment size limit). This mismatch means the optimizer may behave differently than expected during the crash recovery test — for example, it might not trigger segment compaction at the same thresholds, leading to a test that doesn't actually exercise the intended code paths.