[issue8604] Adding an atomic FS write API

Charles-François Natali report at bugs.python.org
Fri Dec 23 15:28:37 CET 2011


Charles-François Natali <neologix at free.fr> added the comment:

> If you want atomicity to apply to logging,
> you must instead guarantee the durability of each write() call, meaning
> calling fsync() on each logging call

Why so?
There's no point in calling fsync() after each write, since data is
written to a temporary file which won't be visible before rename():
even if you call fsync() after each write, if the file is not properly
closed, it won't be committed (i.e.renamed).
You just need to call fsync() once before closing the file, and then
rename it, to ensure that the committed file version is consistent.
In the meantime, you could do whatever you want with the stream (the
hypothetical AtomicFile): seek(), read(), etc. I'm not sure many
methods besides write will be useful, but for example one could easily
imagine that the library expects the passed object to have a fileno()
method.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8604>
_______________________________________


More information about the Python-bugs-list mailing list