-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Don't open a raft snapshot file until we have a successful snapshot response. #9894
Conversation
} | ||
defer snapFile.Close() | ||
defer w.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.
I know this was in the original code, but isn't this a case where we really should be checking the result of the Close
call?
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.
Sure? It makes the code a little uglier but what the heck.
|
||
type lazyOpenWriter struct { | ||
openFunc func() (io.WriteCloser, error) | ||
writer io.WriteCloser |
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.
It makes me a little uncomfortable that this isn't thread/data-race safe, but it looks like it won't break anything in the existing Sys.RaftSnapshot implementation.
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.
Yeah, my thought was this local, unexportable writer is only used in the one case. If it were reusable I'd stick a mutex in it.
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.
Approved, but note Brian's new comment in the jira, which may require more work.
Looks good! |
…esponse. (#9894) * Don't open the snapshot file until we have a successful response * Check the success of Close if nothing else errors
Implement a lazy writer which only opens the file once data starts being
written to it, e.g. the snapshot request has succeeded. This will prevent
opening 0 byte files or clobbering existing files on error.