loads info from the db */
| 340 | |
| 341 | /* loads info from the db */ |
| 342 | int load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, cluster_info_t **cl_list) |
| 343 | { |
| 344 | int int_vals[NO_DB_INT_VALS]; |
| 345 | str str_vals[NO_DB_STR_VALS]; |
| 346 | int no_clusters; |
| 347 | int i; |
| 348 | int rc; |
| 349 | node_info_t *_ = NULL; |
| 350 | db_key_t columns[NO_DB_COLS]; /* the columns from the db table */ |
| 351 | db_res_t *res = NULL; |
| 352 | db_row_t *row; |
| 353 | static db_key_t clusterer_node_id_key = &node_id_col; |
| 354 | static db_val_t clusterer_node_id_value = { |
| 355 | .type = DB_INT, |
| 356 | .nul = 0, |
| 357 | }; |
| 358 | |
| 359 | *cl_list = NULL; |
| 360 | |
| 361 | columns[0] = &id_col; |
| 362 | columns[1] = &cluster_id_col; |
| 363 | columns[2] = &node_id_col; |
| 364 | columns[3] = &url_col; |
| 365 | columns[4] = &state_col; |
| 366 | columns[5] = &no_ping_retries_col; |
| 367 | columns[6] = &priority_col; |
| 368 | columns[7] = &sip_addr_col; |
| 369 | columns[8] = &flags_col; |
| 370 | columns[9] = &description_col; |
| 371 | |
| 372 | CON_OR_RESET(db_hdl); |
| 373 | |
| 374 | if (db_check_table_version(dr_dbf, db_hdl, &db_table, CLUSTERER_TABLE_VERSION)) |
| 375 | goto error; |
| 376 | |
| 377 | if (dr_dbf->use_table(db_hdl, &db_table) < 0) { |
| 378 | LM_ERR("cannot select table: \"%.*s\"\n", db_table.len, db_table.s); |
| 379 | goto error; |
| 380 | } |
| 381 | |
| 382 | LM_DBG("DB query - retrieve the list of clusters" |
| 383 | " in which the local node runs\n"); |
| 384 | |
| 385 | VAL_INT(&clusterer_node_id_value) = current_id; |
| 386 | |
| 387 | /* first we see in which clusters the local node runs*/ |
| 388 | if (dr_dbf->query(db_hdl, &clusterer_node_id_key, &op_eq, |
| 389 | &clusterer_node_id_value, columns+1, 1, 1, 0, &res) < 0) { |
| 390 | LM_ERR("DB query failed - cannot retrieve the list of clusters in which" |
| 391 | " the local node runs\n"); |
| 392 | goto error; |
| 393 | } |
| 394 | |
| 395 | LM_DBG("%d rows found in %.*s\n", |
| 396 | RES_ROW_N(res), db_table.len, db_table.s); |
| 397 | |
| 398 | if (RES_ROW_N(res) > MAX_NO_CLUSTERS) { |
| 399 | LM_ERR("Defined: %d clusters for local node, maximum number of clusters " |
no test coverage detected