Fix for retry on serialization errors for ZPsycopgDA

This commit is contained in:
Federico Di Gregorio 2009-08-09 16:22:43 +02:00
parent 36aff2f73d
commit 29d00f56f6
2 changed files with 13 additions and 18 deletions

View File

@ -1,5 +1,8 @@
2009-08-08 Federico Di Gregorio <fog@initd.org> 2009-08-08 Federico Di Gregorio <fog@initd.org>
* ZPsycopgDA/db.py: applied serialization error retry from Brian
Sutherland.
* Implemented connection.reset() method to reset the connection to * Implemented connection.reset() method to reset the connection to
well-know default parameters. This is much faster than closing and well-know default parameters. This is much faster than closing and
reopening the connection. (Suggested by a bug report by Glenn reopening the connection. (Suggested by a bug report by Glenn

View File

@ -27,7 +27,7 @@ import pool
import psycopg2 import psycopg2
from psycopg2.extensions import INTEGER, LONGINTEGER, FLOAT, BOOLEAN, DATE, TIME from psycopg2.extensions import INTEGER, LONGINTEGER, FLOAT, BOOLEAN, DATE, TIME
from psycopg2.extensions import register_type from psycopg2.extensions import TransactionRollbackError, register_type
from psycopg2 import NUMBER, STRING, ROWID, DATETIME from psycopg2 import NUMBER, STRING, ROWID, DATETIME
@ -169,26 +169,18 @@ class DB(TM, dbi_db.DB):
c.execute(qs, query_data) c.execute(qs, query_data)
else: else:
c.execute(qs) c.execute(qs)
except psycopg2.OperationalError, e: except TransactionRollbackError:
# Ha, here we have to look like we are the ZODB raising conflict errrors, raising ZPublisher.Publish.Retry just doesn't work
logging.debug("Serialization Error, retrying transaction", exc_info=True)
raise ConflictError("TransactionRollbackError from psycopg2")
except psycopg2.OperationalError:
logging.exception("Operational error on connection, closing it.")
try: try:
self.close() # Only close our connection
self.putconn(True)
except: except:
logging.debug("Something went wrong when we tried to close the pool", exc_info=True)
pass pass
self.open()
try:
if query_data:
c.execute(qs, query_data)
else:
c.execute(qs)
except (psycopg2.ProgrammingError,
psycopg2.IntegrityError), e:
if e.args[0].find("concurrent update") > -1:
raise ConflictError
raise e
except (psycopg2.ProgrammingError, psycopg2.IntegrityError), e:
if e.args[0].find("concurrent update") > -1:
raise ConflictError
raise e
if c.description is not None: if c.description is not None:
nselects += 1 nselects += 1
if c.description != desc and nselects > 1: if c.description != desc and nselects > 1: