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

Function cdb2_dbinfo_query

cdb2api/cdb2api.c:5717–5891  ·  view source on GitHub ↗

get dbinfo * returns -1 on error * returns 0 if number of hosts it finds is > 0 */

Source from the content-addressed store, hash-verified

5715 * returns 0 if number of hosts it finds is > 0
5716 */
5717static int cdb2_dbinfo_query(cdb2_hndl_tp *hndl, const char *type, const char *dbname, int dbnum, const char *host,
5718 char valid_hosts[][CDB2HOSTNAME_LEN], int *valid_ports, int *master_node,
5719 int *num_valid_hosts, int *num_valid_sameroom_hosts)
5720{
5721 char newsql_typestr[128];
5722 SBUF2 *sb = NULL;
5723 int rc = 0; /* Make compilers happy. */
5724 int port = 0;
5725
5726 void *callbackrc;
5727 int overwrite_rc = 0;
5728 cdb2_event *e = NULL;
5729
5730 while ((e = cdb2_next_callback(hndl, CDB2_BEFORE_DBINFO, e)) != NULL) {
5731 callbackrc = cdb2_invoke_callback(hndl, e, 2, CDB2_HOSTNAME, host,
5732 CDB2_PORT, port);
5733 PROCESS_EVENT_CTRL_BEFORE(hndl, e, rc, callbackrc, overwrite_rc);
5734 }
5735
5736 if (overwrite_rc)
5737 goto after_callback;
5738
5739 debugprint("entering\n");
5740
5741 rc = snprintf(newsql_typestr, sizeof(newsql_typestr),
5742 "comdb2/%s/%s/newsql/%s", dbname, type, hndl->policy);
5743 if (rc < 1 || rc >= sizeof(newsql_typestr)) {
5744 debugprint(
5745 "ERROR: can not fit entire string 'comdb2/%s/%s/newsql/%s'\n",
5746 dbname, type, hndl->policy);
5747 rc = -1;
5748 goto after_callback;
5749 }
5750 int fd = cdb2_socket_pool_get(newsql_typestr, dbnum, NULL);
5751 get_host_and_port_from_fd(fd, hndl->cached_host, sizeof(hndl->cached_host), &hndl->cached_port);
5752 debugprint("cdb2_socket_pool_get fd %d, host '%s'\n", fd, host);
5753 if (fd < 0) {
5754 if (host == NULL) {
5755 rc = -1;
5756 goto after_callback;
5757 }
5758
5759 if (!cdb2_allow_pmux_route) {
5760 if (!port) {
5761 port = cdb2portmux_get(hndl, type, host, "comdb2",
5762 "replication", dbname);
5763 debugprint("cdb2portmux_get port=%d'\n", port);
5764 }
5765 if (port < 0) {
5766 rc = -1;
5767 goto after_callback;
5768 }
5769 fd =
5770 cdb2_tcpconnecth_to(hndl, host, port, 0, hndl->connect_timeout);
5771 } else {
5772 fd = cdb2portmux_route(hndl, host, "comdb2", "replication", dbname);
5773 debugprint("cdb2portmux_route fd=%d'\n", fd);
5774 }

Callers 2

get_comdb2db_hostsFunction · 0.70
cdb2_get_dbhostsFunction · 0.70

Calls 11

cdb2_next_callbackFunction · 0.85
cdb2_invoke_callbackFunction · 0.85
cdb2_socket_pool_getFunction · 0.85
cdb2portmux_getFunction · 0.85
mallocFunction · 0.85
freeFunction · 0.85
parse_dbresponseFunction · 0.85
cdb2_tcpconnecth_toFunction · 0.70
cdb2portmux_routeFunction · 0.70

Tested by

no test coverage detected