MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sentinelSendHello

Function sentinelSendHello

app/redis-6.2.6/src/sentinel.c:2990–3030  ·  view source on GitHub ↗

Send a "Hello" message via Pub/Sub to the specified 'ri' Redis * instance in order to broadcast the current configuration for this * master, and to advertise the existence of this Sentinel at the same time. * * The message has the following format: * * sentinel_ip,sentinel_port,sentinel_runid,current_epoch, * master_name,master_ip,master_port,master_config_epoch. * * Returns C_OK if the P

Source from the content-addressed store, hash-verified

2988 * Returns C_OK if the PUBLISH was queued correctly, otherwise
2989 * C_ERR is returned. */
2990int sentinelSendHello(sentinelRedisInstance *ri) {
2991 char ip[NET_IP_STR_LEN];
2992 char payload[NET_IP_STR_LEN+1024];
2993 int retval;
2994 char *announce_ip;
2995 int announce_port;
2996 sentinelRedisInstance *master = (ri->flags & SRI_MASTER) ? ri : ri->master;
2997 sentinelAddr *master_addr = sentinelGetCurrentMasterAddress(master);
2998
2999 if (ri->link->disconnected) return C_ERR;
3000
3001 /* Use the specified announce address if specified, otherwise try to
3002 * obtain our own IP address. */
3003 if (sentinel.announce_ip) {
3004 announce_ip = sentinel.announce_ip;
3005 } else {
3006 if (anetFdToString(ri->link->cc->c.fd,ip,sizeof(ip),NULL,FD_TO_SOCK_NAME) == -1)
3007 return C_ERR;
3008 announce_ip = ip;
3009 }
3010 if (sentinel.announce_port) announce_port = sentinel.announce_port;
3011 else if (server.tls_replication && server.tls_port) announce_port = server.tls_port;
3012 else announce_port = server.port;
3013
3014 /* Format and send the Hello message. */
3015 snprintf(payload,sizeof(payload),
3016 "%s,%d,%s,%llu," /* Info about this sentinel. */
3017 "%s,%s,%d,%llu", /* Info about current master. */
3018 announce_ip, announce_port, sentinel.myid,
3019 (unsigned long long) sentinel.current_epoch,
3020 /* --- */
3021 master->name,announceSentinelAddr(master_addr),master_addr->port,
3022 (unsigned long long) master->config_epoch);
3023 retval = redisAsyncCommand(ri->link->cc,
3024 sentinelPublishReplyCallback, ri, "%s %s %s",
3025 sentinelInstanceMapCommand(ri,"PUBLISH"),
3026 SENTINEL_HELLO_CHANNEL,payload);
3027 if (retval != C_OK) return C_ERR;
3028 ri->link->pending_commands++;
3029 return C_OK;
3030}
3031
3032/* Reset last_pub_time in all the instances in the specified dictionary
3033 * in order to force the delivery of a Hello update ASAP. */

Callers 1

Calls 6

anetFdToStringFunction · 0.85
snprintfFunction · 0.85
announceSentinelAddrFunction · 0.85
redisAsyncCommandFunction · 0.85

Tested by

no test coverage detected