-
Notifications
You must be signed in to change notification settings - Fork 242
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
Improve AtomicFileWriter's support for Win and Mac #1554
Conversation
b52978b
to
f6b6560
Compare
Add ExplicitCommit option to provide calling code the ability to preserve original files when an application error occurs, not just an error that occurs during writing. Change Close() impl to safely handle redundant calls (for defer usage safety) Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
f6b6560
to
21ec71c
Compare
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.
// to the destination. This allows an application to preserve the original | ||
// file when an error occurs during processing (and not just during write) | ||
// The default is false, which will auto-commit on Close | ||
ExplicitCommit bool |
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.
I think I'm missing a point and wonder why ExplicitCommit
and Commit()
are needed. I somehow expected changes to Close()
only. @n1hility, can you elaborate on that?
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.
I think the point is that there is no way to abort this operation.
As shown in the example in the PR description when the encoder returns an error which was not caused by the Write() call, the encoder returns early and we can have a corrupted file once Close() is called. The only way to prevent this would be to not call Close() but this would then leak fds instead and would never allow the use of defer somefile.Close()
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, makes sense 👍
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.
Great summary, I couldn't have said it better. I would have preferred to make a hard move and make this commit() approach the only option instead of a flag like in my PR, since the previous auto-commit behavior is likely to cause problems in most usage patterns. However, it would be compatibility breaking, and I wasnt sure how much usage of this API there is in the wild.
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.
I think that's a great way of keeping the API stable, @n1hility. Thanks!
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.
LGTM
LGTM |
Updates to containers/storage@main (contains a required fswriters PR: containers/storage#1554) Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
Updates to containers/storage@main (contains a required fswriters PR: containers/storage#1554) Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
Updates to containers/storage@main (contains a required fswriters PR: containers/storage#1554) [NO NEW TESTS NEEDED] Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
As discussed on containers/common#1397, this PR is a step towards addressing corruption issues with container and machine configuration files that can occur with an improper shutdown.
Add ExplicitCommit option to provide calling code the ability to preserve original files when an application error occurs, not just an error that occurs during writing (e.g. a marshaller failure)
Change Close() impl to safely handle redundant calls (for defer usage safety)
Introduces two flush points, one just after data is written that supports the previous code's Linux approach of using fdatasync(), and another for Mac/Win/Non-Linux Unix that needs to full flush after metadata updates are staged.
Using this patch, common's usage for writting the container config file would look like this: