[sr-dev] git:master: db_cluster: new module for generic database clustering

Juha Heinanen jh at tutpro.com
Sat Apr 7 16:59:00 CEST 2012


daniel,

the patch below upgrades working connection if read operation on another
connection with same priority has failed, i.e., next time the working
connection will be tried before the failing one.

is the patch ok with you?  if so, the same could be done on write
operations.

-- juha

*** /usr/src/orig/sip-router/modules_k/db_cluster/dbcl_api.c	2012-03-28 18:26:21.000000000 +0300
--- modules_k/db_cluster/dbcl_api.c	2012-04-07 17:51:28.000000000 +0300
***************
*** 46,51 ****
--- 46,52 ----
  	int k;\
  	db1_con_t  *dbh=NULL;\
  	dbcl_cls_t *cls=NULL;\
+ 	dbcl_con_t *tmp;\
  	cls = (dbcl_cls_t*)_h->tail;\
  	ret = 0;\
  	for(i=DBCL_PRIO_SIZE-1; i>0; i--)\
***************
*** 58,68 ****
  					if(cls->rlist[i].clist[j] != NULL && cls->rlist[i].clist[j]->flags!=0\
  						&& cls->rlist[i].clist[j]->dbh != NULL)\
  					{\
! 						LM_DBG("serial operation - cluster [%.*s] (%d/%d)\n",\
  								cls->name.len, cls->name.s, i, j);\
  						dbh = cls->rlist[i].clist[j]->dbh;\
  						ret = cls->rlist[i].clist[j]->dbf.command;\
  						if (ret==0) {\
  							cls->usedcon = cls->rlist[i].clist[j];\
  							return 0;\
  						}\
--- 59,76 ----
  					if(cls->rlist[i].clist[j] != NULL && cls->rlist[i].clist[j]->flags!=0\
  						&& cls->rlist[i].clist[j]->dbh != NULL)\
  					{\
! 					        LM_DBG("serial operation - cluster [%.*s] (%d/%d)\n", \
  								cls->name.len, cls->name.s, i, j);\
  						dbh = cls->rlist[i].clist[j]->dbh;\
  						ret = cls->rlist[i].clist[j]->dbf.command;\
  						if (ret==0) {\
+ 						        if (j > 0) {\
+ 							    LM_INFO("upgrading connection - cluster [%.*s] (%d/%d)\n", \
+ 								cls->name.len, cls->name.s, i, j);\
+ 							    tmp = cls->rlist[i].clist[j];\
+ 							    cls->rlist[i].clist[j] = cls->rlist[i].clist[j-1];\
+ 							    cls->rlist[i].clist[j-1] = tmp;\
+ 							}\
  							cls->usedcon = cls->rlist[i].clist[j];\
  							return 0;\
  						}\





More information about the sr-dev mailing list