Cluster: free HANDSHAKE nodes after node_timeout.

Handshake nodes should turn into normal nodes or be freed in a
reasonable amount of time, otherwise they'll keep accumulating if the
address they are associated with is not reachable for some reason.
This commit is contained in:
antirez 2013-09-04 12:41:21 +02:00
parent 2debce325b
commit 72587e6cc5
2 changed files with 12 additions and 0 deletions

View File

@ -359,6 +359,7 @@ clusterNode *createClusterNode(char *nodename, int flags) {
memcpy(node->name, nodename, REDIS_CLUSTER_NAMELEN);
else
getRandomHexChars(node->name, REDIS_CLUSTER_NAMELEN);
node->ctime = time(NULL);
node->flags = flags;
memset(node->slots,0,sizeof(node->slots));
node->numslots = 0;
@ -1588,6 +1589,16 @@ void clusterCron(void) {
clusterNode *node = dictGetVal(de);
if (node->flags & (REDIS_NODE_MYSELF|REDIS_NODE_NOADDR)) continue;
/* A Node in HANDSHAKE state has a limited lifespan equal to the
* configured node timeout. */
if (node->flags & REDIS_NODE_HANDSHAKE &&
server.unixtime - node->ctime > server.cluster_node_timeout)
{
freeClusterNode(node);
continue;
}
if (node->link == NULL) {
int fd;
time_t old_ping_sent;

View File

@ -614,6 +614,7 @@ struct clusterNodeFailReport {
} typedef clusterNodeFailReport;
struct clusterNode {
time_t ctime; /* Node object creation time. */
char name[REDIS_CLUSTER_NAMELEN]; /* Node name, hex string, sha1-size */
int flags; /* REDIS_NODE_... */
unsigned char slots[REDIS_CLUSTER_SLOTS/8]; /* slots handled by this node */