-
Notifications
You must be signed in to change notification settings - Fork 66
PSMDB-810 improve logging #695
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
base: v4.2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1491,6 +1491,8 @@ static void copy_file_size(const boost::filesystem::path& srcFile, const boost:: | |||||||||||||||
| dst.write(bufptr, cnt); | ||||||||||||||||
| fsize -= cnt; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| dst.close(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| Status WiredTigerKVEngine::_hotBackupPopulateLists(OperationContext* opCtx, const std::string& path, std::vector<DBTuple>& dbList, std::vector<FileTuple>& filesList) { | ||||||||||||||||
|
|
@@ -2062,11 +2064,20 @@ Status WiredTigerKVEngine::hotBackup(OperationContext* opCtx, const std::string& | |||||||||||||||
| std::set<fs::path> existDirs{destPath}; | ||||||||||||||||
|
|
||||||||||||||||
| // Do copy files | ||||||||||||||||
| int fcCtr = 0; | ||||||||||||||||
| for (auto&& file : filesList) { | ||||||||||||||||
| fs::path srcFile{std::get<0>(file)}; | ||||||||||||||||
| fs::path destFile{std::get<1>(file)}; | ||||||||||||||||
| auto fsize{std::get<2>(file)}; | ||||||||||||||||
|
|
||||||||||||||||
| log() << "Beginning copy of {}/{} files in backup snapshot: {}, {} bytes"_format( | ||||||||||||||||
| ++fcCtr, filesList.size(), srcFile.string(), fsize); | ||||||||||||||||
|
||||||||||||||||
| ++fcCtr, filesList.size(), srcFile.string(), fsize); | |
| LOG(1) << "Beginning copy of " << (fcCtr + 1) << "/" << filesList.size() | |
| << " files in backup snapshot: " << srcFile.string() << ", " << fsize << " bytes"; | |
| if ((fcCtr % 100 == 0) || (fcCtr + 1 == filesList.size())) { | |
| log() << "Backup progress: copying file " << (fcCtr + 1) << " of " << filesList.size(); | |
| } | |
| ++fcCtr; |
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.
Can you focus on improving log messages so they are more user / support friendly?
Copilot
AI
Aug 19, 2025
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.
The fs::file_size() call can throw an exception if the file doesn't exist or there are permission issues, but it's not wrapped in a try-catch block. This could cause the backup operation to fail unexpectedly. Consider wrapping this call in a try-catch block or checking file existence first.
| log() << "Source file size is: {} bytes"_format(fs::file_size(srcFile)); | |
| try { | |
| log() << "Source file size is: {} bytes"_format(fs::file_size(srcFile)); | |
| } catch (const fs::filesystem_error& ex) { | |
| log() << "Could not get source file size for '{}': {}"_format(srcFile.string(), ex.what()); | |
| } |
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.
| } else { | |
| log() << "Source file size is: {} bytes"_format(fs::file_size(srcFile)); | |
| } | |
| } | |
Truncating the byte size log line from here because the preceding edit suggestion would include it there.
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.
My idea was to show current size of the file. It may be different from the size reported in another message (that size is captured when file list is generated)
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.
Thanks for catching the fcCtr increment bug.
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.
Regarding showing the size of the file it is true, it might become notably bigger during the backup. And that is so interesting to DBAs worried about file size growth that I first drafted an edit where it would warn() (not log) if the file size had grown (> +10% && > +100MB).
I don't think it's helpful for users to just be informed what the size is if it is not the same size as what is copied. I think they will see it as an error and report it.
But then I discarded that draft because the $backupCursor work will probably require us doing this all again, didn't seem worthwhile now.
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.
The dst.close() call is redundant and potentially problematic. The ofstream destructor will automatically close the file when the function exits, and calling close() explicitly here could mask exceptions that occur during the write operations since close() is called outside the try-catch block that handles the file operations.