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

Prevent inconsistent data in json files. #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tobox
Copy link

@tobox tobox commented Dec 1, 2015

Dumping the json content directly into the final output files creates
inconsistend data temporarily, which may cause strange
effects. Writing to temporary files and atomically renaming them
should fix this.

Works only on unix-like systems where os.rename can overwrite existing
files.

Dumping the json content directly into the final output files creates
inconsistend data temporarily, which may cause strange
effects. Writing to temporary files and atomically renaming them
should fix this.

Works only on unix-like systems where os.rename can overwrite existing
files.
@leahoswald
Copy link

@tobox it would be nice if you fix the problems which let the tests to fail.

@jplitza
Copy link
Member

jplitza commented Dec 7, 2015

This only fixes a small aspect of the bigger problem that also caused #44, namely that apparently in many instances, the output of this script currently is served directly by webservers. This PR may guarantee an atomic modification to the JSON files, but not to the RRDs or PNGs. So I somehow have the feeling there should be a more general approach to the bigger problem, rather than fixing several small effects it has.

@tobox
Copy link
Author

tobox commented Dec 7, 2015

If somebody was working on fixing the bigger problem, I would agree that this PR should not be merged yet. If nobody is working on it, I guess a workaround for real-world problems should be considered for merging, especially since this minor change is trivial to revert.

@ecsv
Copy link

ecsv commented Jun 24, 2016

I have (unfortunately) seen a complete messed up nodes.json due to some hard reset of a server. I would therefore appreciate such a change. But It would be good when the buffer is actually written to disk before the file is renamed

f.flush()
os.fsync(f.fileno())


with open(nodelist_fn, 'w') as f:
with open(nodelist_fn + 'tmp', 'w') as f:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a '.' missing in front of the tmp'

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.

None yet

5 participants