Add sql_idle_timeout

This commit is contained in:
Rick Harris 2011-02-11 00:12:51 +00:00
parent 415112967a
commit f134884714
3 changed files with 38 additions and 1 deletions

View File

@ -42,3 +42,12 @@ bind_port = 9191
# registry server. Any valid SQLAlchemy connection string is fine.
# See: http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#sqlalchemy.create_engine
sql_connection = sqlite:///glance.sqlite
# Period in seconds after which SQLAlchemy should reestablish its connection
# to the database.
#
# MySQL uses a default `wait_timeout` of 8 hours, after which it will drop
# idle connections. This can result in 'MySQL Gone Away' exceptions. If you
# notice this, you can lower this value to ensure that SQLAlchemy reconnects
# before MySQL can drop the connection.
sql_idle_timeout = 3600

View File

@ -293,3 +293,24 @@ def load_paste_app(app_name, options, args):
"configuration file %(conf_file)s."
"\nGot: %(e)r" % locals())
return conf, app
def get_option(options, option, **kwargs):
if option in options:
value = options[option]
type_ = kwargs.get('type', 'str')
if type_ == 'bool':
if hasattr(value, 'lower'):
return value.lower() == 'true'
else:
return value
elif type_ == 'int':
return int(value)
elif type_ == 'float':
return float(value)
else:
return value
elif 'default' in kwargs:
return kwargs['default']
else:
raise KeyError("option '%s' not found" % option)

View File

@ -27,6 +27,7 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import sessionmaker
from glance.common import config
from glance.common import exception
from glance.common import utils
from glance.registry.db import models
@ -52,8 +53,14 @@ def configure_db(options):
"""
global _ENGINE
if not _ENGINE:
verbose = config.get_option(
options, 'verbose', type='bool', default=False)
timeout = config.get_option(
options, 'sql_idle_timeout', type='int', default=3600)
_ENGINE = create_engine(options['sql_connection'],
echo=options['verbose'])
echo=verbose,
echo_pool=verbose,
pool_recycle=timeout)
register_models()