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

Don't open a raft snapshot file until we have a successful snapshot response. #9894

Merged
merged 4 commits into from
Sep 14, 2020

Conversation

sgmiller
Copy link
Collaborator

@sgmiller sgmiller commented Sep 4, 2020

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.

}
defer snapFile.Close()
defer w.Close()
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

@ncabatoff ncabatoff left a 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.

@ncabatoff
Copy link
Collaborator

Looks good!

@sgmiller sgmiller merged commit 31fbd77 into master Sep 14, 2020
@sgmiller sgmiller deleted the raft-snapshot-fix branch September 14, 2020 17:22
sgmiller added a commit that referenced this pull request Sep 14, 2020
…esponse. (#9894)

* Don't open the snapshot file until we have a successful response

* Check the success of Close if nothing else errors
sgmiller added a commit that referenced this pull request Sep 14, 2020
…esponse. (#9894) (#9944)

* Don't open the snapshot file until we have a successful response

* Check the success of Close if nothing else errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants