Skip to content

Commit

Permalink
Truncate short write from the AOF
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
saj committed Jul 18, 2012
1 parent a2db8e4 commit 55302e9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 55302e9

Please sign in to comment.