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

fsync before overwriting previous persist file #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jmckaskill
Copy link

Standard process for an atomic update on unix systems is:

  1. Write new contents to a temp file on same filesystem/folder
  2. fsync the file
  3. Close the file
  4. Rename the temp file over top of the existing file

The existing code was missing #2. If you lose power soon after persisting a new file, the file rename can be synced through without the new data contents. If that happens you end up losing your settings.

Standard process for an atomic update on unix systems is:
1. Write new contents to a temp file on same filesystem/folder
2. fsync the file
3. Close the file
4. Rename the temp file over top of the existing file

The existing code was missing seladb#2. If you lose power soon after
persisting a new file, the file rename can be synced through without the
new data contents. If that happens you end up losing your settings.
@seladb
Copy link
Owner

seladb commented Jul 19, 2024

@jmckaskill I'm not sure I understand. Why do we need fsync here? 🤔

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.

2 participants