MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / sentinelSendHello

Function sentinelSendHello

src/sentinel.cpp:3002–3042  ·  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

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

Callers 1

Calls 5

anetFdToStringFunction · 0.85
announceSentinelAddrFunction · 0.85
redisAsyncCommandFunction · 0.85

Tested by

no test coverage detected