File 0001-Start-ping-listener-also-for-postgresql.patch of Package openstack-nova-doc

Index: nova/openstack/common/db/sqlalchemy/session.py
===================================================================
--- nova/openstack/common/db/sqlalchemy/session.py.orig
+++ nova/openstack/common/db/sqlalchemy/session.py
@@ -492,7 +492,7 @@ def _thread_yield(dbapi_con, con_record)
 
 
 def _ping_listener(engine, dbapi_conn, connection_rec, connection_proxy):
-    """Ensures that MySQL and DB2 connections are alive.
+    """Ensures that MySQL, PostgreSQL or DB2 connections are alive.
 
     Borrowed from:
     http://groups.google.com/group/sqlalchemy/msg/a4ce563d802c929f
@@ -508,6 +508,15 @@ def _ping_listener(engine, dbapi_conn, c
         if engine.dialect.is_disconnect(ex, dbapi_conn, cursor):
             msg = _LW('Database server has gone away: %s') % ex
             LOG.warning(msg)
+
+            # if the database server has gone away, all connections in the pool
+            # have become invalid and we can safely close all of them here,
+            # rather than waste time on checking of every single connection
+            engine.dispose()
+
+            # this will be handled by SQLAlchemy and will force it to create
+            # a new connection and retry the original action
+
             raise sqla_exc.DisconnectionError(msg)
         else:
             raise
@@ -629,7 +638,7 @@ def create_engine(sql_connection, sqlite
 
     sqlalchemy.event.listen(engine, 'checkin', _thread_yield)
 
-    if engine.name in ['mysql', 'ibm_db_sa']:
+    if engine.name in ('ibm_db_sa', 'mysql', 'postgresql'):
         ping_callback = functools.partial(_ping_listener, engine)
         sqlalchemy.event.listen(engine, 'checkout', ping_callback)
         if engine.name == 'mysql':
openSUSE Build Service is sponsored by