File 0001-Add-_wrap_db_error-support-for-postgresql.patch of Package openstack-nova-doc
From 8a7eaed83e927e71c022818b47c08cef4e110773 Mon Sep 17 00:00:00 2001
From: rossella <rsblendido@suse.com>
Date: Wed, 30 Jul 2014 09:19:41 +0000
Subject: [PATCH 1/2] Add _wrap_db_error support for postgresql
The original "_wrap_db_error" function is only available for mysql.
We need to add support for postgresql.
The deadlock exception thrown from postgresql is TransactionRollbackError,
it's not the same with "OperationalError" thrown from mysql,
and isn't included in sqlalchemy. So, the base exception need to be
catched.
---
nova/openstack/common/db/sqlalchemy/session.py | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
Index: nova-2014.1.3.dev100.gc04b6ea/nova/openstack/common/db/sqlalchemy/session.py
===================================================================
--- nova-2014.1.3.dev100.gc04b6ea.orig/nova/openstack/common/db/sqlalchemy/session.py
+++ nova-2014.1.3.dev100.gc04b6ea/nova/openstack/common/db/sqlalchemy/session.py
@@ -402,8 +402,11 @@ def _raise_if_duplicate_entry_error(inte
# mysql:
# (OperationalError) (1213, 'Deadlock found when trying to get lock; try '
# 'restarting transaction') <query_str> <query_args>
+# postgresql:
+# (TransactionRollbackError) deadlock detected <deadlock_details>
_DEADLOCK_RE_DB = {
- "mysql": re.compile(r"^.*\(1213, 'Deadlock.*")
+ "mysql": re.compile(r"^.*\(1213, 'Deadlock.*"),
+ "postgresql": re.compile(r"^.*deadlock detected.*")
}
@@ -455,6 +458,21 @@ def _wrap_db_error(f):
# unique constraint, from error message.
_raise_if_duplicate_entry_error(e, self.bind.dialect.name)
raise exception.DBError(e)
+ except sqla_exc.DBAPIError as e:
+ # NOTE(wingwj): This branch is used to catch deadlock exception
+ # under postgresql. The original exception thrown from postgresql
+ # is TransactionRollbackError, it's not included in the sqlalchemy.
+ # Moreover, DBAPIError is the base class of OperationalError
+ # and IntegrityError, so we catch it on the end of the process.
+ # The issue has also submitted to sqlalchemy on
+ # https://bitbucket.org/zzzeek/sqlalchemy/issue/3075/
+ # support-non-standard-dbapi-exception
+ # (FIXME) This branch should be refactored after the patch
+ # merged in & our requirement of sqlalchemy updated
+ _raise_if_db_connection_lost(e, self.bind)
+ _raise_if_deadlock_error(e, self.bind.dialect.name)
+ LOG.exception(_LE('DBAPIError exception wrapped from %s') % e)
+ raise exception.DBError(e)
except exception.DBError:
# note(zzzeek) - if _wrap_db_error is applied to nested functions,
# ensure an existing DBError is propagated outwards