From b0939303e6a9288efaef159cc4a08b656c3b9ff3 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 19 Jan 2016 15:05:52 +0100 Subject: [PATCH] Cluster announce ip / port configuration handling. --- src/config.c | 8 ++++++++ src/server.c | 2 ++ src/server.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/src/config.c b/src/config.c index 850850628..520d23d86 100644 --- a/src/config.c +++ b/src/config.c @@ -514,6 +514,9 @@ void loadServerConfigFromString(char *config) { } else if (!strcasecmp(argv[0],"cluster-config-file") && argc == 2) { zfree(server.cluster_configfile); server.cluster_configfile = zstrdup(argv[1]); + } else if (!strcasecmp(argv[0],"cluster-announce-ip") && argc == 2) { + zfree(server.cluster_announce_ip); + server.cluster_announce_ip = zstrdup(argv[1]); } else if (!strcasecmp(argv[0],"cluster-require-full-coverage") && argc == 2) { @@ -745,6 +748,9 @@ void configSetCommand(client *c) { } config_set_special_field("masterauth") { zfree(server.masterauth); server.masterauth = ((char*)o->ptr)[0] ? zstrdup(o->ptr) : NULL; + } config_set_special_field("cluster-announce-ip") { + zfree(server.cluster_announce_ip); + server.cluster_announce_ip = ((char*)o->ptr)[0] ? zstrdup(o->ptr) : NULL; } config_set_special_field("maxclients") { int orig_value = server.maxclients; @@ -1067,6 +1073,7 @@ void configGetCommand(client *c) { config_get_string_field("dbfilename",server.rdb_filename); config_get_string_field("requirepass",server.requirepass); config_get_string_field("masterauth",server.masterauth); + config_get_string_field("cluster-announce-ip",server.cluster_announce_ip); config_get_string_field("unixsocket",server.unixsocket); config_get_string_field("logfile",server.logfile); config_get_string_field("pidfile",server.pidfile); @@ -1812,6 +1819,7 @@ int rewriteConfig(char *path) { rewriteConfigDirOption(state); rewriteConfigSlaveofOption(state); rewriteConfigStringOption(state,"masterauth",server.masterauth,NULL); + rewriteConfigStringOption(state,"cluster-announce-ip",server.cluster_announce_ip,NULL); rewriteConfigYesNoOption(state,"slave-serve-stale-data",server.repl_serve_stale_data,CONFIG_DEFAULT_SLAVE_SERVE_STALE_DATA); rewriteConfigYesNoOption(state,"slave-read-only",server.repl_slave_ro,CONFIG_DEFAULT_SLAVE_READ_ONLY); rewriteConfigNumericalOption(state,"repl-ping-slave-period",server.repl_ping_slave_period,CONFIG_DEFAULT_REPL_PING_SLAVE_PERIOD); diff --git a/src/server.c b/src/server.c index aac39d983..429dfc230 100644 --- a/src/server.c +++ b/src/server.c @@ -1523,6 +1523,8 @@ void initServerConfig(void) { server.cluster_slave_validity_factor = CLUSTER_DEFAULT_SLAVE_VALIDITY; server.cluster_require_full_coverage = CLUSTER_DEFAULT_REQUIRE_FULL_COVERAGE; server.cluster_configfile = zstrdup(CONFIG_DEFAULT_CLUSTER_CONFIG_FILE); + server.cluster_announce_ip = NULL; + server.cluster_announce_port = 0; server.migrate_cached_sockets = dictCreate(&migrateCacheDictType,NULL); server.next_client_id = 1; /* Client IDs, start from 1 .*/ server.loading_process_events_interval_bytes = (1024*1024*2); diff --git a/src/server.h b/src/server.h index 2ec33f507..879368daf 100644 --- a/src/server.h +++ b/src/server.h @@ -947,6 +947,8 @@ struct redisServer { int cluster_slave_validity_factor; /* Slave max data age for failover. */ int cluster_require_full_coverage; /* If true, put the cluster down if there is at least an uncovered slot.*/ + char *cluster_announce_ip; /* cluster-announce-ip option. */ + int cluster_announce_port; /* cluster-announce-port option. */ /* Scripting */ lua_State *lua; /* The Lua interpreter. We use just one for all clients */ client *lua_client; /* The "fake client" to query Redis from Lua */