Skip to content

Commit

Permalink
cachedb_mongodb: Implement the "truncate" capability
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Feb 26, 2018
1 parent 73e4f14 commit 458690a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/cachedb_mongodb/cachedb_mongodb.c
Expand Up @@ -121,6 +121,7 @@ static int mod_init(void)
cde.cdb_func.set_cols = mongo_con_set_cols;
cde.cdb_func.unset_cols = mongo_con_unset_cols;
cde.cdb_func.raw_query = mongo_con_raw_query;
cde.cdb_func.truncate = mongo_truncate;
cde.cdb_func.db_query_trans = mongo_db_query_trans;
cde.cdb_func.db_free_trans = mongo_db_free_result_trans;
cde.cdb_func.db_insert_trans = mongo_db_insert_trans;
Expand Down
19 changes: 19 additions & 0 deletions modules/cachedb_mongodb/cachedb_mongodb_dbase.c
Expand Up @@ -1627,6 +1627,25 @@ int mongo_db_update_trans(cachedb_con *con, const str *table,
return -1;
}

int mongo_truncate(cachedb_con *con)
{
bson_t empty_doc = BSON_INITIALIZER;
bson_error_t error;
struct timeval start;
int ret = 0;

start_expire_timer(start, mongo_exec_threshold);
if (!mongoc_collection_remove(MONGO_COLLECTION(con),
MONGOC_REMOVE_NONE, &empty_doc, NULL, &error)) {
LM_ERR("failed to truncate con %.*s!\n", con->url.len, con->url.s);
ret = -1;
}
stop_expire_timer(start, mongo_exec_threshold, "MongoDB truncate",
con->url.s, con->url.len, 0);

return ret;
}

int mongo_doc_to_dict(const bson_t *doc, cdb_dict_t *out_dict)
{
bson_iter_t iter;
Expand Down
1 change: 1 addition & 0 deletions modules/cachedb_mongodb/cachedb_mongodb_dbase.h
Expand Up @@ -91,6 +91,7 @@ int mongo_db_update_trans(cachedb_con *con, const str *table,
const db_key_t *_k, const db_op_t *_o,
const db_val_t *_v, const db_key_t *_uk,
const db_val_t *_uv, const int _n, const int _un);
int mongo_truncate(cachedb_con *con);

int mongo_con_get_rows(cachedb_con *con, const cdb_filter_t *row_filter,
cdb_res_t *res);
Expand Down

0 comments on commit 458690a

Please sign in to comment.