Fsync

From PortaWiki

Jump to: navigation, search

POSIX explicitly allows a null implementation of fsync(2) when _POSIX_SYNCHRONIZED_IO is not defined. Unfortunately, the addition of _POSIX_SYNCHRONIZED_IO is relatively recent and so cannot be relied upon.

Testing for _POSIX_SYNCHRONIZED_IO is probably a good thing to do anyway, and then add exceptions for platforms you know to be not broken.

fsync may return EINTR on some platforms - if you really want data to be on disk, check for this. the mysys library loops while errno==EINTR.

MacOS X

MacOS X is one of the interesting platforms. You need to do an additional fcntl to get data to be flushed to disk.

In the MySQL source tree, innobase/os/os0file.c is interesting to look at as it implements a portable os_file_flush(file) function.

ret = fcntl(file, F_FULLFSYNC, NULL);


Linux

fsync on a raw device returns EINVAL (or at least used to, InnoDB checks for this, so it was likely true at some point)

Personal tools