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

Function createSentinelRedisInstance

src/sentinel.cpp:1295–1385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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