[erlang-questions] Erlang and fsync

Mon Aug 4 03:37:26 CEST 2014

> Hello!
> When a UNIX program wants to ensure that a file and its contents have been
> written to disk, the normal way is to call fsync().

>From the Mac OS X manual page for fsync(2):

     Note that while fsync() will flush all data from the host to the
     drive (i.e. the "permanent storage device"), the drive itself
     may not physically write the data to the platters for quite some
     time and it may be written in an out-of-order sequence.

     Specifically, if the drive loses power or the OS crashes, the
     application may find that only some or none of their data was
     written.  The disk drive may also re-order the data so that
     later writes may be present, while earlier writes are not.

     This is not a theoretical edge case.  This scenario is easily
     reproduced with real world workloads and drive power failures.

It is possible to ask a drive to commit stuff to permanent storage,
and Mac OS X provide the F_FULLSYNC fcntl() call to do that.  None
of the other UNIX systems I have, or have access to manuals for,
has the same fcntl() option.

If anyone _does_ know of a tolerably portable way to ensure that
your data are physically on a permanent medium, I would be glad
to hear of it.

More information about the erlang-questions mailing list