| 5899 | } |
| 5900 | |
| 5901 | static int cdb2_get_dbhosts(cdb2_hndl_tp *hndl) |
| 5902 | { |
| 5903 | char comdb2db_hosts[MAX_NODES][CDB2HOSTNAME_LEN]; |
| 5904 | int comdb2db_ports[MAX_NODES]; |
| 5905 | int num_comdb2db_hosts; |
| 5906 | int master = -1, rc = 0; |
| 5907 | int num_retry = 0; |
| 5908 | int comdb2db_num = COMDB2DB_NUM; |
| 5909 | char comdb2db_name[32] = COMDB2DB; |
| 5910 | |
| 5911 | if (!cdb2cfg_override) { |
| 5912 | /* Try dbinfo query without any host info. */ |
| 5913 | only_read_config(hndl, 0, 0); |
| 5914 | if (cdb2_dbinfo_query(hndl, hndl->type, hndl->dbname, hndl->dbnum, NULL, |
| 5915 | hndl->hosts, hndl->ports, &hndl->master, |
| 5916 | &hndl->num_hosts, |
| 5917 | &hndl->num_hosts_sameroom) == 0) { |
| 5918 | /* We get a plaintext socket from sockpool. |
| 5919 | We still need to read SSL config */ |
| 5920 | return 0; |
| 5921 | } |
| 5922 | } |
| 5923 | |
| 5924 | rc = get_comdb2db_hosts(hndl, comdb2db_hosts, comdb2db_ports, &master, |
| 5925 | comdb2db_name, &num_comdb2db_hosts, &comdb2db_num, |
| 5926 | hndl->dbname, hndl->hosts, &(hndl->num_hosts), |
| 5927 | &hndl->dbnum, 1, 0); |
| 5928 | |
| 5929 | /* Before database destination discovery */ |
| 5930 | cdb2_event *e = NULL; |
| 5931 | void *callbackrc; |
| 5932 | while ((e = cdb2_next_callback(hndl, CDB2_BEFORE_DISCOVERY, e)) != NULL) { |
| 5933 | int unused; |
| 5934 | (void)unused; |
| 5935 | callbackrc = cdb2_invoke_callback(hndl, e, 0); |
| 5936 | PROCESS_EVENT_CTRL_AFTER(hndl, e, unused, callbackrc); |
| 5937 | } |
| 5938 | |
| 5939 | if (rc != 0) |
| 5940 | goto after_callback; |
| 5941 | |
| 5942 | if ((cdb2_default_cluster[0] != '\0') && (cdb2_comdb2dbname[0] != '\0')) { |
| 5943 | strcpy(comdb2db_name, cdb2_comdb2dbname); |
| 5944 | } |
| 5945 | |
| 5946 | if (strcasecmp(hndl->cluster, "default") == 0) { |
| 5947 | if (cdb2_default_cluster[0] == '\0') { |
| 5948 | sprintf(hndl->errstr, "cdb2_get_dbhosts: no default_type " |
| 5949 | "entry in comdb2db config."); |
| 5950 | rc = -1; |
| 5951 | goto after_callback; |
| 5952 | } |
| 5953 | strncpy(hndl->cluster, cdb2_default_cluster, sizeof(hndl->cluster) - 1); |
| 5954 | if (cdb2cfg_override) { |
| 5955 | strncpy(hndl->type, cdb2_default_cluster, sizeof(hndl->type) - 1); |
| 5956 | } |
| 5957 | } |
| 5958 |
no test coverage detected