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

atomic write service state and checks files #2240

Merged
merged 1 commit into from
Nov 7, 2016
Merged

atomic write service state and checks files #2240

merged 1 commit into from
Nov 7, 2016

Conversation

camerondavison
Copy link
Contributor

fixes #1221

@shoenig
Copy link
Contributor

shoenig commented Aug 3, 2016

I think you will want to also call Sync on the tmpfile and parent directory for this to actually be atomic

@camerondavison
Copy link
Contributor Author

doing a sync would help make it durable, should not have anything to do with it being atomic. I would say doing a sync for these files (which are just to help with entropy) is unnecessary, my original intention is just to make it so there never exists a 0 byte file. Without the sync there will either be a full byte file, or no file.

@rboyer
Copy link
Member

rboyer commented Aug 3, 2016

If your goal is to never have a zero-byte file between system crashes, you must call sync on the file before the rename. If you don't care about the crash/reboot scenario then you can omit the Sync call.

@camerondavison
Copy link
Contributor Author

okay. then this helps prevent corrupt state for consul restarts, and consul crashes but not for machine level crashes. I'll defer to the consul devs if they would like to add the sync, or just remove corrupt state files on startup.

@kyhavlov kyhavlov merged commit d138752 into hashicorp:master Nov 7, 2016
@camerondavison camerondavison deleted the atomic-write-service-states-and-checks branch December 29, 2016 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unexpected end of JSON input after server crash
4 participants