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

Function createSentinelRedisInstance

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

Source from the content-addressed store, hash-verified

1287 * with the same ID already exists. */
1288
1289sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char *hostname, int port, int quorum, sentinelRedisInstance *master) {
1290 sentinelRedisInstance *ri;
1291 sentinelAddr *addr;
1292 dict *table = NULL;
1293 sds sdsname;
1294
1295 serverAssert(flags & (SRI_MASTER|SRI_SLAVE|SRI_SENTINEL));
1296 serverAssert((flags & SRI_MASTER) || master != NULL);
1297
1298 /* Check address validity. */
1299 addr = createSentinelAddr(hostname,port);
1300 if (addr == NULL) return NULL;
1301
1302 /* For slaves use ip/host:port as name. */
1303 if (flags & SRI_SLAVE)
1304 sdsname = announceSentinelAddrAndPort(addr);
1305 else
1306 sdsname = sdsnew(name);
1307
1308 /* Make sure the entry is not duplicated. This may happen when the same
1309 * name for a master is used multiple times inside the configuration or
1310 * if we try to add multiple times a slave or sentinel with same ip/port
1311 * to a master. */
1312 if (flags & SRI_MASTER) table = sentinel.masters;
1313 else if (flags & SRI_SLAVE) table = master->slaves;
1314 else if (flags & SRI_SENTINEL) table = master->sentinels;
1315 if (dictFind(table,sdsname)) {
1316 releaseSentinelAddr(addr);
1317 sdsfree(sdsname);
1318 errno = EBUSY;
1319 return NULL;
1320 }
1321
1322 /* Create the instance object. */
1323 ri = zmalloc(sizeof(*ri));
1324 /* Note that all the instances are started in the disconnected state,
1325 * the event loop will take care of connecting them. */
1326 ri->flags = flags;
1327 ri->name = sdsname;
1328 ri->runid = NULL;
1329 ri->config_epoch = 0;
1330 ri->addr = addr;
1331 ri->link = createInstanceLink();
1332 ri->last_pub_time = mstime();
1333 ri->last_hello_time = mstime();
1334 ri->last_master_down_reply_time = mstime();
1335 ri->s_down_since_time = 0;
1336 ri->o_down_since_time = 0;
1337 ri->down_after_period = master ? master->down_after_period :
1338 SENTINEL_DEFAULT_DOWN_AFTER;
1339 ri->master_link_down_time = 0;
1340 ri->auth_pass = NULL;
1341 ri->auth_user = NULL;
1342 ri->slave_priority = SENTINEL_DEFAULT_SLAVE_PRIORITY;
1343 ri->replica_announced = 1;
1344 ri->slave_reconf_sent_time = 0;
1345 ri->slave_master_host = NULL;
1346 ri->slave_master_port = 0;

Callers 5

sentinelCommandFunction · 0.85

Calls 11

createSentinelAddrFunction · 0.85
sdsnewFunction · 0.85
releaseSentinelAddrFunction · 0.85
sdsfreeFunction · 0.85
zmallocFunction · 0.85
createInstanceLinkFunction · 0.85
dictFindFunction · 0.70
mstimeFunction · 0.70
dictCreateFunction · 0.70
dictAddFunction · 0.70

Tested by

no test coverage detected