]> git.saurik.com Git - redis.git/commitdiff
Truncate short write from the AOF
authorSaj Goonatilleke <sg@redu.cx>
Mon, 16 Jul 2012 05:33:25 +0000 (15:33 +1000)
committerantirez <antirez@gmail.com>
Tue, 31 Jul 2012 08:58:16 +0000 (10:58 +0200)
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

index 1df60b941e0f5d34b40cd20c8eae6016b4502b13..441ccaf18802ef9139efd2c38169a3c39a57799d 100644 (file)
--- 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);
     }