ソースを参照

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.
Peter Dunkley 13 年 前
コミット
765a538aa9
1 ファイル変更7 行追加2 行削除
  1. 7 2
      modules/db_postgres/km_dbase.c

+ 7 - 2
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)
 static int db_postgres_submit_query(const db1_con_t* _con, const str* _s)
 {
 {
-	int i;
+	int i, retries;
 	ExecStatusType pqresult;
 	ExecStatusType pqresult;
 
 
 	if(! _con || !_s || !_s->s)
 	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;
 			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 */
 		/* free any previous query that is laying about */
 		db_postgres_free_query(_con);
 		db_postgres_free_query(_con);
 		/* exec the query */
 		/* exec the query */