Skip to content

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

Merged
sgmiller merged 4 commits into
masterfrom
raft-snapshot-fix
Sep 14, 2020
Merged

Don't open a raft snapshot file until we have a successful snapshot response.#9894
sgmiller merged 4 commits into
masterfrom
raft-snapshot-fix

Conversation

@sgmiller
Copy link
Copy Markdown
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.

Comment thread command/operator_raft_snapshot_save.go Outdated
},
}
defer snapFile.Close()
defer w.Close()
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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