Skip to content

Commit

Permalink
clusterer: remove exhaustive warnings
Browse files Browse the repository at this point in the history
Also re-arrange the code to be properly used
  • Loading branch information
razvancrainea committed Nov 17, 2015
1 parent d583f0e commit 7754003
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.
54 changes: 17 additions & 37 deletions modules/clusterer/clusterer.c
Expand Up @@ -101,8 +101,6 @@ str failed_attempts_col = str_init("failed_attempts");
str no_tries_col = str_init("no_tries");

str description_col = str_init("description");
static db_key_t *clusterer_machine_id_key = NULL;
static db_val_t *clusterer_machine_id_value = NULL;
static db_key_t *clusterer_cluster_id_key = NULL;
static db_val_t *clusterer_cluster_id_value = NULL;
/* EQUAL OPERATOR*/
Expand Down Expand Up @@ -287,14 +285,12 @@ static int mod_init(void)
no_tries_col.len = strlen(no_tries_col.s);


LM_INFO("LOCK - initializing\n");
/* create & init lock */
if ((ref_lock = lock_init_rw()) == NULL) {
LM_CRIT("failed to init lock\n");
goto error;
}

LM_INFO("DATA - initializing\n");
/* data pointer in shm */
tdata = (table_entry_t**) shm_malloc(sizeof(table_entry_t*));
if (tdata == 0) {
Expand All @@ -303,15 +299,13 @@ static int mod_init(void)
}
*tdata = 0;

LM_INFO("BINDING\n");
/* bind to the mysql module */
if (db_bind_mod(&clusterer_db_url, &dr_dbf)) {
LM_CRIT("cannot bind to database module! "
"Did you forget to load a database module ?\n");
goto error;
}

LM_INFO("verifying db capabilities\n");
if (!DB_CAPABILITY(dr_dbf, DB_CAP)) {
LM_CRIT("database modules does not "
"provide QUERY functions needed by DRounting module\n");
Expand Down Expand Up @@ -695,6 +689,13 @@ table_entry_t* load_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)
int no_rows = 5;
int db_cols = 10;
unsigned long last_attempt;
static db_key_t clusterer_machine_id_key = &machine_id_col;
static db_val_t clusterer_machine_id_value = {
.type = DB_INT,
.nul = 0,
};

VAL_INT(&clusterer_machine_id_value) = server_id;

/* the columns from the db table */
db_key_t columns[10];
Expand All @@ -721,30 +722,6 @@ table_entry_t* load_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)

CON_OR_RESET(db_hdl);

/* allocating memory only once */
if (!clusterer_machine_id_key) {
clusterer_machine_id_key = pkg_malloc(sizeof(db_key_t));

if (!clusterer_machine_id_key) {
LM_ERR("no more pkg memory\n");
goto error;
}
clusterer_machine_id_key[0] = &machine_id_col;
}

/* allocating memory only once */
if (!clusterer_machine_id_value) {
clusterer_machine_id_value = pkg_malloc(sizeof(db_val_t));
if (!clusterer_machine_id_value) {
LM_ERR("no more pkg memory\n");
goto error;
}
VAL_TYPE(clusterer_machine_id_value) = DB_INT;
VAL_NULL(clusterer_machine_id_value) = 0;
VAL_INT(clusterer_machine_id_value) = server_id;

}

/* checking if the table version is up to date*/
if (db_check_table_version(dr_dbf, db_hdl, db_table, 1/*version*/) != 0)
goto error;
Expand All @@ -759,8 +736,8 @@ table_entry_t* load_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)
"in which the specified server runs\n");

/* first we see in which clusters the specified server runs*/
if (dr_dbf->query(db_hdl, clusterer_machine_id_key, &op,
clusterer_machine_id_value, columns, 1, 1, 0, &res) < 0) {
if (dr_dbf->query(db_hdl, &clusterer_machine_id_key, &op,
&clusterer_machine_id_value, columns, 1, 1, 0, &res) < 0) {
LM_ERR("DB query failed - cannot retrieve the clusters list in which"
" the specified server runs\n");
goto error;
Expand All @@ -769,9 +746,13 @@ table_entry_t* load_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)
LM_DBG("%d rows found in %.*s\n",
RES_ROW_N(res), db_table->len, db_table->s);

if (RES_ROW_N(res) == 0) {
LM_WARN("No machines found in cluster %d\n", server_id);
return 0;
}

clusterer_cluster_id_key = pkg_realloc(clusterer_cluster_id_key,
RES_ROW_N(res) * sizeof(db_key_t));

if (!clusterer_cluster_id_key) {
LM_ERR("no more pkg memory\n");
goto error;
Expand Down Expand Up @@ -883,6 +864,9 @@ table_entry_t* load_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table)

n++;
}
if (n == 1)
LM_WARN("The server is the only one in the cluster\n");

if (DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
if (dr_dbf->fetch_result(db_hdl, &res, no_rows) < 0) {
LM_ERR("fetching rows (1)\n");
Expand Down Expand Up @@ -1036,7 +1020,6 @@ static int reload_data(void)
/* destroy function */
static void destroy(void)
{
LM_INFO("destroy function\n");

struct module_list *tmp;

Expand Down Expand Up @@ -1465,8 +1448,6 @@ int clusterer_check(int cluster_id, union sockaddr_union* su, int machine_id, in
int rc = 0;
table_entry_value_t *head;

LM_INFO("checking connection\n");

lock_start_read(ref_lock);

head = clusterer_find_nodes(cluster_id, proto);
Expand Down Expand Up @@ -1522,7 +1503,6 @@ static int send_to(int cluster_id, int proto)
str send_buffer;
unsigned long ctime = time(0);
int ok = -1;
LM_INFO("get nodes \n");

if (proto == PROTO_BIN) {
bin_get_buffer(&send_buffer);
Expand Down
4 changes: 2 additions & 2 deletions modules/dialog/dlg_replication.c
Expand Up @@ -612,12 +612,12 @@ void receive_prof_binary_packet(int packet_type, struct receive_info *ri, int se

if (packet_type == SERVER_TEMP_DISABLED) {
get_su_info(&ri->src_su.s, ip, port);
LM_WARN("server: %s:%hu temporary disabled\n", ip, port);
LM_INFO("server: %s:%hu temporary disabled\n", ip, port);
return;
}

if (packet_type == SERVER_TIMEOUT) {
LM_WARN("server with clusterer id %d timeout\n", server_id);
LM_INFO("server with clusterer id %d timeout\n", server_id);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/ratelimit/ratelimit_helper.c
Expand Up @@ -837,7 +837,7 @@ void rl_rcv_bin(int packet_type, struct receive_info *ri, int server_id)
}

if (packet_type == SERVER_TIMEOUT) {
LM_WARN("server with clustererer id %d timeout\n", server_id);
LM_INFO("server with clustererer id %d timeout\n", server_id);
return;
}

Expand Down

0 comments on commit 7754003

Please sign in to comment.