提交 72f7abf6 编写于 作者: A antirez

Cluster: clusterSetStartupEpoch() made more generally useful.

The actual goal of the function was to get the max configEpoch found in
the cluster, so make it general by removing the assignment of the max
epoch to currentEpoch that is useful only at startup.
上级 44f7afe2
...@@ -73,21 +73,19 @@ void resetManualFailover(void); ...@@ -73,21 +73,19 @@ void resetManualFailover(void);
* Initialization * Initialization
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
/* This function is called at startup in order to set the currentEpoch /* Return the greatest configEpoch found in the cluster. */
* (which is not saved on permanent storage) to the greatest configEpoch found uint64_t clusterGetMaxEpoch(void) {
* in the loaded nodes (configEpoch is stored on permanent storage as soon as uint64_t max = 0;
* it changes for some node). */
void clusterSetStartupEpoch() {
dictIterator *di; dictIterator *di;
dictEntry *de; dictEntry *de;
di = dictGetSafeIterator(server.cluster->nodes); di = dictGetSafeIterator(server.cluster->nodes);
while((de = dictNext(di)) != NULL) { while((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetVal(de); clusterNode *node = dictGetVal(de);
if (node->configEpoch > server.cluster->currentEpoch) if (node->configEpoch > max) max = node->configEpoch;
server.cluster->currentEpoch = node->configEpoch;
} }
dictReleaseIterator(di); dictReleaseIterator(di);
return max;
} }
int clusterLoadConfig(char *filename) { int clusterLoadConfig(char *filename) {
...@@ -227,7 +225,10 @@ int clusterLoadConfig(char *filename) { ...@@ -227,7 +225,10 @@ 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);
clusterSetStartupEpoch(); /* Set the currentEpoch to the max epoch found in the master.
* FIXME: this should actually be part of the persistent state, as
* documented in the Github issue #1479. */
server.cluster->currentEpoch = clusterGetMaxEpoch();
return REDIS_OK; return REDIS_OK;
fmterr: fmterr:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册