From 4fcc564a974ff20804906a622b1d8d2f5583c106 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 14 Dec 2017 12:19:30 +0100 Subject: [PATCH] safe_write -> aofWrite. Function commented. Related to #4498. --- src/aof.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/aof.c b/src/aof.c index 50abe1d34..3f2969636 100644 --- a/src/aof.c +++ b/src/aof.c @@ -266,7 +266,14 @@ int startAppendOnly(void) { return C_OK; } -ssize_t safe_write(int fd, const char *buf, size_t len) { +/* This is a wrapper to the write syscall in order to retry on short writes + * or if the syscall gets interrupted. It could look strange that we retry + * on short writes given that we are writing to a block device: normally if + * the first call is short, there is a end-of-space condition, so the next + * is likely to fail. However apparently in modern systems this is no longer + * true, and in general it looks just more resilient to retry the write. If + * there is an actual error condition we'll get it at the next try. */ +ssize_t aofWrite(int fd, const char *buf, size_t len) { ssize_t nwritten = 0, totwritten = 0; while(len) { @@ -344,7 +351,7 @@ void flushAppendOnlyFile(int force) { * or alike */ latencyStartMonitor(latency); - nwritten = safe_write(server.aof_fd,server.aof_buf,sdslen(server.aof_buf)); + nwritten = aofWrite(server.aof_fd,server.aof_buf,sdslen(server.aof_buf)); latencyEndMonitor(latency); /* We want to capture different events for delayed writes: * when the delay happens with a pending fsync, or with a saving child