Skip to content
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

Task AB#1310795: [LevelDB] Fixing an issue where a carriage return in the CURRENT file would consider our files as corrupted. #8

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,17 @@ Status VersionSet::Recover(bool* save_manifest) {
if (!s.ok()) {
return s;
}
if (current.empty() || current[current.size() - 1] != '\n') {
const size_t size = current.size();
if (size == 0 || (current[size - 1] != '\n' && current[size - 1] != '\r')) {

Choose a reason for hiding this comment

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

Change looks fine as is but I wonder when do we have this condition (file ending with \r only not with the combination \r\n) ... wasn't this condition a side effect of not having the change below? (as in the first time we call recover it goes and clears the \n but not the \r and now the file is all weird).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Doesn't seem like the current.resize(current.size() - 1); causes this problem since current is just a string that gets reinitialized each time Recover is called. Removing the /n in current (for posix devices) on the first run shouldn't cause the next value of current after Recover is called again to be messed up since it's reinitialized with ReadFileToString. Seems like value of current is only adjusted for setting dscname. Not why file would be ending with \r, but this fix seems to have fixed whatever was causing it, but the original author of this commit was unable to remember the specifics.

return Status::Corruption("CURRENT file does not end with newline");
}
current.resize(current.size() - 1);

int resizeSize = 1;
if (size >= 2 && current[size - 2] == '\r') {
resizeSize = 2;
}

current.resize(size - resizeSize);

std::string dscname = dbname_ + "/" + current;
SequentialFile* file;
Expand Down
Loading