Skip to content

Commit

Permalink
clusterer: don't shutdown at startup or MI reload if DB is empty
Browse files Browse the repository at this point in the history
(cherry picked from commit a028550)
  • Loading branch information
rvlad-patrascu committed Apr 3, 2017
1 parent 77db320 commit ec96b93
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 2 additions & 4 deletions modules/clusterer/clusterer_mod.c
Expand Up @@ -285,8 +285,7 @@ static int child_init(int rank)

/* child 1 loads the clusterer DB info */
if (rank == 1) {
*cluster_list = load_db_info(&dr_dbf, db_hdl, &db_table);
if (*cluster_list == NULL) {
if (load_db_info(&dr_dbf, db_hdl, &db_table, cluster_list) < 0) {
LM_ERR("Failed to load info from DB\n");
return -1;
}
Expand All @@ -300,8 +299,7 @@ static struct mi_root* clusterer_reload(struct mi_root* root, void *param)
cluster_info_t *new_info;
cluster_info_t *old_info;

new_info = load_db_info(&dr_dbf, db_hdl, &db_table);
if (!new_info) {
if (load_db_info(&dr_dbf, db_hdl, &db_table, &new_info) < 0) {
LM_ERR("Failed to load info from DB\n");
return init_mi_tree(500, "Failed to reload", 16);
}
Expand Down
20 changes: 11 additions & 9 deletions modules/clusterer/node_info.c
Expand Up @@ -294,7 +294,7 @@ node_info_t *add_node_info(cluster_info_t **cl_list, int *int_vals, char **str_v
} while (0)

/* loads info from the db */
cluster_info_t* load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)
int load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table, cluster_info_t **cl_list)
{
int int_vals[NO_DB_INT_VALS];
char *str_vals[NO_DB_STR_VALS];
Expand All @@ -303,13 +303,14 @@ cluster_info_t* load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)
db_key_t columns[NO_DB_COLS]; /* the columns from the db table */
db_res_t *res = NULL;
db_row_t *row;
cluster_info_t *cl_list = NULL;
static db_key_t clusterer_node_id_key = &node_id_col;
static db_val_t clusterer_node_id_value = {
.type = DB_INT,
.nul = 0,
};

*cl_list = NULL;

columns[0] = &id_col;
columns[1] = &cluster_id_col;
columns[2] = &node_id_col;
Expand Down Expand Up @@ -350,7 +351,7 @@ cluster_info_t* load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)

if (RES_ROW_N(res) == 0) {
LM_WARN("No nodes found in cluster\n");
return NULL;
return 1;
}

clusterer_cluster_id_key = pkg_realloc(clusterer_cluster_id_key,
Expand Down Expand Up @@ -435,7 +436,7 @@ cluster_info_t* load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)
str_vals[STR_VALS_DESCRIPTION_COL] = (char*) VAL_STRING(ROW_VALUES(row) + 10);

/* add info to backing list */
if (add_node_info(&cl_list, int_vals, str_vals) == 0) {
if (add_node_info(cl_list, int_vals, str_vals) == 0) {
LM_ERR("Unable to add node info to backing list\n");
goto error;
}
Expand All @@ -446,13 +447,14 @@ cluster_info_t* load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)

dr_dbf->free_result(db_hdl, res);

return cl_list;
return 0;
error:
if (res)
dr_dbf->free_result(db_hdl, res);
if (cl_list)
free_info(cl_list);
return NULL;
if (*cl_list)
free_info(*cl_list);
*cl_list = NULL;
return -1;
}

int update_db_current(void)
Expand Down Expand Up @@ -649,7 +651,7 @@ clusterer_node_t* get_clusterer_nodes(int cluster_id)

cl = get_cluster_by_id(cluster_id);
if (!cl) {
LM_DBG("cluster node id %d not found!\n", cluster_id);
LM_DBG("cluster id: %d not found!\n", cluster_id);
goto end;
}
for (node = cl->node_list; node; node = node->next) {
Expand Down
2 changes: 1 addition & 1 deletion modules/clusterer/node_info.h
Expand Up @@ -109,7 +109,7 @@ extern rw_lock_t *cl_list_lock;
extern cluster_info_t **cluster_list;

int update_db_current(void);
cluster_info_t* load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table);
int load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table, cluster_info_t **cl_list);
void free_info(cluster_info_t *cl_list);

node_info_t *add_node_info(cluster_info_t **cl_list, int *int_vals, char **str_vals);
Expand Down

0 comments on commit ec96b93

Please sign in to comment.