Skip to content

Commit

Permalink
sql_cacher: don't allow usage of a replicated local cache
Browse files Browse the repository at this point in the history
Using a replicated collection for cachedb_local would lead to invalid
keys in the cache due to reload version inconsistencies.

(cherry picked from commit 1b96626)
  • Loading branch information
rvlad-patrascu committed Jul 21, 2022
1 parent 99275f6 commit 6a71c14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cachedb/cachedb.h
Expand Up @@ -144,6 +144,11 @@ typedef struct cachedb_funcs_t {
const cdb_dict_t *pairs);
/* TODO: can we also implement these ^ with Redis, or can we adapt them? */

/* Checks if the database is replicated (in an OpenSIPS cluster).
* Currently only makes sense for cachedb_local
*/
int (*is_replicated) (cachedb_con *con);

int capability;
} cachedb_funcs;

Expand Down
5 changes: 5 additions & 0 deletions modules/cachedb_local/cachedb_local.c
Expand Up @@ -321,6 +321,10 @@ void lcache_destroy(cachedb_con *con)
cachedb_do_close(con,lcache_free_connection);
}

int lcache_is_replicated (cachedb_con *con)
{
return cluster_id ? 1 : 0;
}

/**
* init module function
Expand Down Expand Up @@ -348,6 +352,7 @@ static int mod_init(void)
cde.cdb_func.remove = lcache_htable_remove;
cde.cdb_func.add = lcache_htable_add;
cde.cdb_func.sub = lcache_htable_sub;
cde.cdb_func.is_replicated = lcache_is_replicated;

cde.cdb_func.capability = CACHEDB_CAP_BINARY_VALUE;

Expand Down
7 changes: 7 additions & 0 deletions modules/sql_cacher/sql_cacher.c
Expand Up @@ -743,6 +743,13 @@ static db_handlers_t *db_init_test_conn(cache_entry_t *c_entry)
c_entry->cachedb_url.len, c_entry->cachedb_url.s);
return NULL;
}

if (new_db_hdls->cdbf.is_replicated &&
new_db_hdls->cdbf.is_replicated(new_db_hdls->cdbcon)) {
LM_ERR("Cannot use an OpenSIPS replicated cacheDB\n");
return NULL;
}

/* setting and getting a test key in cachedb */
if (new_db_hdls->cdbf.set(new_db_hdls->cdbcon, &cdb_test_key, &cdb_test_val,
0) < 0) {
Expand Down

0 comments on commit 6a71c14

Please sign in to comment.