-
Notifications
You must be signed in to change notification settings - Fork 90
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
PBM-1329 Write to temporary file name and sync before renaming #954
Conversation
hi @DanielOliverRJ. thank you for your contributions. Could you please try to review/sign the CLA again so we can proceed? |
Sorry, I had to get the CLA text approved before I could sign. This is now completed. |
Thank you for your contribution. I see one problem here: percona-backup-mongodb/pbm/storage/fs/fs.go Lines 70 to 101 in fd2c57a
Please ensure that the temporary file is deleted in case of an error before the function exists. Thus, the caller code may remain unaware of the implementation details specific to file system storage. |
I've re-factored slightly to move write to a common function and attempt to remove the temporary file on any error. |
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.
tested by debugging
Whilst trying to understand historic cases where we have seen BSON deserialisation errors, I realised it was possible for filesystem writes to be incomplete, but be unable to determine the fact. In particular, once an oplog file exists on the filesystem, it is assumed to be complete even though the write may have been interrupted.
This change performs all filesystem writes to a temporary file in the same directory and does a rename once the sync has returned.
In the event of a failure, calling Close() on the same file handle does not cause an error because the deferred call discards the error.
I do not believe non-filesystem storage are affected by this problem, as the providers have other checks in place to ensure the upload completed.