[sr-dev] git:master: lib/srdb1: Enable non-pooled database connections to be defined .
Peter Dunkley
peter.dunkley at crocodile-rcs.com
Mon Dec 19 00:55:16 CET 2011
Hi,
I think this is a good idea.
Paul (the guy who made this change) is on holiday and won't be back in the
office until after the new year. I don't know if he will check his list
email before then.
I will forward this directly to him to make sure he sees it as soon as he
is back in the office.
Regards,
Peter
> Hello,
>
> It would be great if you could implement the "non-pooled" flag as a
> URL parameter, rather than putting an asterisk into the scheme part.
> For example:
> mysql://user:password@db_server/dbname;pool=false
>
> The asterisk character is not allowed in the scheme name part, so by
> using it there you'll break the generic URI syntax. That may have
> unexpected consequences for provisioning applications (think
> generating Kamailio config files from a template).
>
> Also, the code below will most likely not work correctly if somebody
> uses just "*" as the database name. In that case Kamailio ends up
> searching for a database module named "db_", instead of reporting
> syntax error.
>
> -Jan
>
> On Sun, Dec 18, 2011 at 22:16, Peter Dunkley
> <peter.dunkley at crocodile-rcs.com> wrote:
>> Module: sip-router
>> Branch: master
>> Commit: 2dad021502d0f931fabde0e4c220baf70898a877
>> URL: Â
>> Â http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2dad021502d0f931fabde0e4c220baf70898a877
>>
>> Author: pd <peter.dunkley at crocodile-rcs.com>
>> Committer: pd <peter.dunkley at crocodile-rcs.com>
>> Date: Â Sun Dec 18 21:13:19 2011 +0000
>>
>> lib/srdb1: Enable non-pooled database connections to be defined.
>>
>> - Kamailio pools database connections, but sometimes this causes
>> Â problems. Â For example, we (Crocodile) observed an issue with
>> Â many different queries happening on the same connection while
>> Â using db_fetch_next().
>> - This change enables you to specify a DB connection as non-pooled
>> Â by putting a '*' at the start of the DB URL in kamailio.cfg.
>> - Feature added by Paul Pankhurst @ Crocodile RCS
>>
>> ---
>>
>>  lib/srdb1/db.c   |  13 +++++++++++--
>> Â lib/srdb1/db_id.c | Â 27 ++++++++++++++++++++++++---
>> Â lib/srdb1/db_id.h | Â Â 1 +
>> Â 3 files changed, 36 insertions(+), 5 deletions(-)
>>
>> diff --git a/lib/srdb1/db.c b/lib/srdb1/db.c
>> index 892a849..5905bb0 100644
>> --- a/lib/srdb1/db.c
>> +++ b/lib/srdb1/db.c
>> @@ -182,8 +182,17 @@ int db_bind_mod(const str* mod, db_func_t* mydbf)
>> Â Â Â Â Â Â Â Â return -1;
>> Â Â Â Â }
>> Â Â Â Â memcpy(name, "db_", 3);
>> - Â Â Â memcpy(name+3, mod->s, mod->len);
>> - Â Â Â name[mod->len+3] = 0;
>> +
>> + Â Â Â if (mod->s[0]=='*' )
>> + Â Â Â {
>> + Â Â Â Â Â Â Â memcpy(name+3, (mod->s)+1, (mod->len)-1);
>> + Â Â Â Â Â Â Â name[mod->len-1+3] = 0;
>> + Â Â Â }
>> + Â Â Â else
>> + Â Â Â {
>> + Â Â Â Â Â Â Â memcpy(name+3, mod->s, mod->len);
>> + Â Â Â Â Â Â Â name[mod->len+3] = 0;
>> + Â Â Â }
>>
>> Â Â Â Â /* for safety we initialize mydbf with 0 (this will cause
>> Â Â Â Â * Â a segfault immediately if someone tries to call a
>> function
>> diff --git a/lib/srdb1/db_id.c b/lib/srdb1/db_id.c
>> index 8c8b2a3..4aa564b 100644
>> --- a/lib/srdb1/db_id.c
>> +++ b/lib/srdb1/db_id.c
>> @@ -65,12 +65,13 @@ static int dupl_string(char** dst, const char*
>> begin, const char* end)
>> Â * \param url parsed URL
>> Â * \return 0 if parsing was successful and -1 otherwise
>> Â */
>> -static int parse_db_url(struct db_id* id, const str* url)
>> +static int parse_db_url(struct db_id* id, const str* url, int *poolid )
>> Â {
>> Â #define SHORTEST_DB_URL "s://a/b"
>> Â #define SHORTEST_DB_URL_LEN (sizeof(SHORTEST_DB_URL) - 1)
>>
>> Â Â Â Â enum state {
>> + Â Â Â Â Â Â Â ST_NONPOOL, Â Â /* Non pooling flag */
>> Â Â Â Â Â Â Â Â ST_SCHEME, Â Â /* Scheme part */
>> Â Â Â Â Â Â Â Â ST_SLASH1, Â Â /* First slash */
>> Â Â Â Â Â Â Â Â ST_SLASH2, Â Â /* Second slash */
>> @@ -99,11 +100,25 @@ static int parse_db_url(struct db_id* id, const
>> str* url)
>>
>> Â Â Â Â /* Initialize all attributes to 0 */
>> Â Â Â Â memset(id, 0, sizeof(struct db_id));
>> - Â Â Â st = ST_SCHEME;
>> + Â Â Â st = ST_NONPOOL;
>> Â Â Â Â begin = url->s;
>>
>> Â Â Â Â for(i = 0; i < len; i++) {
>> Â Â Â Â Â Â Â Â switch(st) {
>> + Â Â Â Â Â Â Â case ST_NONPOOL:
>> + Â Â Â Â Â Â Â Â Â Â Â st = ST_SCHEME;
>> + Â Â Â Â Â Â Â Â Â Â Â switch(url->s[i]) {
>> + Â Â Â Â Â Â Â Â Â Â Â case '*':
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â id->poolid = ++(*poolid);
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â begin++;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â default:
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â id->poolid = 0;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break;
>> + Â Â Â Â Â Â Â Â Â Â Â }
>> + Â Â Â Â Â Â Â Â Â Â Â break;
>> +
>> Â Â Â Â Â Â Â Â case ST_SCHEME:
>> Â Â Â Â Â Â Â Â Â Â Â Â switch(url->s[i]) {
>> Â Â Â Â Â Â Â Â Â Â Â Â case ':':
>> @@ -229,6 +244,7 @@ static int parse_db_url(struct db_id* id, const str*
>> url)
>> Â */
>> Â struct db_id* new_db_id(const str* url)
>> Â {
>> + Â Â Â static int poolid=0;
>> Â Â Â Â struct db_id* ptr;
>>
>> Â Â Â Â if (!url || !url->s) {
>> @@ -243,7 +259,7 @@ struct db_id* new_db_id(const str* url)
>> Â Â Â Â }
>> Â Â Â Â memset(ptr, 0, sizeof(struct db_id));
>>
>> - Â Â Â if (parse_db_url(ptr, url) < 0) {
>> + Â Â Â if (parse_db_url(ptr, url, &poolid) < 0) {
>> Â Â Â Â Â Â Â Â LM_ERR("error while parsing database URL: '%.*s'
>> \n", url->len, url->s);
>> Â Â Â Â Â Â Â Â goto err;
>> Â Â Â Â }
>> @@ -286,6 +302,11 @@ unsigned char cmp_db_id(const struct db_id* id1,
>> const struct db_id* id2)
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â id1->pid, id2->pid);
>> Â Â Â Â Â Â Â Â return 0;
>> Â Â Â Â }
>> + Â Â Â if(id1->poolid!=id2->poolid) {
>> + Â Â Â Â Â Â Â LM_DBG("identical DB URLs, but different poolids
>> [%d/%d]\n",
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â id1->poolid,
>> id2->poolid);
>> + Â Â Â Â Â Â Â return 0;
>> + Â Â Â }
>> Â Â Â Â return 1;
>> Â }
>>
>> diff --git a/lib/srdb1/db_id.h b/lib/srdb1/db_id.h
>> index 20ab846..b7427a7 100644
>> --- a/lib/srdb1/db_id.h
>> +++ b/lib/srdb1/db_id.h
>> @@ -41,6 +41,7 @@ struct db_id {
>> Â Â Â Â unsigned short port; /**< Port number */
>> Â Â Â Â char* database; Â Â Â /**< Database, case sensitive */
>>     int  pid;      /**< Process ID (detect cross
>> connections) */
>> +    int  poolid;     /**< poolid within a pid */
>> Â };
>>
>>
>>
>>
>> _______________________________________________
>> sr-dev mailing list
>> sr-dev at lists.sip-router.org
>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
--
Peter Dunkley
Technical Director
Crocodile RCS Ltd
More information about the sr-dev
mailing list