summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-11-19 10:13:04 +0100
committerantirez <antirez@gmail.com>2013-11-21 15:22:11 +0100
commit93d924ff1c70891e3fe93357988d68e158ddeda5 (patch)
tree2e349b042797a9d27743818f47fd790ab8c2937b
parenta52909c5f21fc81b8aeff3e67eea96126f911228 (diff)
downloadredis-93d924ff1c70891e3fe93357988d68e158ddeda5.tar.gz
Sentinel: sentinelFlushConfig() to CONFIG REWRITE + fsync.
-rw-r--r--src/redis.h1
-rw-r--r--src/sentinel.c22
2 files changed, 23 insertions, 0 deletions
diff --git a/src/redis.h b/src/redis.h
index 015d82c4d..eb9d9e079 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -1146,6 +1146,7 @@ void appendServerSaveParams(time_t seconds, int changes);
void resetServerSaveParams();
struct rewriteConfigState; /* Forward declaration to export API. */
void rewriteConfigRewriteLine(struct rewriteConfigState *state, char *option, sds line, int force);
+int rewriteConfig(char *path);
/* db.c -- Keyspace access API */
int removeExpire(redisDb *db, robj *key);
diff --git a/src/sentinel.c b/src/sentinel.c
index e71486f27..d7ad3a1c0 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -36,6 +36,7 @@
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/wait.h>
+#include <fcntl.h>
extern char **environ;
@@ -1434,6 +1435,27 @@ void rewriteConfigSentinelOption(struct rewriteConfigState *state) {
dictReleaseIterator(di);
}
+/* This function uses the config rewriting Redis engine in order to persist
+ * the state of the Sentinel in the current configuration file.
+ *
+ * Before returning the function calls fsync() against the generated
+ * configuration file to make sure changes are committed to disk.
+ *
+ * On failure the function logs a warning on the Redis log. */
+void sentinelFlushConfig(void) {
+ int fd;
+
+ if (rewriteConfig(server.configfile) == -1) {
+ redisLog(REDIS_WARNING,"WARNING: Senitnel was not able to save the new configuration on disk!!!: %s", strerror(errno));
+ return;
+ }
+ if ((fd = open(server.configfile,O_RDONLY)) != -1) {
+ fsync(fd);
+ close(fd);
+ }
+ return;
+}
+
/* ====================== hiredis connection handling ======================= */
/* Completely disconnect an hiredis link from an instance. */