From 55302e9e285d13ae5eda021420d1a3ea6ca21afc Mon Sep 17 00:00:00 2001 From: Saj Goonatilleke Date: Mon, 16 Jul 2012 15:33:25 +1000 Subject: [PATCH] Truncate short write from the AOF If Redis only manages to write out a partial buffer, the AOF file won't load back into Redis the next time it starts up. It is better to discard the short write than waste time running redis-check-aof. --- src/aof.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/aof.c b/src/aof.c index 09bfb0492..7c9bbdcb5 100644 --- a/src/aof.c +++ b/src/aof.c @@ -250,6 +250,13 @@ void flushAppendOnlyFile(int force) { strerror(errno), (long)nwritten, (long)sdslen(server.aof_buf)); + + if (ftruncate(server.aof_fd, server.aof_current_size) == -1) { + redisLog(REDIS_WARNING, "Could not remove short write " + "from the append-only file. Redis may refuse " + "to load the AOF the next time it starts. " + "ftruncate: %s", strerror(errno)); + } } exit(1); } -- GitLab