diff --git a/cachedb/cachedb.h b/cachedb/cachedb.h index 67acf49af8..72d4778c27 100644 --- a/cachedb/cachedb.h +++ b/cachedb/cachedb.h @@ -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); @@ -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); diff --git a/modules/cachedb_mongodb/cachedb_mongodb_dbase.c b/modules/cachedb_mongodb/cachedb_mongodb_dbase.c index 46e8c92054..7c1116f0f1 100644 --- a/modules/cachedb_mongodb/cachedb_mongodb_dbase.c +++ b/modules/cachedb_mongodb/cachedb_mongodb_dbase.c @@ -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) { @@ -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; @@ -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); diff --git a/modules/usrloc/udomain.c b/modules/usrloc/udomain.c index 38f1b4287f..234b9c7e58 100644 --- a/modules/usrloc/udomain.c +++ b/modules/usrloc/udomain.c @@ -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 */