Skip to content

Commit

Permalink
usrloc & cachedb: Document and check some return codes
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Mar 12, 2018
1 parent 30f8e7c commit 610a97a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cachedb/cachedb.h
Expand Up @@ -96,6 +96,8 @@ typedef struct cachedb_funcs_t {
* @con: The cacheDB connection to use.
* @filter: NULL, one or more AND'ed filters for the query.
* @res: Will contain zero or more results.
*
* Return: 0 on success, -1 otherwise. @res is always safe to free.
*/
int (*query) (cachedb_con *con, const cdb_filter_t *filter, cdb_res_t *res);

Expand All @@ -116,6 +118,8 @@ typedef struct cachedb_funcs_t {
* backends may only support row-level TTLs and set a TTL equal to the
* max TTL between all input and existing DB TTL (e.g. MongoDB), others
* may actually fully support dictionary-level TTLs (e.g. Cassandra).
*
* Return: 0 on success, -1 otherwise.
*/
int (*update) (cachedb_con *con, const cdb_filter_t *row_filter,
const cdb_dict_t *pairs);
Expand Down
6 changes: 2 additions & 4 deletions modules/cachedb_mongodb/cachedb_mongodb_dbase.c
Expand Up @@ -1825,6 +1825,8 @@ int mongo_con_query(cachedb_con *con, const cdb_filter_t *filter,

LM_DBG("find all in %s\n", MONGO_NAMESPACE(con));

cdb_res_init(res);

#if MONGOC_CHECK_VERSION(1, 5, 0)
/* TODO: test this! */
if (mongo_cdb_filter_to_bson(filter, &bson_filter) != 0) {
Expand All @@ -1839,8 +1841,6 @@ int mongo_con_query(cachedb_con *con, const cdb_filter_t *filter,
stop_expire_timer(start, mongo_exec_threshold, "MongoDB query rows",
con->url.s, con->url.len, 0);

cdb_res_init(res);

while (mongoc_cursor_next(cursor, &doc)) {
#else
bson_t child;
Expand All @@ -1862,8 +1862,6 @@ int mongo_con_query(cachedb_con *con, const cdb_filter_t *filter,
stop_expire_timer(start, mongo_exec_threshold, "MongoDB query rows",
con->url.s, con->url.len, 0);

cdb_res_init(res);

while (mongoc_cursor_more(cursor) && mongoc_cursor_next(cursor, &doc)) {
#endif
row = mongo_mk_cdb_row(doc);
Expand Down
5 changes: 4 additions & 1 deletion modules/usrloc/udomain.c
Expand Up @@ -1175,7 +1175,10 @@ urecord_t* cachedb_load_urecord(db_con_t* _c, const udomain_t* _d,
return NULL;
}

cdbf.query(cdbc, aor_filter, &res);
if (cdbf.query(cdbc, aor_filter, &res) != 0) {
LM_ERR("query failed for AoR %.*s\n", _aor->len, _aor->s);
goto out_null;
}

/* TODO: implement use table _d->name */

Expand Down

0 comments on commit 610a97a

Please sign in to comment.