Module: sip-router Branch: master Commit: 0411d363ab8eb9cf146852a1c6cd8cf146acfc6d URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0411d363...
Author: Morten Tryfoss morten@tryfoss.no Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Mon Mar 3 19:53:42 2014 +0100
db_cluster: new parameter max_query_length
- set threshold in second after which a connection is marked inactive if the query fails - allow to let connectioncs being active if the error is due to some sql mistake - default is 0 (set connection innactive immediately, same behavior as so far)
---
modules/db_cluster/README | 23 ++++++++++++++++- modules/db_cluster/db_cluster_mod.c | 2 + modules/db_cluster/dbcl_api.c | 34 +++++++++++++++++++++++---- modules/db_cluster/doc/db_cluster_admin.xml | 23 ++++++++++++++++++ 4 files changed, 75 insertions(+), 7 deletions(-)
diff --git a/modules/db_cluster/README b/modules/db_cluster/README index aecbcee..0364bf6 100644 --- a/modules/db_cluster/README +++ b/modules/db_cluster/README @@ -28,6 +28,7 @@ Daniel-Constantin Mierla 3.1. connection (str) 3.2. cluster (str) 3.3. inactive_interval (int) + 3.4. max_query_length (int)
4. Usage
@@ -36,7 +37,8 @@ Daniel-Constantin Mierla 1.1. Set connection parameter 1.2. Set cluster parameter 1.3. Set inactive_interval parameter - 1.4. Set cluster parameter + 1.4. Set max_query_length parameter + 1.5. Set cluster parameter
Chapter 1. Admin Guide
@@ -53,6 +55,7 @@ Chapter 1. Admin Guide 3.1. connection (str) 3.2. cluster (str) 3.3. inactive_interval (int) + 3.4. max_query_length (int)
4. Usage
@@ -90,6 +93,7 @@ Chapter 1. Admin Guide 3.1. connection (str) 3.2. cluster (str) 3.3. inactive_interval (int) + 3.4. max_query_length (int)
3.1. connection (str)
@@ -148,6 +152,21 @@ modparam("db_cluster", "cluster", "cls1=>con1=9s8p;con2=9s8p") modparam("db_cluster", "inactive_interval", 180) ...
+3.4. max_query_length (int) + + How long (seconds) a failed db operation needs to last before + deactivating the connection for inactive_interval seconds. This + prevents disabling of connections that reply fast with error codes, + thus being active (e.g., due to primary key insert errors). In such + cases, the database server is active. + + Default value is 0. + + Example 1.4. Set max_query_length parameter +... +modparam("db_cluster", "max_query_length", 5) +... + 4. Usage
Practically, all the modules that want to use a cluster, have to set @@ -169,7 +188,7 @@ modparam("db_cluster", "inactive_interval", 180) to be used for parallel writing from acc and round-robin reading by sqlops.
- Example 1.4. Set cluster parameter + Example 1.5. Set cluster parameter ... modparam("db_cluster", "connection", "c1=>mysql://kamailio:kamailiorw@localhost/kamailio1") diff --git a/modules/db_cluster/db_cluster_mod.c b/modules/db_cluster/db_cluster_mod.c index c0b78cb..1d15531 100644 --- a/modules/db_cluster/db_cluster_mod.c +++ b/modules/db_cluster/db_cluster_mod.c @@ -37,6 +37,7 @@ int dbcl_con_param(modparam_t type, void *val); int dbcl_cls_param(modparam_t type, void *val);
int dbcl_inactive_interval = 300; +int dbcl_max_query_length = 0;
/*! \brief * DB Cluster module interface @@ -53,6 +54,7 @@ static param_export_t params[] = { {"connection", STR_PARAM|USE_FUNC_PARAM, (void*)dbcl_con_param}, {"cluster", STR_PARAM|USE_FUNC_PARAM, (void*)dbcl_cls_param}, {"inactive_interval", INT_PARAM, &dbcl_inactive_interval}, + {"max_query_length", INT_PARAM, &dbcl_max_query_length}, {0, 0, 0} };
diff --git a/modules/db_cluster/dbcl_api.c b/modules/db_cluster/dbcl_api.c index 0269343..2629a84 100644 --- a/modules/db_cluster/dbcl_api.c +++ b/modules/db_cluster/dbcl_api.c @@ -33,10 +33,12 @@ #include "../../trim.h" #include "../../globals.h" #include "../../lib/srdb1/db.h" +#include "../../timer.h"
#include "dbcl_data.h" #include "dbcl_api.h"
+extern int dbcl_max_query_length;
#define DBCL_READ(command) \ do {\ @@ -44,6 +46,7 @@ int i;\ int j;\ int k;\ + unsigned int sec = 0;\ db1_con_t *dbh=NULL;\ dbcl_cls_t *cls=NULL;\ cls = (dbcl_cls_t*)_h->tail;\ @@ -60,6 +63,7 @@ {\ LM_DBG("serial operation - cluster [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ + sec = get_ticks();\ dbh = cls->rlist[i].clist[j]->dbh;\ ret = cls->rlist[i].clist[j]->dbf.command;\ if (ret==0) {\ @@ -69,7 +73,10 @@ LM_DBG("serial operation - failre on cluster"\ " [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ - dbcl_inactive_con(cls->rlist[i].clist[j]);\ + sec = get_ticks() - sec;\ + if(sec >= dbcl_max_query_length){\ + dbcl_inactive_con(cls->rlist[i].clist[j]);\ + }\ }\ }\ }\ @@ -83,6 +90,7 @@ {\ LM_DBG("round robin operation - cluster [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ + sec = get_ticks();\ dbh = cls->rlist[i].clist[j]->dbh;\ ret = cls->rlist[i].clist[j]->dbf.command;\ if (ret==0)\ @@ -94,7 +102,10 @@ LM_DBG("round robin operation - failre on cluster"\ " [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ - dbcl_inactive_con(cls->rlist[i].clist[j]);\ + sec = get_ticks() - sec;\ + if(sec >= dbcl_max_query_length){\ + dbcl_inactive_con(cls->rlist[i].clist[j]);\ + }\ }\ }\ }\ @@ -118,6 +129,7 @@ int i;\ int j;\ int k;\ + unsigned int sec = 0;\ db1_con_t *dbh=NULL;\ dbcl_cls_t *cls=NULL;\ cls = (dbcl_cls_t*)_h->tail;\ @@ -136,6 +148,7 @@ {\ LM_DBG("serial operation - cluster [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ + sec = get_ticks();\ dbh = cls->wlist[i].clist[j]->dbh;\ ret = cls->wlist[i].clist[j]->dbf.command;\ if (ret==0) {\ @@ -145,7 +158,10 @@ LM_DBG("serial operation - failure on cluster"\ " [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ - dbcl_inactive_con(cls->wlist[i].clist[j]);\ + sec = get_ticks() - sec;\ + if(sec >= dbcl_max_query_length){\ + dbcl_inactive_con(cls->wlist[i].clist[j]);\ + }\ }\ }\ }\ @@ -159,6 +175,7 @@ {\ LM_DBG("round robin operation - cluster [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ + sec = get_ticks();\ dbh = cls->wlist[i].clist[j]->dbh;\ ret = cls->wlist[i].clist[j]->dbf.command;\ if (ret==0)\ @@ -170,7 +187,10 @@ LM_DBG("round robin operation - failure on cluster"\ " [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ - dbcl_inactive_con(cls->wlist[i].clist[j]);\ + sec = get_ticks() - sec;\ + if(sec >= dbcl_max_query_length){\ + dbcl_inactive_con(cls->wlist[i].clist[j]);\ + }\ }\ }\ }\ @@ -183,6 +203,7 @@ {\ LM_DBG("parallel operation - cluster [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ + sec = get_ticks();\ dbh = cls->wlist[i].clist[j]->dbh;\ rc = cls->wlist[i].clist[j]->dbf.command;\ if(rc==0) {\ @@ -192,7 +213,10 @@ LM_DBG("parallel operation - failure on cluster"\ " [%.*s] (%d/%d)\n",\ cls->name.len, cls->name.s, i, j);\ - dbcl_inactive_con(cls->wlist[i].clist[j]);\ + sec = get_ticks() - sec;\ + if(sec >= dbcl_max_query_length){\ + dbcl_inactive_con(cls->wlist[i].clist[j]);\ + }\ }\ ret |= rc;\ }\ diff --git a/modules/db_cluster/doc/db_cluster_admin.xml b/modules/db_cluster/doc/db_cluster_admin.xml index d849f20..17543fd 100644 --- a/modules/db_cluster/doc/db_cluster_admin.xml +++ b/modules/db_cluster/doc/db_cluster_admin.xml @@ -146,6 +146,29 @@ modparam("db_cluster", "inactive_interval", 180) </programlisting> </example> </section> + <section id="db_cluster.p.max_query_length"> + <title><varname>max_query_length</varname> (int)</title> + <para> + How long (seconds) a failed db operation needs to last before + deactivating the connection for inactive_interval seconds. This + prevents disabling of connections that reply fast with error + codes, thus being active (e.g., due to primary key insert errors). + In such cases, the database server is active. + </para> + <para> + <emphasis> + Default value is 0. + </emphasis> + </para> + <example> + <title>Set <varname>max_query_length</varname> parameter</title> + <programlisting format="linespecific"> +... +modparam("db_cluster", "max_query_length", 5) +... +</programlisting> + </example> + </section> </section> <section> <title>Usage</title>