Commit 172f14d4 authored by antirez's avatar antirez
Browse files

Use fflush() before fsync() in rio.c.

Incremental flushing in rio.c is only used to avoid huge kernel buffers
synched to slow disks creating big latency spikes, so this fix has no
durability implications, however it is certainly more correct to make
sure that the FILE buffers are flushed to the kernel before calling
fsync on the file descriptor.

Thanks to Li Shao Kai for reporting this issue in the Redis mailing
list.
parent 80e80668
...@@ -86,6 +86,7 @@ static size_t rioFileWrite(rio *r, const void *buf, size_t len) { ...@@ -86,6 +86,7 @@ static size_t rioFileWrite(rio *r, const void *buf, size_t len) {
if (r->io.file.autosync && if (r->io.file.autosync &&
r->io.file.buffered >= r->io.file.autosync) r->io.file.buffered >= r->io.file.autosync)
{ {
fflush(r->io.file.fp);
aof_fsync(fileno(r->io.file.fp)); aof_fsync(fileno(r->io.file.fp));
r->io.file.buffered = 0; r->io.file.buffered = 0;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment