File 0001-Add-_wrap_db_error-support-for-postgresql.patch of Package openstack-cinder
From b75919edbef98766429d7b1bbbd162099c2bd755 Mon Sep 17 00:00:00 2001
From: rossella <rsblendido@suse.com>
Date: Fri, 12 Sep 2014 10:05:01 +0000
Subject: [PATCH 2/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.
---
cinder/openstack/common/db/sqlalchemy/session.py | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/cinder/openstack/common/db/sqlalchemy/session.py b/cinder/openstack/common/db/sqlalchemy/session.py
index 2967f23..0c622f4 100644
--- a/cinder/openstack/common/db/sqlalchemy/session.py
+++ b/cinder/openstack/common/db/sqlalchemy/session.py
@@ -442,8 +442,12 @@ def _raise_if_duplicate_entry_error(integrity_error, engine_name):
# 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.*")
}
@@ -483,6 +487,21 @@ def _wrap_db_error(f):
# unique constraint, from error message.
_raise_if_duplicate_entry_error(e, get_engine().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_deadlock_error(e, get_engine().name)
+ LOG.exception('DBAPIError exception wrapped from %s' % e)
+ raise exception.DBError(e)
except Exception as e:
LOG.exception(_('DB exception wrapped.'))
raise exception.DBError(e)
--
1.7.9.5