mirror of
https://github.com/fluencelabs/redis
synced 2025-04-01 15:21:03 +00:00
centralized cluster config file name. Assigned slots in CLUSTER NODES output and in cluster config file.
This commit is contained in:
parent
4b72c5617f
commit
ef21ab960e
@ -44,7 +44,7 @@ int clusterLoadConfig(char *filename) {
|
|||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
|
|
||||||
fmterr:
|
fmterr:
|
||||||
redisLog(REDIS_WARNING,"Unrecovarable error: corrupted redis-cluster.conf file.");
|
redisLog(REDIS_WARNING,"Unrecovarable error: corrupted cluster config file.");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -53,11 +53,12 @@ fmterr:
|
|||||||
*
|
*
|
||||||
* This function writes the node config and returns 0, on error -1
|
* This function writes the node config and returns 0, on error -1
|
||||||
* is returned. */
|
* is returned. */
|
||||||
int clusterSaveConfig(char *filename) {
|
int clusterSaveConfig(void) {
|
||||||
sds ci = clusterGenNodesDescription();
|
sds ci = clusterGenNodesDescription();
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if ((fd = open(filename,O_WRONLY|O_CREAT,0644)) == -1) goto err;
|
if ((fd = open(server.cluster.configfile,O_WRONLY|O_CREAT,0644)) == -1)
|
||||||
|
goto err;
|
||||||
if (write(fd,ci,sdslen(ci)) != (ssize_t)sdslen(ci)) goto err;
|
if (write(fd,ci,sdslen(ci)) != (ssize_t)sdslen(ci)) goto err;
|
||||||
close(fd);
|
close(fd);
|
||||||
sdsfree(ci);
|
sdsfree(ci);
|
||||||
@ -68,6 +69,13 @@ err:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clusterSaveConfigOrDie(void) {
|
||||||
|
if (clusterSaveConfig() == -1) {
|
||||||
|
redisLog(REDIS_WARNING,"Fatal: can't update cluster config file.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void clusterInit(void) {
|
void clusterInit(void) {
|
||||||
int saveconf = 0;
|
int saveconf = 0;
|
||||||
|
|
||||||
@ -81,7 +89,7 @@ void clusterInit(void) {
|
|||||||
sizeof(server.cluster.importing_slots_from));
|
sizeof(server.cluster.importing_slots_from));
|
||||||
memset(server.cluster.slots,0,
|
memset(server.cluster.slots,0,
|
||||||
sizeof(server.cluster.slots));
|
sizeof(server.cluster.slots));
|
||||||
if (clusterLoadConfig("redis-cluster.conf") == REDIS_ERR) {
|
if (clusterLoadConfig(server.cluster.configfile) == REDIS_ERR) {
|
||||||
/* No configuration found. We will just use the random name provided
|
/* No configuration found. We will just use the random name provided
|
||||||
* by the createClusterNode() function. */
|
* by the createClusterNode() function. */
|
||||||
redisLog(REDIS_NOTICE,"No cluster configuration found, I'm %.40s",
|
redisLog(REDIS_NOTICE,"No cluster configuration found, I'm %.40s",
|
||||||
@ -89,12 +97,7 @@ void clusterInit(void) {
|
|||||||
saveconf = 1;
|
saveconf = 1;
|
||||||
}
|
}
|
||||||
clusterAddNode(server.cluster.myself);
|
clusterAddNode(server.cluster.myself);
|
||||||
if (saveconf) {
|
if (saveconf) clusterSaveConfigOrDie();
|
||||||
if (clusterSaveConfig("redis-cluster.conf") == -1) {
|
|
||||||
redisLog(REDIS_WARNING,"Fatal: can't update cluster config file.");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* We need a listening TCP port for our cluster messaging needs */
|
/* We need a listening TCP port for our cluster messaging needs */
|
||||||
server.cfd = anetTcpServer(server.neterr,
|
server.cfd = anetTcpServer(server.neterr,
|
||||||
server.port+REDIS_CLUSTER_PORT_INCR, server.bindaddr);
|
server.port+REDIS_CLUSTER_PORT_INCR, server.bindaddr);
|
||||||
@ -910,6 +913,7 @@ sds clusterGenNodesDescription(void) {
|
|||||||
sds ci = sdsempty();
|
sds ci = sdsempty();
|
||||||
dictIterator *di;
|
dictIterator *di;
|
||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
|
int j, start;
|
||||||
|
|
||||||
di = dictGetIterator(server.cluster.nodes);
|
di = dictGetIterator(server.cluster.nodes);
|
||||||
while((de = dictNext(di)) != NULL) {
|
while((de = dictNext(di)) != NULL) {
|
||||||
@ -939,11 +943,32 @@ sds clusterGenNodesDescription(void) {
|
|||||||
ci = sdscatprintf(ci,"- ");
|
ci = sdscatprintf(ci,"- ");
|
||||||
|
|
||||||
/* Latency from the POV of this node, link status */
|
/* Latency from the POV of this node, link status */
|
||||||
ci = sdscatprintf(ci,"%ld %ld %s\n",
|
ci = sdscatprintf(ci,"%ld %ld %s",
|
||||||
(long) node->ping_sent,
|
(long) node->ping_sent,
|
||||||
(long) node->pong_received,
|
(long) node->pong_received,
|
||||||
node->link ? "connected" : "disconnected");
|
node->link ? "connected" : "disconnected");
|
||||||
|
|
||||||
|
/* Slots served by this instance */
|
||||||
|
start = -1;
|
||||||
|
for (j = 0; j < REDIS_CLUSTER_SLOTS; j++) {
|
||||||
|
int bit;
|
||||||
|
|
||||||
|
if ((bit = clusterNodeGetSlotBit(node,j)) != 0) {
|
||||||
|
if (start == -1) start = j;
|
||||||
|
}
|
||||||
|
if (start != -1 && (!bit || j == REDIS_CLUSTER_SLOTS-1)) {
|
||||||
|
if (j == REDIS_CLUSTER_SLOTS-1) j++;
|
||||||
|
|
||||||
|
if (start == j-1) {
|
||||||
|
ci = sdscatprintf(ci," %d",start);
|
||||||
|
} else {
|
||||||
|
ci = sdscatprintf(ci," %d-%d",start,j-1);
|
||||||
|
}
|
||||||
|
start = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ci = sdscatlen(ci,"\n",1);
|
||||||
dictReleaseIterator(di);
|
dictReleaseIterator(di);
|
||||||
return ci;
|
return ci;
|
||||||
}
|
}
|
||||||
|
@ -841,6 +841,7 @@ void initServerConfig() {
|
|||||||
server.shutdown_asap = 0;
|
server.shutdown_asap = 0;
|
||||||
server.cache_flush_delay = 0;
|
server.cache_flush_delay = 0;
|
||||||
server.cluster_enabled = 0;
|
server.cluster_enabled = 0;
|
||||||
|
server.cluster.configfile = zstrdup("nodes.conf");
|
||||||
|
|
||||||
updateLRUClock();
|
updateLRUClock();
|
||||||
resetServerSaveParams();
|
resetServerSaveParams();
|
||||||
|
@ -411,6 +411,7 @@ struct clusterNode {
|
|||||||
typedef struct clusterNode clusterNode;
|
typedef struct clusterNode clusterNode;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
char *configfile;
|
||||||
clusterNode *myself; /* This node */
|
clusterNode *myself; /* This node */
|
||||||
int state; /* REDIS_CLUSTER_OK, REDIS_CLUSTER_FAIL, ... */
|
int state; /* REDIS_CLUSTER_OK, REDIS_CLUSTER_FAIL, ... */
|
||||||
int node_timeout;
|
int node_timeout;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user