Hi, using kamailio 5.3, I have added two connections to the cluster: ``` modparam("db_cluster", "connection", DB_URL_REDIS_READ) modparam("db_cluster", "connection", DB_URL_REDIS_WRITE) modparam("ims_charging", "db_url", "cluster://cluster1") ``` it fails to start, here with additional debug prints
``` 2020-06-30T20:51:10.003728531Z 0(128) DEBUG: db_cluster [dbcl_api.c:267]: db_cluster_init(): initializing with cluster [cluster://k1] len 46 2020-06-30T20:51:10.003751277Z 0(128) DEBUG: db_cluster [dbcl_api.c:277]: db_cluster_init(): call dbcl_get_cluster with trimmed name of cluster [k1] len 36 2020-06-30T20:51:10.003772897Z 0(128) DEBUG: db_cluster [dbcl_data.c:67]: dbcl_get_cluster(): inside dbcl_get_cluster looking up new cluster [k1] len 36 2020-06-30T20:51:10.003801798Z 0(128) DEBUG: db_cluster [dbcl_data.c:75]: dbcl_get_cluster(): checking new 2749854490 cluster with name [k1] len 36 2020-06-30T20:51:10.003825383Z 0(128) DEBUG: db_cluster [dbcl_data.c:76]: dbcl_get_cluster(): checking 26214 cluster with name [k1] len 2 2020-06-30T20:51:10.003844796Z 0(128) ERROR: db_cluster [dbcl_api.c:281]: db_cluster_init(): cluster not found [cluster://k1] ```
so i see different hash id and the length mismatch, where it seems that db_cluster_init already gets wrong dburl strict structure from DB API, because the _dburl.s is pointing to the db_url but the length is calculated from the 2nd connection URL so 36 = strlen ("c2=>mysql://scscf:heslo@mysql/scscf2")
I couldn't get it work also with only 1 connection. I could only tell there is something wrong with the way db_do_init2 / new_db_id from srdb1 interacts with db_cluster_init and then I found this commit [https://github.com/kamailio/kamailio/commit/5457bcbc51012e93775c3aaefa32c73f...)
What I am getting at is: is it possible that commit in srdb1 with id 5457bcbc51012e93775c3aaefa32c73f956aa279 broke the db_cluster module in 2014?
The modparams for db_cluster are not all provided or not complete, because there is no cluster definition.
@miconda there was a copy&paste error here in my description complete configuration looks like this: ``` # ----- db_cluster params ------ modparam("db_cluster", "connection", DB_URL_REDIS_READ) modparam("db_cluster", "connection", DB_URL_REDIS_WRITE) modparam("db_cluster", "cluster", "cluster1=>c1=9r0p;c2=0r9p") ``` So the configuration looks complete according to Readme. Still the debug prints i added revealed the len mismatch. I have workarounded it in db_cluster module by recalculating the len in db_cluster_init. Here is the patch including the change and debug prints: ``` diff --git a/src/modules/db_cluster/dbcl_api.c b/src/modules/db_cluster/dbcl_api.c index 111abcca2..b1ddcd9fc 100644 --- a/src/modules/db_cluster/dbcl_api.c +++ b/src/modules/db_cluster/dbcl_api.c @@ -264,27 +264,27 @@ db1_con_t* db_cluster_init(const str* _dburl) dbcl_cls_t *cls=NULL; str name;
- LM_DBG("initializing with cluster [%.*s]\n", _dburl->len, _dburl->s); + LM_DBG("initializing with cluster [%.*s] len %d\n", _dburl->len, _dburl->s, _dburl->len); if(_dburl->len<10 || strncmp(_dburl->s, "cluster://", 10)!=0) { - LM_ERR("invlaid url for cluster module [%.*s]\n", + LM_ERR("invalid url for cluster module [%.*s]\n", _dburl->len, _dburl->s); return NULL; } name.s = _dburl->s + 10; - name.len = _dburl->len - 10; + name.len = strlen(_dburl->s) - 10; trim(&name); cls = dbcl_get_cluster(&name); if(cls==NULL) { LM_ERR("cluster not found [%.*s]\n", - _dburl->len, _dburl->s); + name.len, name.s); return NULL; } if(dbcl_init_dbf(cls)<0) { LM_ERR("cluster [%.*s] - unable to bind to DB engines\n", - _dburl->len, _dburl->s); + name.len, name.s); return NULL; } dbcl_init_connections(cls); ``` I will re-test it against the latest master and report if I still need the patch. But was thinking perhaps that the root cause is some changes in srdb1 lib.
The `init` function from DB connector modules get the parameter from the module using the connector, in this case it is ims_charging giving the db_url. The issue was in that module, declaring db_url as PARAM_STRING, but the variable for it was `str`, which requires PARAM_STR to have the len recomputed. Commit referenced above should fix it.
Probably worth reviewing to see if other str variables in the module are used to get the value of PARAM_STRING and update to PARAM_STR.
Reopen if still an issue with the above commit.
Closed #2385.