[sr-dev] git:master: modules_k/rls: Used db_begin() and db_commit() around blocks of related DB queries and updates

Peter Dunkley peter.dunkley at crocodile-rcs.com
Fri Apr 20 15:02:30 CEST 2012


Module: sip-router
Branch: master
Commit: f71bdc3cbdf5acdf243217778e4159f2e6ab341d
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f71bdc3cbdf5acdf243217778e4159f2e6ab341d

Author: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Date:   Fri Apr 20 14:00:22 2012 +0100

modules_k/rls: Used db_begin() and db_commit() around blocks of related DB queries and updates

- This makes these related sets of DB queries a single transaction.  As Klaus
  pointed out this if you don't do this you can get inconsistencies when using
  multiple presence servers.

---

 modules_k/rls/notify.c          |   12 ++++++++++++
 modules_k/rls/resource_notify.c |   24 ++++++++++++++++++++++++
 modules_k/rls/rls_db.c          |   21 +++++++++++++++++++++
 3 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/modules_k/rls/notify.c b/modules_k/rls/notify.c
index 082fbfa..1836808 100644
--- a/modules_k/rls/notify.c
+++ b/modules_k/rls/notify.c
@@ -128,6 +128,12 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, str* rl_uri,
 		goto error;
 	}
 
+	if (db_begin(&rlpres_dbf, rlpres_db) < 0)
+	{
+		LM_ERR("in BEGIN\n");
+		goto error;
+	}
+
 	if(rlpres_dbf.query(rlpres_db, query_cols, 0, query_vals, result_cols,
 					1, n_result_cols, &str_resource_uri_col, &result )< 0)
 	{
@@ -257,6 +263,12 @@ int send_full_notify(subs_t* subs, xmlNodePtr rl_node, str* rl_uri,
 		goto error;
 	}
 
+	if (db_commit(&rlpres_dbf, rlpres_db) < 0)
+	{
+		LM_ERR("in COMMIT\n");
+		goto error;
+	}
+
 	xmlFree(rlmi_cont->s);
 	pkg_free(rlmi_cont);
 
diff --git a/modules_k/rls/resource_notify.c b/modules_k/rls/resource_notify.c
index 29e0b11..87ce806 100644
--- a/modules_k/rls/resource_notify.c
+++ b/modules_k/rls/resource_notify.c
@@ -893,6 +893,12 @@ static void timer_send_full_state_notifies(int round)
 		goto done;
 	}
 
+	if (db_begin(&rls_dbf, rls_db) < 0)
+	{
+		LM_ERR("in BEGIN\n");
+		goto done;
+	}
+
 	/* Step 1: Find rls_watchers that require full-state notification */
 	if (rls_dbf.query(rls_db, query_cols, 0, query_vals, result_cols,
 				1, n_result_cols, 0, &result) < 0)
@@ -912,6 +918,12 @@ static void timer_send_full_state_notifies(int round)
 		goto done;
 	}
 
+	if (db_commit(&rls_dbf, rls_db) < 0)
+	{
+		LM_ERR("in COMMIT\n");
+		goto done;
+	}
+
 	/* Step 3: Full-state notify each watcher we found */
 	rows = RES_ROWS(result);
 	for (i = 0; i < RES_ROW_N(result); i++)
@@ -1025,6 +1037,12 @@ static void timer_send_update_notifies(int round)
 		goto done;
 	}
 
+	if (db_begin(&rlpres_dbf, rlpres_db) < 0)
+	{
+		LM_ERR("in BEGIN\n");
+		goto error;
+	}
+
 	if(rlpres_dbf.query(rlpres_db, query_cols, 0, query_vals, result_cols,
 					1, n_result_cols, &str_rlsubs_did_col, &result)< 0)
 	{
@@ -1042,6 +1060,12 @@ static void timer_send_update_notifies(int round)
 		goto error;
 	}
 
+	if (db_commit(&rlpres_dbf, rlpres_db) < 0)
+	{
+		LM_ERR("in COMMIT\n");
+		goto error;
+	}
+
 	send_notifies(result, did_col, resource_uri_col, auth_state_col, reason_col,
                   pres_state_col, content_type_col);
 error:
diff --git a/modules_k/rls/rls_db.c b/modules_k/rls/rls_db.c
index 6a00c21..46bda91 100644
--- a/modules_k/rls/rls_db.c
+++ b/modules_k/rls/rls_db.c
@@ -124,6 +124,7 @@ int delete_expired_subs_rlsdb( void )
 	int i;
 	subs_t subs;
 	str rlsubs_did = {0, 0};
+	int transaction_started = 0;
 
 	if(rls_db == NULL)
 	{
@@ -148,6 +149,13 @@ int delete_expired_subs_rlsdb( void )
 	result_cols[r_to_tag_col=n_result_cols++] = &str_to_tag_col;
 	result_cols[r_from_tag_col=n_result_cols++] = &str_from_tag_col;
 
+	if (db_begin(&rls_dbf, rls_db) < 0)
+	{
+		LM_ERR("in BEGIN\n");
+		goto error;
+	}
+	transaction_started = 1;
+
 	if(rls_dbf.query(rls_db, query_cols, query_ops, query_vals, result_cols, 
 				n_query_cols, n_result_cols, 0, &result )< 0)
 	{
@@ -213,12 +221,25 @@ int delete_expired_subs_rlsdb( void )
 		pkg_free(rlsubs_did.s);
 	}
 
+	if (db_commit(&rls_dbf, rls_db) < 0)
+	{
+		LM_ERR("in COMMIT\n");
+		goto error;
+	}
+
 	if(result) rls_dbf.free_result(rls_db, result);
 	return 1;
 
 error:
 	if (result) rls_dbf.free_result(rls_db, result);
 	if (rlsubs_did.s) pkg_free(rlsubs_did.s);
+
+	if (transaction_started)
+	{
+		if (db_commit(&rls_dbf, rls_db) < 0)
+			LM_ERR("in COMMIT\n");
+	}
+
 	return -1;
 }
 




More information about the sr-dev mailing list