From 01f7db608dbf77c24a9735d686aba35dc250a96f Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 16 Sep 2014 10:57:40 +0200 Subject: [PATCH] Seek at the end of AOF after truncate call. It is not clear if files open in append only mode will automatically fix their offset after a truncate(2) operation. This commit makes sure that we reposition the AOF file descriptor offset at the end of the file after a truncated AOF is loaded and trimmed to the last valid command. --- src/aof.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/aof.c b/src/aof.c index 350ea8d9..0f9682cd 100644 --- a/src/aof.c +++ b/src/aof.c @@ -683,9 +683,16 @@ uxeof: /* Unexpected AOF end of file. */ strerror(errno)); } } else { - redisLog(REDIS_WARNING, - "AOF loaded anyway because aof-load-truncated is enabled"); - goto loaded_ok; + /* Make sure the AOF file descriptor points to the end of the + * file after the truncate call. */ + if (server.aof_fd != -1 && lseek(server.aof_fd,0,SEEK_END) == -1) { + redisLog(REDIS_WARNING,"Can't seek the end of the AOF file: %s", + strerror(errno)); + } else { + redisLog(REDIS_WARNING, + "AOF loaded anyway because aof-load-truncated is enabled"); + goto loaded_ok; + } } } redisLog(REDIS_WARNING,"Unexpected end of file reading the append only file. You can: 1) Make a backup of your AOF file, then use ./redis-check-aof --fix . 2) Alternatively you can set the 'aof-load-truncated' configuration option to yes and restart the server.");