Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 26 additions & 3 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,11 @@ static void updateAnnouncedHostname(clusterNode *node, char *value) {
}

static void updateAnnouncedHumanNodename(clusterNode *node, char *value) {
updateSdsExtensionField(&node->human_nodename, value);
/* We should only update the human nodename when the provided new
* value isn't NULL, otherwise the following function will clear
* the human nodename field. */
if (value != NULL)
updateSdsExtensionField(&node->human_nodename, value);
}

static void updateAnnouncedClientIpV4(clusterNode *node, char *value) {
Expand Down Expand Up @@ -1284,6 +1288,13 @@ static void updateShardId(clusterNode *node, const char *shard_id) {
}
}

static void updateHumanNodenameToAddress(clusterNode *node) {
const int port = server.tls_cluster ? node->tls_port : node->tcp_port;
char buf[64];
snprintf(buf, sizeof(buf), "%s:%d", node->ip, port);
updateAnnouncedHumanNodename(node, buf);
}

static inline int areInSameShard(clusterNode *node1, clusterNode *node2) {
return memcmp(node1->shard_id, node2->shard_id, CLUSTER_NAMELEN) == 0;
}
Expand Down Expand Up @@ -1408,7 +1419,18 @@ void clusterInit(void) {
clusterUpdateMyselfClientIpV4();
clusterUpdateMyselfClientIpV6();
clusterUpdateMyselfHostname();
clusterUpdateMyselfHumanNodename();
/* Assigning human-readable nodename at start-up makes it much
* easier to read the server logs. By default, a server doesn't
* have a human-readable nodename unless explicitly assigned by
* CONFIG SET command or config file edit, so we simply use
* the server's IP and port as the nodename. This name will be
* carried in the PING extension so that all nodes in the cluster
* will know this name eventually. */
if (server.cluster_announce_human_nodename != NULL &&
server.cluster_announce_human_nodename[0] != '\0')
clusterUpdateMyselfHumanNodename();
else
updateHumanNodenameToAddress(myself);
resetClusterStats();
}

Expand Down Expand Up @@ -3746,6 +3768,7 @@ int clusterProcessPacket(clusterLink *link) {
memcpy(myself->ip, ip, NET_IP_STR_LEN);
serverLog(LL_NOTICE, "IP address for this node updated to %s", myself->ip);
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG);
updateHumanNodenameToAddress(myself);
}
}

Expand Down Expand Up @@ -5823,7 +5846,7 @@ void clusterCron(void) {
long long cluster_node_conn_attempts = maxConnectionAttemptsPerCron();
while ((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetVal(de);
/* We free the inbound or outboud link to the node if the link has an
/* We free the inbound or outbound link to the node if the link has an
* oversized message send queue and immediately try reconnecting. */
clusterNodeCronFreeLinkOnBufferLimitReached(node);
/* The protocol is that function(s) below return non-zero if the node was
Expand Down
2 changes: 1 addition & 1 deletion tests/support/util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ proc verify_log_message {srv_idx pattern from_line} {
incr from_line
set result [exec tail -n +$from_line < [srv $srv_idx stdout]]
if {![string match $pattern $result]} {
fail "expected message not found in log file: $pattern"
fail "expected pattern found in log file: $pattern, but instead got: $result"
}
}

Expand Down
13 changes: 8 additions & 5 deletions tests/unit/cluster/manual-failover.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ start_cluster 3 1 {tags {external:skip cluster}} {
set R2_nodeid [R 2 cluster myid]
set R3_nodeid [R 3 cluster myid]

set R0_port [srv 0 port]
set R3_port [srv -3 port]

set R0_shardid [R 0 cluster myshardid]
set R3_shardid [R 3 cluster myshardid]
assert_equal $R0_shardid $R3_shardid
Expand Down Expand Up @@ -478,21 +481,21 @@ start_cluster 3 1 {tags {external:skip cluster}} {
# verify we print the logs.

# Both importing slots and migrating slots are move to R3.
set pattern "*Failover occurred in migration source. Update importing source for slot 0 to node $R3_nodeid () in shard $R3_shardid*"
set pattern "*Failover occurred in migration source. Update importing source for slot 0 to node $R3_nodeid (127.0.0.1:$R3_port) in shard $R3_shardid*"
verify_log_message -1 $pattern $loglines1
set pattern "*Failover occurred in migration target. Slot 5462 is now being migrated to node $R3_nodeid () in shard $R3_shardid*"
set pattern "*Failover occurred in migration target. Slot 5462 is now being migrated to node $R3_nodeid (127.0.0.1:$R3_port) in shard $R3_shardid*"
verify_log_message -1 $pattern $loglines1

# Both slots are move to R3.
set R0_slots 5462
set pattern "*A failover occurred in shard $R3_shardid; node $R0_nodeid () lost $R0_slots slot(s) and failed over to node $R3_nodeid*"
set pattern "*A failover occurred in shard $R3_shardid; node $R0_nodeid (127.0.0.1:$R0_port) lost $R0_slots slot(s) and failed over to node $R3_nodeid*"
verify_log_message -1 $pattern $loglines1
verify_log_message -2 $pattern $loglines2

# Both importing slots and migrating slots are move to R3.
set pattern "*A failover occurred in migration source. Update importing source of 1 slot(s) to node $R3_nodeid () in shard $R3_shardid*"
set pattern "*A failover occurred in migration source. Update importing source of 1 slot(s) to node $R3_nodeid (127.0.0.1:$R3_port) in shard $R3_shardid*"
verify_log_message -1 $pattern $loglines1
set pattern "*A failover occurred in migration target. Update migrating target of 1 slot(s) to node $R3_nodeid () in shard $R3_shardid*"
set pattern "*A failover occurred in migration target. Update migrating target of 1 slot(s) to node $R3_nodeid (127.0.0.1:$R3_port) in shard $R3_shardid*"
verify_log_message -1 $pattern $loglines1

R 1 debug disable-cluster-reconnection 0
Expand Down
Loading