On Monday 29 August 2011, MÉSZÁROS Mihály wrote:
> I am experiencing that in usrloc module, still more then one worker
> process share the same sql connection:


I'm sorry, the first patch was totally bogus. Due to the forking of the 
childs, they have the same memory layout and a very high chance of allocating 
the same address (in their own address space) for the connection struct.

Attached patch should give a thread_id truly unique per connection. If you're 
able to find multiple processes using the same thread_id, you've found the 
cause.
-- 
Greetings,

Alex Hermann

diff --git a/modules/db_mysql/km_dbase.c b/modules/db_mysql/km_dbase.c
index d85fe5f..0be7136 100644
--- a/modules/db_mysql/km_dbase.c
+++ b/modules/db_mysql/km_dbase.c
@@ -78,6 +78,13 @@ static int db_mysql_submit_query(const db1_con_t* _h, const str* _s)
 		return -1;
 	}
 
+	if (_h->table && _h->table->s)
+		LM_INFO(" submit_query:  con: %ld  table: %.*s  query: %.*s\n",
+				mysql_thread_id(CON_CONNECTION(_h)), _h->table->len, _h->table->s, _s->len, _s->s);
+	else 
+		LM_INFO(" submit_query:  con: %ld  query: %.*s\n",
+				mysql_thread_id(CON_CONNECTION(_h)), _s->len, _s->s);
+
 	if (my_ping_interval) {
 		t = time(0);
 		if ((t - CON_TIMESTAMP(_h)) > my_ping_interval) {
@@ -163,6 +170,12 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
 		return -1;
 	}
 
+	if (_h->table && _h->table->s)
+		LM_INFO("store_result:  con: %ld  table: %.*s\n",
+				mysql_thread_id(CON_CONNECTION(_h)), _h->table->len, _h->table->s);
+	else 
+		LM_INFO("store_result:  con: %ld\n", mysql_thread_id(CON_CONNECTION(_h)));
+
 	*_r = db_new_result();
 	if (*_r == 0) {
 		LM_ERR("no memory left\n");
diff --git a/modules/db_mysql/km_my_con.c b/modules/db_mysql/km_my_con.c
index ce20be2..26a4613 100644
--- a/modules/db_mysql/km_my_con.c
+++ b/modules/db_mysql/km_my_con.c
@@ -119,6 +119,7 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
 		ptr->con->reconnect = 0;
 
 	LM_DBG("connection type is %s\n", mysql_get_host_info(ptr->con));
+	LM_DBG("connection thread_id is %ld\n", mysql_thread_id(ptr->con));
 	LM_DBG("protocol version is %d\n", mysql_get_proto_info(ptr->con));
 	LM_DBG("server version is %s\n", mysql_get_server_info(ptr->con));
 
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

Reply via email to