summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUri Shachar <uri@redislabs.com>2021-06-16 06:35:13 +0300
committerGitHub <noreply@github.com>2021-06-15 20:35:13 -0700
commitc7e502a07bdeec29c2be41da70b483b2156d36db (patch)
tree08625974ea3e8aadd44b5940ea7ed71f777151f3
parente5d8a5eb85b50ee7da1bf652c7d67e8e5b757ec9 (diff)
downloadredis-c7e502a07bdeec29c2be41da70b483b2156d36db.tar.gz
Cleaning up the cluster interface by moving almost all related declar… (#9080)
* Cleaning up the cluster interface by moving almost all related declarations into cluster.h (no logic change -- just moving declarations/definitions around) This initial effort leaves two items out of scope - the configuration parsing into the server struct and the internals exposed by the clusterNode struct. * Remove unneeded declarations of dictSds* Ideally all the dictSds functionality would move from server.c into a dedicated module so we can avoid the duplication in redis-benchmark/cli * Move crc16 back into server.h, will be moved out once we create a seperate header file for hashing functions
-rw-r--r--src/cluster.c25
-rw-r--r--src/cluster.h11
-rw-r--r--src/config.c3
-rw-r--r--src/module.c2
-rw-r--r--src/pubsub.c1
-rw-r--r--src/sentinel.c4
-rw-r--r--src/server.c25
-rw-r--r--src/server.h15
-rw-r--r--src/t_zset.c3
9 files changed, 37 insertions, 52 deletions
diff --git a/src/cluster.c b/src/cluster.c
index cd4def90f..aaecd5aea 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -81,6 +81,31 @@ const char *clusterGetMessageTypeString(int type);
#define RCVBUF_INIT_LEN 1024
#define RCVBUF_MAX_PREALLOC (1<<20) /* 1MB */
+/* Cluster nodes hash table, mapping nodes addresses 1.2.3.4:6379 to
+ * clusterNode structures. */
+dictType clusterNodesDictType = {
+ dictSdsHash, /* hash function */
+ NULL, /* key dup */
+ NULL, /* val dup */
+ dictSdsKeyCompare, /* key compare */
+ dictSdsDestructor, /* key destructor */
+ NULL, /* val destructor */
+ NULL /* allow to expand */
+};
+
+/* 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 */
+ NULL /* allow to expand */
+};
+
/* -----------------------------------------------------------------------------
* Initialization
* -------------------------------------------------------------------------- */
diff --git a/src/cluster.h b/src/cluster.h
index f476a50a0..890cd788a 100644
--- a/src/cluster.h
+++ b/src/cluster.h
@@ -15,8 +15,6 @@
* multiplicators of the node timeout value (when ending with MULT). */
#define CLUSTER_FAIL_REPORT_VALIDITY_MULT 2 /* Fail report validity. */
#define CLUSTER_FAIL_UNDO_TIME_MULT 2 /* Undo fail if master is back. */
-#define CLUSTER_FAIL_UNDO_TIME_ADD 10 /* Some additional time. */
-#define CLUSTER_FAILOVER_DELAY 5 /* Seconds */
#define CLUSTER_MF_TIMEOUT 5000 /* Milliseconds to do a manual failover. */
#define CLUSTER_MF_PAUSE_MULT 2 /* Master pause manual failover mult. */
#define CLUSTER_SLAVE_MIGRATION_DELAY 5000 /* Delay for slave migration. */
@@ -288,9 +286,18 @@ typedef struct {
master is up. */
/* ---------------------- API exported outside cluster.c -------------------- */
+void clusterInit(void);
+void clusterCron(void);
+void clusterBeforeSleep(void);
clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, int argc, int *hashslot, int *ask);
+clusterNode *clusterLookupNode(const char *name);
int clusterRedirectBlockedClientIfNeeded(client *c);
void clusterRedirectClient(client *c, clusterNode *n, int hashslot, int error_code);
+void migrateCloseTimedoutSockets(void);
+int verifyClusterConfigWithData(void);
unsigned long getClusterConnectionsCount(void);
+int clusterSendModuleMessageToTarget(const char *target, uint64_t module_id, uint8_t type, unsigned char *payload, uint32_t len);
+void clusterPropagatePublish(robj *channel, robj *message);
+unsigned int keyHashSlot(char *key, int keylen);
#endif /* __CLUSTER_H */
diff --git a/src/config.c b/src/config.c
index ed1f81fd4..df29be2b8 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1058,9 +1058,6 @@ void configGetCommand(client *c) {
/* We use the following dictionary type to store where a configuration
* option is mentioned in the old configuration file, so it's
* like "maxmemory" -> list of line numbers (first line is zero). */
-uint64_t dictSdsCaseHash(const void *key);
-int dictSdsKeyCaseCompare(void *privdata, const void *key1, const void *key2);
-void dictSdsDestructor(void *privdata, void *val);
void dictListDestructor(void *privdata, void *val);
/* Sentinel config rewriting is implemented inside sentinel.c by
diff --git a/src/module.c b/src/module.c
index e04a60b48..fd2f69948 100644
--- a/src/module.c
+++ b/src/module.c
@@ -6125,8 +6125,6 @@ size_t RM_GetClusterSize(void) {
return dictSize(server.cluster->nodes);
}
-clusterNode *clusterLookupNode(const char *name); /* We need access to internals */
-
/* Populate the specified info for the node having as ID the specified 'id',
* then returns REDISMODULE_OK. Otherwise if the node ID does not exist from
* the POV of this local node, REDISMODULE_ERR is returned.
diff --git a/src/pubsub.c b/src/pubsub.c
index 6d58e1b89..0169b3604 100644
--- a/src/pubsub.c
+++ b/src/pubsub.c
@@ -28,6 +28,7 @@
*/
#include "server.h"
+#include "cluster.h"
int clientSubscriptionsCount(client *c);
diff --git a/src/sentinel.c b/src/sentinel.c
index 060e499ad..473174cf1 100644
--- a/src/sentinel.c
+++ b/src/sentinel.c
@@ -404,10 +404,6 @@ void sentinelSimFailureCrash(void);
/* ========================= Dictionary types =============================== */
-uint64_t dictSdsHash(const void *key);
-uint64_t dictSdsCaseHash(const void *key);
-int dictSdsKeyCompare(void *privdata, const void *key1, const void *key2);
-int dictSdsKeyCaseCompare(void *privdata, const void *key1, const void *key2);
void releaseSentinelRedisInstance(sentinelRedisInstance *ri);
void dictInstancesValDestructor (void *privdata, void *obj) {
diff --git a/src/server.c b/src/server.c
index a2fb20c0e..53af65235 100644
--- a/src/server.c
+++ b/src/server.c
@@ -1499,31 +1499,6 @@ dictType keylistDictType = {
NULL /* allow to expand */
};
-/* Cluster nodes hash table, mapping nodes addresses 1.2.3.4:6379 to
- * clusterNode structures. */
-dictType clusterNodesDictType = {
- dictSdsHash, /* hash function */
- NULL, /* key dup */
- NULL, /* val dup */
- dictSdsKeyCompare, /* key compare */
- dictSdsDestructor, /* key destructor */
- NULL, /* val destructor */
- NULL /* allow to expand */
-};
-
-/* 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 */
- NULL /* allow to expand */
-};
-
/* Modules system dictionary type. Keys are module name,
* values are pointer to RedisModule struct. */
dictType modulesDictType = {
diff --git a/src/server.h b/src/server.h
index 23bd4a762..367a6d0bc 100644
--- a/src/server.h
+++ b/src/server.h
@@ -1178,8 +1178,6 @@ typedef struct redisTLSContextConfig {
* Global server state
*----------------------------------------------------------------------------*/
-struct clusterState;
-
/* AIX defines hz to __hz, we don't use this define and in order to allow
* Redis build on AIX we need to undef it. */
#ifdef _AIX
@@ -1774,8 +1772,6 @@ extern dictType objectKeyPointerValueDictType;
extern dictType objectKeyHeapPointerValueDictType;
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;
@@ -2400,7 +2396,6 @@ void signalFlushedDb(int dbid, int async);
unsigned int getKeysInSlot(unsigned int hashslot, robj **keys, unsigned int count);
unsigned int countKeysInSlot(unsigned int hashslot);
unsigned int delKeysInSlot(unsigned int hashslot);
-int verifyClusterConfigWithData(void);
void scanGenericCommand(client *c, robj *o, unsigned long cursor);
int parseScanCursorOrReply(client *c, robj *o, unsigned long *cursor);
void slotToKeyAdd(sds key);
@@ -2430,15 +2425,7 @@ int xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult
int memoryGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result);
int lcsGetKeys(struct redisCommand *cmd, robj **argv, int argc, getKeysResult *result);
-/* Cluster */
-void clusterInit(void);
unsigned short crc16(const char *buf, int len);
-unsigned int keyHashSlot(char *key, int keylen);
-void clusterCron(void);
-void clusterPropagatePublish(robj *channel, robj *message);
-void migrateCloseTimedoutSockets(void);
-void clusterBeforeSleep(void);
-int clusterSendModuleMessageToTarget(const char *target, uint64_t module_id, uint8_t type, unsigned char *payload, uint32_t len);
/* Sentinel */
void initSentinelConfig(void);
@@ -2503,7 +2490,9 @@ int performEvictions(void);
/* Keys hashing / comparison functions for dict.c hash tables. */
uint64_t dictSdsHash(const void *key);
+uint64_t dictSdsCaseHash(const void *key);
int dictSdsKeyCompare(void *privdata, const void *key1, const void *key2);
+int dictSdsKeyCaseCompare(void *privdata, const void *key1, const void *key2);
void dictSdsDestructor(void *privdata, void *val);
/* Git SHA1 */
diff --git a/src/t_zset.c b/src/t_zset.c
index 333e0221e..08c00909a 100644
--- a/src/t_zset.c
+++ b/src/t_zset.c
@@ -2537,9 +2537,6 @@ static void zdiff(zsetopsrc *src, long setnum, zset *dstzset, size_t *maxelelen)
}
}
-uint64_t dictSdsHash(const void *key);
-int dictSdsKeyCompare(void *privdata, const void *key1, const void *key2);
-
dictType setAccumulatorDictType = {
dictSdsHash, /* hash function */
NULL, /* key dup */