Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
7fb14b73
Commit
7fb14b73
authored
Mar 27, 2014
by
antirez
Browse files
Cluster: save/restore vars that must persist after recovery.
This fixes issue #1479.
parent
6dd2dbbd
Changes
1
Show whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
7fb14b73
...
@@ -121,6 +121,25 @@ int clusterLoadConfig(char *filename) {
...
@@ -121,6 +121,25 @@ int clusterLoadConfig(char *filename) {
argv = sdssplitargs(line,&argc);
argv = sdssplitargs(line,&argc);
if (argv == NULL) goto fmterr;
if (argv == NULL) goto fmterr;
/* Handle the special "vars" line. Don't pretend it is the last
* line even if it actually is when generated by Redis. */
if (strcasecmp(argv[0],"vars") == 0) {
for (j = 1; j < argc; j += 2) {
if (strcasecmp(argv[j],"currentEpoch") == 0) {
server.cluster->currentEpoch =
strtoull(argv[j+1],NULL,10);
} else if (strcasecmp(argv[j],"last_vote_epoch") == 0) {
server.cluster->last_vote_epoch =
strtoull(argv[j+1],NULL,10);
} else {
redisLog(REDIS_WARNING,
"Skipping unknown cluster config variable '%s'",
argv[j]);
}
}
continue;
}
/* Create this node if it does not exist */
/* Create this node if it does not exist */
n = clusterLookupNode(argv[0]);
n = clusterLookupNode(argv[0]);
if (!n) {
if (!n) {
...
@@ -227,10 +246,13 @@ int clusterLoadConfig(char *filename) {
...
@@ -227,10 +246,13 @@ int clusterLoadConfig(char *filename) {
/* Config sanity check */
/* Config sanity check */
redisAssert(server.cluster->myself != NULL);
redisAssert(server.cluster->myself != NULL);
redisLog(REDIS_NOTICE,"Node configuration loaded, I'm %.40s", myself->name);
redisLog(REDIS_NOTICE,"Node configuration loaded, I'm %.40s", myself->name);
/* Set the currentEpoch to the max epoch found in the master.
* FIXME: this should actually be part of the persistent state, as
/* Something that should never happen: currentEpoch smaller than
* documented in the Github issue #1479. */
* the max epoch found in the nodes configuration. However we handle this
* as some form of protection against manual editing of critical files. */
if (clusterGetMaxEpoch() > server.cluster->currentEpoch) {
server.cluster->currentEpoch = clusterGetMaxEpoch();
server.cluster->currentEpoch = clusterGetMaxEpoch();
}
return REDIS_OK;
return REDIS_OK;
fmterr:
fmterr:
...
@@ -253,11 +275,19 @@ fmterr:
...
@@ -253,11 +275,19 @@ fmterr:
* bigger we pad our payload with newlines that are anyway ignored and truncate
* bigger we pad our payload with newlines that are anyway ignored and truncate
* the file afterward. */
* the file afterward. */
int clusterSaveConfig(int do_fsync) {
int clusterSaveConfig(int do_fsync) {
sds ci
= clusterGenNodesDescription(REDIS_NODE_HANDSHAKE)
;
sds ci;
size_t content_size
= sdslen(ci)
;
size_t content_size;
struct stat sb;
struct stat sb;
int fd;
int fd;
/* Get the nodes description and concatenate our "vars" directive to
* save currentEpoch and last_vote_epoch. */
ci = clusterGenNodesDescription(REDIS_NODE_HANDSHAKE);
ci = sdscatprintf(ci,"vars currentEpoch %llu last_vote_epoch %llu\n",
(unsigned long long) server.cluster->currentEpoch,
(unsigned long long) server.cluster->last_vote_epoch);
content_size = sdslen(ci);
if ((fd = open(server.cluster_configfile,O_WRONLY|O_CREAT,0644))
if ((fd = open(server.cluster_configfile,O_WRONLY|O_CREAT,0644))
== -1) goto err;
== -1) goto err;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment