-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache CLUSTER SLOTS response for improving throughput and reduced lat…
…ency. (#53) This commit adds a logic to cache `CLUSTER SLOTS` response for reduced latency and also updates the cache when a change in the cluster is detected. Historically, `CLUSTER SLOTS` command was deprecated, however all the server clients have been using `CLUSTER SLOTS` and have not migrated to `CLUSTER SHARDS`. In future this logic can be added to any other commands to improve the performance of the engine. --------- Signed-off-by: Roshan Khatri <[email protected]>
- Loading branch information
1 parent
7253862
commit c478206
Showing
12 changed files
with
180 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -762,6 +762,7 @@ void clusterSaveConfigOrDie(int do_fsync) { | |
serverLog(LL_WARNING,"Fatal: can't update cluster config file."); | ||
exit(1); | ||
} | ||
clearCachedClusterSlotsResponse(); | ||
} | ||
|
||
/* Lock the cluster config using flock(), and retain the file descriptor used to | ||
|
@@ -1039,6 +1040,9 @@ void clusterInit(void) { | |
|
||
server.cluster->mf_end = 0; | ||
server.cluster->mf_slave = NULL; | ||
for (connTypeForCaching conn_type = CACHE_CONN_TCP; conn_type < CACHE_CONN_TYPE_MAX; conn_type++) { | ||
server.cached_cluster_slot_info[conn_type] = NULL; | ||
} | ||
resetManualFailover(); | ||
clusterUpdateMyselfFlags(); | ||
clusterUpdateMyselfIp(); | ||
|
@@ -1363,6 +1367,7 @@ clusterNode *createClusterNode(char *nodename, int flags) { | |
node->repl_offset_time = 0; | ||
node->repl_offset = 0; | ||
listSetFreeMethod(node->fail_reports,zfree); | ||
node->is_node_healthy = 0; | ||
return node; | ||
} | ||
|
||
|
@@ -5862,6 +5867,14 @@ void clusterUpdateSlots(client *c, unsigned char *slots, int del) { | |
} | ||
} | ||
|
||
long long getNodeReplicationOffset(clusterNode *node) { | ||
if (node->flags & CLUSTER_NODE_MYSELF) { | ||
return nodeIsSlave(node) ? replicationGetSlaveOffset() : server.master_repl_offset; | ||
} else { | ||
return node->repl_offset; | ||
} | ||
} | ||
|
||
/* Add detailed information of a node to the output buffer of the given client. */ | ||
void addNodeDetailsToShardReply(client *c, clusterNode *node) { | ||
int reply_count = 0; | ||
|
@@ -5896,12 +5909,7 @@ void addNodeDetailsToShardReply(client *c, clusterNode *node) { | |
reply_count++; | ||
} | ||
|
||
long long node_offset; | ||
if (node->flags & CLUSTER_NODE_MYSELF) { | ||
node_offset = nodeIsSlave(node) ? replicationGetSlaveOffset() : server.master_repl_offset; | ||
} else { | ||
node_offset = node->repl_offset; | ||
} | ||
long long node_offset = getNodeReplicationOffset(node); | ||
|
||
addReplyBulkCString(c, "role"); | ||
addReplyBulkCString(c, nodeIsSlave(node) ? "replica" : "master"); | ||
|
@@ -6882,9 +6890,26 @@ void clusterPromoteSelfToMaster(void) { | |
replicationUnsetMaster(); | ||
} | ||
|
||
int detectAndUpdateCachedNodeHealth(void) { | ||
dictIterator di; | ||
dictInitSafeIterator(&di, server.cluster->nodes); | ||
dictEntry *de; | ||
clusterNode *node; | ||
int overall_health_changed = 0; | ||
while((de = dictNext(&di)) != NULL) { | ||
node = dictGetVal(de); | ||
int present_is_node_healthy = isNodeAvailable(node); | ||
if (present_is_node_healthy != node->is_node_healthy) { | ||
overall_health_changed = 1; | ||
node->is_node_healthy = present_is_node_healthy; | ||
} | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
madolson
Member
|
||
return overall_health_changed; | ||
} | ||
|
||
/* Replicate migrating and importing slot states to all replicas */ | ||
void clusterReplicateOpenSlots(void) | ||
{ | ||
void clusterReplicateOpenSlots(void) { | ||
if (!server.cluster_enabled) return; | ||
|
||
int argc = 5; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
I came to know that if we use stack based iterator, we need to invoke
dictResetIterator
so that rehashing on the dictionary is reenabled after the iteration.valkey/src/dict.c
Lines 960 to 967 in 54c9747
@roshkhatri @madolson