]> 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)
committerSaj Goonatilleke <sg@redu.cx>
Wed, 18 Jul 2012 00:35:17 +0000 (10:35 +1000)
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 09bfb04924520db75201a66382cf409f24a5b088..7c9bbdcb5e4ddbccd3e162556f6dd9eaf79f19e6 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);
     }