From 8f18345ef0fe3adacb4be4434210b939a7198bed Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 29 Nov 2013 17:37:06 +0100 Subject: [PATCH] Cluster: basic data structures for nodes black list. --- src/cluster.c | 2 ++ src/cluster.h | 1 + src/redis.c | 12 ++++++++++++ src/redis.h | 1 + 4 files changed, 16 insertions(+) diff --git a/src/cluster.c b/src/cluster.c index 55d0e8970..d907a993d 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -260,6 +260,8 @@ void clusterInit(void) { server.cluster->state = REDIS_CLUSTER_FAIL; server.cluster->size = 1; server.cluster->nodes = dictCreate(&clusterNodesDictType,NULL); + server.cluster->nodes_black_list = + dictCreate(&clusterNodesBlackListDictType,NULL); server.cluster->failover_auth_time = 0; server.cluster->failover_auth_count = 0; server.cluster->failover_auth_epoch = 0; diff --git a/src/cluster.h b/src/cluster.h index 28d9af806..faba13477 100644 --- a/src/cluster.h +++ b/src/cluster.h @@ -78,6 +78,7 @@ typedef struct clusterState { int state; /* REDIS_CLUSTER_OK, REDIS_CLUSTER_FAIL, ... */ int size; /* Num of master nodes with at least one slot */ dict *nodes; /* Hash table of name -> clusterNode structures */ + dict *nodes_black_list; /* Nodes we don't re-add for a few seconds. */ clusterNode *migrating_slots_to[REDIS_CLUSTER_SLOTS]; clusterNode *importing_slots_from[REDIS_CLUSTER_SLOTS]; clusterNode *slots[REDIS_CLUSTER_SLOTS]; diff --git a/src/redis.c b/src/redis.c index 9d7f9164b..e112f1b56 100644 --- a/src/redis.c +++ b/src/redis.c @@ -583,6 +583,18 @@ dictType clusterNodesDictType = { NULL /* val destructor */ }; +/* Cluster re-addition blacklist. This maps node IDs to the time + * we can re-add this node. The goal is to avoid readding a removed + * node for some time. */ +dictType clusterNodesBlackListDictType = { + dictSdsCaseHash, /* hash function */ + NULL, /* key dup */ + NULL, /* val dup */ + dictSdsKeyCaseCompare, /* key compare */ + dictSdsDestructor, /* key destructor */ + NULL /* val destructor */ +}; + /* Migrate cache dict type. */ dictType migrateCacheDictType = { dictSdsHash, /* hash function */ diff --git a/src/redis.h b/src/redis.h index 76f7dd3b3..9886c6476 100644 --- a/src/redis.h +++ b/src/redis.h @@ -884,6 +884,7 @@ extern struct sharedObjectsStruct shared; extern dictType setDictType; extern dictType zsetDictType; extern dictType clusterNodesDictType; +extern dictType clusterNodesBlackListDictType; extern dictType dbDictType; extern dictType shaScriptObjectDictType; extern double R_Zero, R_PosInf, R_NegInf, R_Nan;