Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dual stack and client-specific IPs in cluster #736

Merged
merged 23 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
adbda42
Add cluster-announce-client-ipv4 and -ipv6 configs and ping extensions
zuiderkwast Jun 19, 2024
ad0c90a
Add IPv6 dimention to cached cluster slots response array
zuiderkwast Jun 28, 2024
3ef550e
Use announced client IPs in replies to clients
zuiderkwast Jul 1, 2024
a27a636
Tests for cluster-announce-client-ipv{4,6}
zuiderkwast Jul 1, 2024
680fa72
Fix IPv6 detection for fake client for cached cluster slots
zuiderkwast Jul 2, 2024
9bd9ba2
Fix tests
zuiderkwast Jul 2, 2024
e1faa79
Fix for CLUSTER SHARDS
zuiderkwast Jul 2, 2024
c094bf9
clang-format
zuiderkwast Jul 2, 2024
2028743
Add tests for CLUSTER SHARDS and CLUSTER NODES
zuiderkwast Jul 2, 2024
9e0d05d
Refactor tests and add tag 'ipv6' to allow skipping when not available
zuiderkwast Jul 2, 2024
0d9aa22
Fix example in conf file
zuiderkwast Jul 4, 2024
16c382c
Fix review comments, change int to size_t in setter (it's what it's c…
zuiderkwast Jul 5, 2024
3d50b87
Add CONFIG SET validation of IPv4 and IPv6
zuiderkwast Jul 5, 2024
a3b364a
Rename variables client_ipvN => announce_client_ipvN
zuiderkwast Jul 5, 2024
8b3afcb
clang-format
zuiderkwast Jul 5, 2024
fa1a7a7
More ClientIp -> AnnounceClintIp
zuiderkwast Jul 7, 2024
1e2a38e
Code dedup
zuiderkwast Jul 7, 2024
234d223
Dedup code for write ping ext
zuiderkwast Jul 7, 2024
32516b4
clang-format
zuiderkwast Jul 7, 2024
4c3e7da
Add VM_GetClusterNodeInfoForClient
zuiderkwast Jul 7, 2024
8cc52a2
Fix compile errors in module.c
zuiderkwast Jul 7, 2024
0c6f140
Add cluster-announce-client-ipv4 example
zuiderkwast Jul 7, 2024
7e237fc
Full uppercase in macros
zuiderkwast Jul 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ int verifyClusterNodeId(const char *name, int length) {
}

int isValidAuxChar(int c) {
return isalnum(c) || (strchr("!#$%&()*+:;<>?@[]^{|}~", c) == NULL);
return isalnum(c) || (strchr("!#$%&()*+.:;<>?@[]^{|}~", c) == NULL);
}

int isValidAuxString(char *s, unsigned int length) {
Expand Down Expand Up @@ -1194,7 +1194,7 @@ void clusterRedirectClient(client *c, clusterNode *n, int hashslot, int error_co
int port = clusterNodeClientPort(n, shouldReturnTlsInfo());
addReplyErrorSds(c,
sdscatprintf(sdsempty(), "-%s %d %s:%d", (error_code == CLUSTER_REDIR_ASK) ? "ASK" : "MOVED",
hashslot, clusterNodePreferredEndpoint(n), port));
hashslot, clusterNodePreferredEndpoint(n, c), port));
} else {
serverPanic("getNodeByQuery() unknown error.");
}
Expand Down Expand Up @@ -1267,7 +1267,7 @@ void addNodeToNodeReply(client *c, clusterNode *node) {
char *hostname = clusterNodeHostname(node);
addReplyArrayLen(c, 4);
if (server.cluster_preferred_endpoint_type == CLUSTER_ENDPOINT_TYPE_IP) {
addReplyBulkCString(c, clusterNodeIp(node));
addReplyBulkCString(c, clusterNodeIp(node, c));
} else if (server.cluster_preferred_endpoint_type == CLUSTER_ENDPOINT_TYPE_HOSTNAME) {
if (hostname != NULL && hostname[0] != '\0') {
addReplyBulkCString(c, hostname);
Expand Down Expand Up @@ -1300,7 +1300,7 @@ void addNodeToNodeReply(client *c, clusterNode *node) {

if (server.cluster_preferred_endpoint_type != CLUSTER_ENDPOINT_TYPE_IP) {
addReplyBulkCString(c, "ip");
addReplyBulkCString(c, clusterNodeIp(node));
addReplyBulkCString(c, clusterNodeIp(node, c));
length--;
}
if (server.cluster_preferred_endpoint_type != CLUSTER_ENDPOINT_TYPE_HOSTNAME && hostname != NULL &&
Expand Down Expand Up @@ -1353,12 +1353,10 @@ void addNodeReplyForClusterSlot(client *c, clusterNode *node, int start_slot, in
}

void clearCachedClusterSlotsResponse(void) {
for (connTypeForCaching conn_type = CACHE_CONN_TCP; conn_type < CACHE_CONN_TYPE_MAX; conn_type++) {
for (int resp = 0; resp <= 3; resp++) {
if (server.cached_cluster_slot_info[conn_type][resp]) {
sdsfree(server.cached_cluster_slot_info[conn_type][resp]);
server.cached_cluster_slot_info[conn_type][resp] = NULL;
}
for (int conn_type = 0; conn_type < CACHE_CONN_TYPE_MAX; conn_type++) {
if (server.cached_cluster_slot_info[conn_type]) {
sdsfree(server.cached_cluster_slot_info[conn_type]);
server.cached_cluster_slot_info[conn_type] = NULL;
}
}
}
Expand Down Expand Up @@ -1415,14 +1413,17 @@ void clusterCommandSlots(client *c) {
* 3) node ID
* ... continued until done
*/
connTypeForCaching conn_type = shouldReturnTlsInfo();
int conn_type = 0;
if (connIsTLS(c->conn)) conn_type |= CACHE_CONN_TYPE_TLS;
if (isClientConnIpV6(c)) conn_type |= CACHE_CONN_TYPE_IPv6;
if (c->resp == 3) conn_type |= CACHE_CONN_TYPE_RESP3;

if (detectAndUpdateCachedNodeHealth()) clearCachedClusterSlotsResponse();

sds cached_reply = server.cached_cluster_slot_info[conn_type][c->resp];
sds cached_reply = server.cached_cluster_slot_info[conn_type];
if (!cached_reply) {
cached_reply = generateClusterSlotResponse(c->resp);
server.cached_cluster_slot_info[conn_type][c->resp] = cached_reply;
server.cached_cluster_slot_info[conn_type] = cached_reply;
} else {
debugServerAssertWithInfo(c, NULL, verifyCachedClusterSlotsResponse(cached_reply, c->resp) == 1);
}
Expand Down
6 changes: 4 additions & 2 deletions src/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ int clusterSendModuleMessageToTarget(const char *target,

void clusterUpdateMyselfFlags(void);
void clusterUpdateMyselfIp(void);
void clusterUpdateMyselfClientIpV4(void);
void clusterUpdateMyselfClientIpV6(void);
void clusterUpdateMyselfHostname(void);
void clusterUpdateMyselfAnnouncedPorts(void);
void clusterUpdateMyselfHumanNodename(void);
Expand Down Expand Up @@ -85,7 +87,7 @@ int handleDebugClusterCommand(client *c);
int clusterNodePending(clusterNode *node);
int clusterNodeIsPrimary(clusterNode *n);
char **getClusterNodesList(size_t *numnodes);
char *clusterNodeIp(clusterNode *node);
char *clusterNodeIp(clusterNode *node, client *c);
int clusterNodeIsReplica(clusterNode *node);
clusterNode *clusterNodeGetPrimary(clusterNode *node);
char *clusterNodeGetName(clusterNode *node);
Expand All @@ -100,7 +102,7 @@ clusterNode *getImportingSlotSource(int slot);
clusterNode *getNodeBySlot(int slot);
int clusterNodeClientPort(clusterNode *n, int use_tls);
char *clusterNodeHostname(clusterNode *node);
const char *clusterNodePreferredEndpoint(clusterNode *n);
const char *clusterNodePreferredEndpoint(clusterNode *n, client *c);
long long clusterNodeReplOffset(clusterNode *node);
clusterNode *clusterLookupNode(const char *name, int length);
int detectAndUpdateCachedNodeHealth(void);
Expand Down
Loading
Loading