[sr-dev] git:master: modules/db_postgres: Retries are disabled within transactions

Peter Dunkley peter.dunkley at crocodile-rcs.com
Wed May 2 18:56:21 CEST 2012


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

Author: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Date:   Wed May  2 17:43:14 2012 +0100

modules/db_postgres: Retries are disabled within transactions

- You don't want automatic retries in the database when inside a
  transaction (that is after an SQL BEGIN).  This is because if the
  database connection fails the outstanding operations will be rolled
  back.  If you automatically connect and retry the failed operation
  it will be acting on a database table/rows that are in a different
  state from which it expects.
- This change disables retries on any SQL operations between a
  start_transaction and an (end|abort)_transaction.
- Other database operations are unaffected.

---

 modules/db_postgres/km_dbase.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/modules/db_postgres/km_dbase.c b/modules/db_postgres/km_dbase.c
index b1ac34b..d2be696 100644
--- a/modules/db_postgres/km_dbase.c
+++ b/modules/db_postgres/km_dbase.c
@@ -163,7 +163,7 @@ void db_postgres_close(db1_con_t* _h)
  */
 static int db_postgres_submit_query(const db1_con_t* _con, const str* _s)
 {
-	int i;
+	int i, retries;
 	ExecStatusType pqresult;
 
 	if(! _con || !_s || !_s->s)
@@ -194,7 +194,12 @@ static int db_postgres_submit_query(const db1_con_t* _con, const str* _s)
 			return -1;
 	}
 
-	for(i = 0; i <= pg_retries; i++) {
+	if (CON_TRANSACTION(_con) == 1)
+		retries = 0;
+	else
+		retries = pg_retries;
+
+	for(i = 0; i <= retries; i++) {
 		/* free any previous query that is laying about */
 		db_postgres_free_query(_con);
 		/* exec the query */




More information about the sr-dev mailing list