summaryrefslogtreecommitdiff
path: root/oslo
diff options
context:
space:
mode:
authorRoman Podoliaka <rpodolyaka@mirantis.com>2014-10-01 16:10:20 +0300
committerRoman Podoliaka <rpodolyaka@mirantis.com>2014-10-03 18:59:56 +0300
commit01a54cc5cc43c8b497007dbb07c78dacd03c1ed2 (patch)
treea2fb0ba3c2931e1397fc5e79a198cf51e8681fcb /oslo
parent26ec2fcaa233fc26e963424771a6296132d2aefd (diff)
downloadoslo-db-01a54cc5cc43c8b497007dbb07c78dacd03c1ed2.tar.gz
Ensure create_engine() retries the initial connection test
Before return create_engine() tests the connectivity to a DB. At this moment a DB might be unavailable for some reason, in which case create_engine() retries a few times. When used with MySQL, we didn't actually retry, but instead failed on the first connectivity error when trying to get the value of sql_mode session variable. Closes-Bug: #1376211 Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com> Change-Id: I14e25cfe1ed51b0d51a94e491b7267f26e42d34e
Diffstat (limited to 'oslo')
-rw-r--r--oslo/db/sqlalchemy/session.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/oslo/db/sqlalchemy/session.py b/oslo/db/sqlalchemy/session.py
index 882a9ea..57b5fb8 100644
--- a/oslo/db/sqlalchemy/session.py
+++ b/oslo/db/sqlalchemy/session.py
@@ -466,19 +466,27 @@ def _init_events(engine, mysql_sql_mode=None, **kw):
cursor = dbapi_con.cursor()
cursor.execute("SET SESSION sql_mode = %s", [mysql_sql_mode])
- realmode = engine.execute("SHOW VARIABLES LIKE 'sql_mode'").fetchone()
- if realmode is None:
- LOG.warning(_LW('Unable to detect effective SQL mode'))
- else:
- realmode = realmode[1]
- LOG.debug('MySQL server mode set to %s', realmode)
- if 'TRADITIONAL' not in realmode.upper() and \
- 'STRICT_ALL_TABLES' not in realmode.upper():
- LOG.warning(
- _LW(
- "MySQL SQL mode is '%s', "
- "consider enabling TRADITIONAL or STRICT_ALL_TABLES"),
- realmode)
+ @sqlalchemy.event.listens_for(engine, "first_connect")
+ def _check_effective_sql_mode(dbapi_con, connection_rec):
+ if mysql_sql_mode is not None:
+ _set_session_sql_mode(dbapi_con, connection_rec)
+
+ cursor = dbapi_con.cursor()
+ cursor.execute("SHOW VARIABLES LIKE 'sql_mode'")
+ realmode = cursor.fetchone()
+
+ if realmode is None:
+ LOG.warning(_LW('Unable to detect effective SQL mode'))
+ else:
+ realmode = realmode[1]
+ LOG.debug('MySQL server mode set to %s', realmode)
+ if 'TRADITIONAL' not in realmode.upper() and \
+ 'STRICT_ALL_TABLES' not in realmode.upper():
+ LOG.warning(
+ _LW(
+ "MySQL SQL mode is '%s', "
+ "consider enabling TRADITIONAL or STRICT_ALL_TABLES"),
+ realmode)
@_init_events.dispatch_for("sqlite")