Commit c698616b authored by antirez's avatar antirez
Browse files

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.
parent ac76d56e
...@@ -726,12 +726,19 @@ uxeof: /* Unexpected AOF end of file. */ ...@@ -726,12 +726,19 @@ uxeof: /* Unexpected AOF end of file. */
redisLog(REDIS_WARNING,"Error truncating the AOF file: %s", redisLog(REDIS_WARNING,"Error truncating the AOF file: %s",
strerror(errno)); strerror(errno));
} }
} else {
/* 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 { } else {
redisLog(REDIS_WARNING, redisLog(REDIS_WARNING,
"AOF loaded anyway because aof-load-truncated is enabled"); "AOF loaded anyway because aof-load-truncated is enabled");
goto loaded_ok; 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 <filename>. 2) Alternatively you can set the 'aof-load-truncated' configuration option to yes and restart the server."); 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 <filename>. 2) Alternatively you can set the 'aof-load-truncated' configuration option to yes and restart the server.");
exit(1); exit(1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment