"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/sentinel.c" between
redis-6.2-rc3.tar.gz and redis-6.2.0.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

sentinel.c  (redis-6.2-rc3):sentinel.c  (redis-6.2.0)
skipping to change at line 652 skipping to change at line 652
if (anetResolve(NULL, hostname, ip, sizeof(ip), if (anetResolve(NULL, hostname, ip, sizeof(ip),
sentinel.resolve_hostnames ? ANET_NONE : ANET_IP_ONLY) == AN ET_ERR) sentinel.resolve_hostnames ? ANET_NONE : ANET_IP_ONLY) == AN ET_ERR)
return 0; return 0;
return !strcasecmp(a->ip, ip); return !strcasecmp(a->ip, ip);
} }
const char *announceSentinelAddr(const sentinelAddr *a) { const char *announceSentinelAddr(const sentinelAddr *a) {
return sentinel.announce_hostnames ? a->hostname : a->ip; return sentinel.announce_hostnames ? a->hostname : a->ip;
} }
/* Return an allocated sds with hostname/address:port. IPv6
* addresses are bracketed the same way anetFormatAddr() does.
*/
sds announceSentinelAddrAndPort(const sentinelAddr *a) {
const char *addr = announceSentinelAddr(a);
if (strchr(addr, ':') != NULL)
return sdscatprintf(sdsempty(), "[%s]:%d", addr, a->port);
else
return sdscatprintf(sdsempty(), "%s:%d", addr, a->port);
}
/* =========================== Events notification ========================== */ /* =========================== Events notification ========================== */
/* Send an event to log, pub/sub, user notification script. /* Send an event to log, pub/sub, user notification script.
* *
* 'level' is the log level for logging. Only LL_WARNING events will trigger * 'level' is the log level for logging. Only LL_WARNING events will trigger
* the execution of the user notification script. * the execution of the user notification script.
* *
* 'type' is the message type, also used as a pub/sub channel name. * 'type' is the message type, also used as a pub/sub channel name.
* *
* 'ri', is the redis instance target of this event if applicable, and is * 'ri', is the redis instance target of this event if applicable, and is
skipping to change at line 1276 skipping to change at line 1287
* createSentinelAddr() function. * createSentinelAddr() function.
* *
* The function may also fail and return NULL with errno set to EBUSY if * The function may also fail and return NULL with errno set to EBUSY if
* a master with the same name, a slave with the same address, or a sentinel * a master with the same name, a slave with the same address, or a sentinel
* with the same ID already exists. */ * with the same ID already exists. */
sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char * hostname, int port, int quorum, sentinelRedisInstance *master) { sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char * hostname, int port, int quorum, sentinelRedisInstance *master) {
sentinelRedisInstance *ri; sentinelRedisInstance *ri;
sentinelAddr *addr; sentinelAddr *addr;
dict *table = NULL; dict *table = NULL;
char slavename[NET_ADDR_STR_LEN], *sdsname; sds sdsname;
serverAssert(flags & (SRI_MASTER|SRI_SLAVE|SRI_SENTINEL)); serverAssert(flags & (SRI_MASTER|SRI_SLAVE|SRI_SENTINEL));
serverAssert((flags & SRI_MASTER) || master != NULL); serverAssert((flags & SRI_MASTER) || master != NULL);
/* Check address validity. */ /* Check address validity. */
addr = createSentinelAddr(hostname,port); addr = createSentinelAddr(hostname,port);
if (addr == NULL) return NULL; if (addr == NULL) return NULL;
/* For slaves use ip:port as name. */ /* For slaves use ip/host:port as name. */
if (flags & SRI_SLAVE) { if (flags & SRI_SLAVE)
anetFormatAddr(slavename, sizeof(slavename), addr->ip, port); sdsname = announceSentinelAddrAndPort(addr);
name = slavename; else
} sdsname = sdsnew(name);
/* Make sure the entry is not duplicated. This may happen when the same /* Make sure the entry is not duplicated. This may happen when the same
* name for a master is used multiple times inside the configuration or * name for a master is used multiple times inside the configuration or
* if we try to add multiple times a slave or sentinel with same ip/port * if we try to add multiple times a slave or sentinel with same ip/port
* to a master. */ * to a master. */
if (flags & SRI_MASTER) table = sentinel.masters; if (flags & SRI_MASTER) table = sentinel.masters;
else if (flags & SRI_SLAVE) table = master->slaves; else if (flags & SRI_SLAVE) table = master->slaves;
else if (flags & SRI_SENTINEL) table = master->sentinels; else if (flags & SRI_SENTINEL) table = master->sentinels;
sdsname = sdsnew(name);
if (dictFind(table,sdsname)) { if (dictFind(table,sdsname)) {
releaseSentinelAddr(addr); releaseSentinelAddr(addr);
sdsfree(sdsname); sdsfree(sdsname);
errno = EBUSY; errno = EBUSY;
return NULL; return NULL;
} }
/* Create the instance object. */ /* Create the instance object. */
ri = zmalloc(sizeof(*ri)); ri = zmalloc(sizeof(*ri));
/* Note that all the instances are started in the disconnected state, /* Note that all the instances are started in the disconnected state,
skipping to change at line 1402 skipping to change at line 1412
zfree(ri); zfree(ri);
} }
/* Lookup a slave in a master Redis instance, by ip and port. */ /* Lookup a slave in a master Redis instance, by ip and port. */
sentinelRedisInstance *sentinelRedisInstanceLookupSlave( sentinelRedisInstance *sentinelRedisInstanceLookupSlave(
sentinelRedisInstance *ri, char *slave_addr, int port) sentinelRedisInstance *ri, char *slave_addr, int port)
{ {
sds key; sds key;
sentinelRedisInstance *slave; sentinelRedisInstance *slave;
char buf[NET_ADDR_STR_LEN];
sentinelAddr *addr; sentinelAddr *addr;
serverAssert(ri->flags & SRI_MASTER); serverAssert(ri->flags & SRI_MASTER);
/* We need to handle a slave_addr that is potentially a hostname. /* We need to handle a slave_addr that is potentially a hostname.
* If that is the case, depending on configuration we either resolve * If that is the case, depending on configuration we either resolve
* it and use the IP addres or fail. * it and use the IP addres or fail.
*/ */
addr = createSentinelAddr(slave_addr, port); addr = createSentinelAddr(slave_addr, port);
if (!addr) return NULL; if (!addr) return NULL;
key = announceSentinelAddrAndPort(addr);
anetFormatAddr(buf,sizeof(buf),addr->ip,addr->port);
releaseSentinelAddr(addr); releaseSentinelAddr(addr);
key = sdsnew(buf);
slave = dictFetchValue(ri->slaves,key); slave = dictFetchValue(ri->slaves,key);
sdsfree(key); sdsfree(key);
return slave; return slave;
} }
/* Return the name of the type of the instance as a string. */ /* Return the name of the type of the instance as a string. */
const char *sentinelRedisInstanceTypeStr(sentinelRedisInstance *ri) { const char *sentinelRedisInstanceTypeStr(sentinelRedisInstance *ri) {
if (ri->flags & SRI_MASTER) return "master"; if (ri->flags & SRI_MASTER) return "master";
else if (ri->flags & SRI_SLAVE) return "slave"; else if (ri->flags & SRI_SLAVE) return "slave";
else if (ri->flags & SRI_SENTINEL) return "sentinel"; else if (ri->flags & SRI_SENTINEL) return "sentinel";
skipping to change at line 2080 skipping to change at line 2087
sentinel.deny_scripts_reconfig ? "yes" : "no"); sentinel.deny_scripts_reconfig ? "yes" : "no");
rewriteConfigRewriteLine(state,"sentinel deny-scripts-reconfig",line, rewriteConfigRewriteLine(state,"sentinel deny-scripts-reconfig",line,
sentinel.deny_scripts_reconfig != SENTINEL_DEFAULT_DENY_SCRIPTS_RECONFIG ); sentinel.deny_scripts_reconfig != SENTINEL_DEFAULT_DENY_SCRIPTS_RECONFIG );
/* sentinel resolve-hostnames. /* sentinel resolve-hostnames.
* This must be included early in the file so it is already in effect * This must be included early in the file so it is already in effect
* when reading the file. * when reading the file.
*/ */
line = sdscatprintf(sdsempty(), "sentinel resolve-hostnames %s", line = sdscatprintf(sdsempty(), "sentinel resolve-hostnames %s",
sentinel.resolve_hostnames ? "yes" : "no"); sentinel.resolve_hostnames ? "yes" : "no");
rewriteConfigRewriteLine(state,"sentinel",line, rewriteConfigRewriteLine(state,"sentinel resolve-hostnames",line,
sentinel.resolve_hostnames != SENTINEL_DEFAULT_RESO LVE_HOSTNAMES); sentinel.resolve_hostnames != SENTINEL_DEFAULT_RESO LVE_HOSTNAMES);
/* sentinel announce-hostnames. */ /* sentinel announce-hostnames. */
line = sdscatprintf(sdsempty(), "sentinel announce-hostnames %s", line = sdscatprintf(sdsempty(), "sentinel announce-hostnames %s",
sentinel.announce_hostnames ? "yes" : "no"); sentinel.announce_hostnames ? "yes" : "no");
rewriteConfigRewriteLine(state,"sentinel",line, rewriteConfigRewriteLine(state,"sentinel announce-hostnames",line,
sentinel.announce_hostnames != SENTINEL_DEFAULT_ANN OUNCE_HOSTNAMES); sentinel.announce_hostnames != SENTINEL_DEFAULT_ANN OUNCE_HOSTNAMES);
/* For every master emit a "sentinel monitor" config entry. */ /* For every master emit a "sentinel monitor" config entry. */
di = dictGetIterator(sentinel.masters); di = dictGetIterator(sentinel.masters);
while((de = dictNext(di)) != NULL) { while((de = dictNext(di)) != NULL) {
sentinelRedisInstance *master, *ri; sentinelRedisInstance *master, *ri;
sentinelAddr *master_addr; sentinelAddr *master_addr;
/* sentinel monitor */ /* sentinel monitor */
master = dictGetVal(de); master = dictGetVal(de);
 End of changes. 9 change blocks. 
13 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)