Skip to content

Commit

Permalink
Resolve comdb2db correctly from phys-rep
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Hannum <[email protected]>
  • Loading branch information
markhannum committed Sep 9, 2024
1 parent 5806d83 commit 5645c1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
6 changes: 2 additions & 4 deletions cdb2api/cdb2api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1664,13 +1664,12 @@ static int read_available_comdb2db_configs(cdb2_hndl_tp *hndl, char comdb2db_hos
return 0;
}

int cdb2_get_comdb2db(char **comdb2dbname, char **default_type)
int cdb2_get_comdb2db(char **comdb2dbname)
{
if (!strlen(cdb2_comdb2dbname)) {
read_available_comdb2db_configs(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0);
}
(*comdb2dbname) = strdup(cdb2_comdb2dbname);
(*default_type) = strdup(cdb2_default_cluster);
return 0;
}

Expand All @@ -1687,8 +1686,7 @@ static int get_host_by_name(const char *comdb2db_name, char comdb2db_hosts[][CDB
if (cdb2_default_cluster[0] == '\0') {
snprintf(dns_name, sizeof(dns_name), "%s.%s", comdb2db_name, cdb2_dnssuffix);
} else {
snprintf(dns_name, sizeof(dns_name), "%s-%s.%s", cdb2_default_cluster, comdb2db_name,
cdb2_dnssuffix);
snprintf(dns_name, sizeof(dns_name), "%s-%s.%s", cdb2_default_cluster, comdb2db_name, cdb2_dnssuffix);
}
#ifdef __APPLE__
hp = gethostbyname(dns_name);
Expand Down
2 changes: 1 addition & 1 deletion cdb2api/cdb2api.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ typedef struct cdb2_effects_type effects_tp;

void cdb2_set_comdb2db_config(const char *cfg_file);
void cdb2_set_comdb2db_info(const char *cfg_info);
int cdb2_get_comdb2db(char **comdb2db_name, char **default_type);
int cdb2_get_comdb2db(char **comdb2db_name);

int cdb2_open(cdb2_hndl_tp **hndl, const char *dbname, const char *type,
int flags);
Expand Down
19 changes: 5 additions & 14 deletions db/phys_rep.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,29 +210,20 @@ static int append_quoted_source_hosts(char *buf, int buf_len, int *rc) {
static char *comdb2dbname = NULL;

if (!comdb2dbname) {
cdb2_get_comdb2db(&comdb2dbname, &comdb2dbclass);
}

// Also fix the 'source tier' in case it is one of the following
if ((strncasecmp(gbl_physrep_source_host, "test", 4) == 0) ||
(strncasecmp(gbl_physrep_source_host, "dev", 3) == 0) ||
(strncasecmp(gbl_physrep_source_host, "fuzz", 4) == 0)) {
// test is dev
gbl_physrep_source_host = (strncasecmp(gbl_physrep_source_host, "fuzz", 4) == 0) ? "fuzz" : "dev";
cdb2_get_comdb2db(&comdb2dbname);
comdb2dbclass = (strcmp(comdb2dbname, "comdb3db") == 0) ? "dev" : "prod";
}

*rc = cdb2_open(&comdb2db, comdb2dbname, comdb2dbclass, 0);
if (*rc) {
physrep_logmsg(LOGMSG_ERROR, "%s:%d Failed to connect to %s@%s (err: %s rc: %d)\n",
__func__, __LINE__, comdb2dbname, comdb2dbclass,
cdb2_errstr(comdb2db), *rc);
physrep_logmsg(LOGMSG_ERROR, "%s:%d Failed to connect to %s@%s (err: %s rc: %d)\n", __func__, __LINE__,
comdb2dbname, comdb2dbclass, cdb2_errstr(comdb2db), *rc);
goto err;
}

*rc = cdb2_bind_param(comdb2db, "dbname", CDB2_CSTRING, gbl_physrep_source_dbname, strlen(gbl_physrep_source_dbname));
if (*rc) {
physrep_logmsg(LOGMSG_ERROR, "%s:%d Failed to bind dbname (rc: %d)\n",
__func__, __LINE__, *rc);
physrep_logmsg(LOGMSG_ERROR, "%s:%d Failed to bind dbname (rc: %d)\n", __func__, __LINE__, *rc);
goto err;
}

Expand Down

0 comments on commit 5645c1c

Please sign in to comment.