MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / comdb2db_get_dbhosts

Function comdb2db_get_dbhosts

cdb2api/cdb2api.c:5517–5711  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5515}
5516
5517static int comdb2db_get_dbhosts(cdb2_hndl_tp *hndl, const char *comdb2db_name,
5518 int comdb2db_num, const char *host, int port,
5519 char hosts[][CDB2HOSTNAME_LEN], int *num_hosts,
5520 const char *dbname, char *cluster, int *dbnum,
5521 int *num_same_room, int num_retries)
5522{
5523 *dbnum = 0;
5524 int n_bindvars = 3;
5525 const char *sql_query = "select M.name, D.dbnum, M.room from machines M "
5526 "join databases D where M.cluster IN (select "
5527 "cluster_machs from clusters where name=@dbname "
5528 "and cluster_name=@cluster) and D.name=@dbname "
5529 "order by (room = @room) desc";
5530 CDB2SQLQUERY__Bindvalue **bindvars =
5531 malloc(sizeof(CDB2SQLQUERY__Bindvalue *) * n_bindvars);
5532 CDB2SQLQUERY__Bindvalue *bind_dbname =
5533 malloc(sizeof(CDB2SQLQUERY__Bindvalue));
5534 CDB2SQLQUERY__Bindvalue *bind_cluster =
5535 malloc(sizeof(CDB2SQLQUERY__Bindvalue));
5536 CDB2SQLQUERY__Bindvalue *bind_room =
5537 malloc(sizeof(CDB2SQLQUERY__Bindvalue));
5538
5539 cdb2__sqlquery__bindvalue__init(bind_dbname);
5540 cdb2__sqlquery__bindvalue__init(bind_cluster);
5541 cdb2__sqlquery__bindvalue__init(bind_room);
5542
5543 bind_dbname->type = CDB2_CSTRING;
5544 bind_dbname->varname = "dbname";
5545 bind_dbname->value.data = (unsigned char *)dbname;
5546 bind_dbname->value.len = strlen(dbname);
5547
5548 bind_cluster->type = CDB2_CSTRING;
5549 bind_cluster->varname = "cluster";
5550 bind_cluster->value.data = (unsigned char *)cluster;
5551 bind_cluster->value.len = strlen(cluster);
5552
5553 bind_room->type = CDB2_CSTRING;
5554 bind_room->varname = "room";
5555 bind_room->value.data = (unsigned char *)cdb2_machine_room;
5556 bind_room->value.len = strlen(cdb2_machine_room);
5557
5558 bindvars[0] = bind_dbname;
5559 bindvars[1] = bind_cluster;
5560 bindvars[2] = bind_room;
5561 char newsql_typestr[128];
5562 int is_sockfd = 1;
5563 int i = 0;
5564
5565 if (num_same_room)
5566 *num_same_room = 0;
5567
5568 int rc = snprintf(newsql_typestr, sizeof(newsql_typestr),
5569 "comdb2/%s/%s/newsql/%s", comdb2db_name, cluster,
5570 hndl->policy);
5571 if (rc < 1 || rc >= sizeof(newsql_typestr)) {
5572 debugprint(
5573 "ERROR: can not fit entire string 'comdb2/%s/%s/newsql/%s'\n",
5574 comdb2db_name, cluster, hndl->policy);

Callers 1

cdb2_get_dbhostsFunction · 0.85

Calls 11

mallocFunction · 0.85
cdb2_socket_pool_getFunction · 0.85
freeFunction · 0.85
cdb2_send_queryFunction · 0.85
cdb2_read_recordFunction · 0.85
free_eventsFunction · 0.85
cdb2_tcpconnecth_toFunction · 0.70
cdb2portmux_routeFunction · 0.70
send_resetFunction · 0.70

Tested by

no test coverage detected