Skip to content

Commit

Permalink
Cluster: free HANDSHAKE nodes after node_timeout.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antirez committed Sep 4, 2013
1 parent 2debce3 commit 72587e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 72587e6

Please sign in to comment.