From 48553a29e8c56fcc21f77b284a4d3a3448a75e1e Mon Sep 17 00:00:00 2001 From: Saj Goonatilleke Date: Tue, 17 Jul 2012 12:06:53 +1000 Subject: [PATCH 1/4] New in INFO: aof_last_bgrewrite_status Behaves like rdb_last_bgsave_status -- even down to reporting 'ok' when no rewrite has been done yet. (You might want to check that aof_last_rewrite_time_sec is not -1.) --- src/aof.c | 6 ++++++ src/redis.c | 9 ++++++--- src/redis.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/aof.c b/src/aof.c index 09bfb049..1df60b94 100644 --- a/src/aof.c +++ b/src/aof.c @@ -1093,6 +1093,8 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) { server.aof_buf = sdsempty(); } + server.aof_lastbgrewrite_status = REDIS_OK; + redisLog(REDIS_NOTICE, "Background AOF rewrite finished successfully"); /* Change state from WAIT_REWRITE to ON if needed */ if (server.aof_state == REDIS_AOF_WAIT_REWRITE) @@ -1104,9 +1106,13 @@ void backgroundRewriteDoneHandler(int exitcode, int bysignal) { redisLog(REDIS_VERBOSE, "Background AOF rewrite signal handler took %lldus", ustime()-now); } else if (!bysignal && exitcode != 0) { + server.aof_lastbgrewrite_status = REDIS_ERR; + redisLog(REDIS_WARNING, "Background AOF rewrite terminated with error"); } else { + server.aof_lastbgrewrite_status = REDIS_ERR; + redisLog(REDIS_WARNING, "Background AOF rewrite terminated by signal %d", bysignal); } diff --git a/src/redis.c b/src/redis.c index fa0603cb..c8fea86f 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1114,6 +1114,7 @@ void initServerConfig() { server.aof_last_fsync = time(NULL); server.aof_rewrite_time_last = -1; server.aof_rewrite_time_start = -1; + server.aof_lastbgrewrite_status = REDIS_OK; server.aof_delayed_fsync = 0; server.aof_fd = -1; server.aof_selected_db = -1; /* Make sure the first time will not match */ @@ -1957,12 +1958,13 @@ sds genRedisInfoString(char *section) { "aof_rewrite_in_progress:%d\r\n" "aof_rewrite_scheduled:%d\r\n" "aof_last_rewrite_time_sec:%ld\r\n" - "aof_current_rewrite_time_sec:%ld\r\n", + "aof_current_rewrite_time_sec:%ld\r\n" + "aof_last_bgrewrite_status:%s\r\n", server.loading, server.dirty, server.rdb_child_pid != -1, server.lastsave, - server.lastbgsave_status == REDIS_OK ? "ok" : "err", + (server.lastbgsave_status == REDIS_OK) ? "ok" : "err", server.rdb_save_time_last, (server.rdb_child_pid == -1) ? -1 : time(NULL)-server.rdb_save_time_start, @@ -1971,7 +1973,8 @@ sds genRedisInfoString(char *section) { server.aof_rewrite_scheduled, server.aof_rewrite_time_last, (server.aof_child_pid == -1) ? - -1 : time(NULL)-server.aof_rewrite_time_start); + -1 : time(NULL)-server.aof_rewrite_time_start, + (server.aof_lastbgrewrite_status == REDIS_OK) ? "ok" : "err"); if (server.aof_state != REDIS_AOF_OFF) { info = sdscatprintf(info, diff --git a/src/redis.h b/src/redis.h index 9a9b511c..2fe2fb9e 100644 --- a/src/redis.h +++ b/src/redis.h @@ -644,6 +644,7 @@ struct redisServer { time_t aof_last_fsync; /* UNIX time of last fsync() */ time_t aof_rewrite_time_last; /* Time used by last AOF rewrite run. */ time_t aof_rewrite_time_start; /* Current AOF rewrite start time. */ + int aof_lastbgrewrite_status; /* REDIS_OK or REDIS_ERR */ unsigned long aof_delayed_fsync; /* delayed AOF fsync() counter */ /* RDB persistence */ long long dirty; /* Changes to DB from the last save */ From 55302e9e285d13ae5eda021420d1a3ea6ca21afc Mon Sep 17 00:00:00 2001 From: Saj Goonatilleke Date: Mon, 16 Jul 2012 15:33:25 +1000 Subject: [PATCH 2/4] Truncate short write from the AOF 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/aof.c b/src/aof.c index 09bfb049..7c9bbdcb 100644 --- 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); } From 7617a6f272474c433c1d2e8884c8a174e91ff9bd Mon Sep 17 00:00:00 2001 From: Jeremy Zawodny Date: Wed, 25 Jul 2012 08:29:11 -0700 Subject: [PATCH 3/4] comment fix improve English a bit. :-) --- sentinel.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentinel.conf b/sentinel.conf index eb2de6a5..45c34401 100644 --- a/sentinel.conf +++ b/sentinel.conf @@ -63,7 +63,7 @@ sentinel failover-timeout mymaster 900000 # The script is called with just two arguments: the first is the event type # and the second the event description. # -# The script must be exits and executable in order for sentinel to start if +# The script must exist and be executable in order for sentinel to start if # this option is provided. # # Example: From c6c19c8372fd9258a35b7d4bdcb454898e6c1413 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Sat, 28 Jul 2012 12:33:01 +0300 Subject: [PATCH 4/4] Include sys/wait.h to avoid compiler warning gcc warned about an implicit declaration of function 'wait3'. Including this header fixes this. --- src/sentinel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sentinel.c b/src/sentinel.c index 227fb693..a5ce31ee 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -36,6 +36,7 @@ #include #include #include +#include extern char **environ;