Commit e481ff54 authored by Philippe Pepiot's avatar Philippe Pepiot
Browse files

[server] move connection pooler initialization logic to get_cnxset()

This avoid complex logic in Repository initialization.
parent 2aae14425c86
......@@ -260,10 +260,14 @@ class _CnxSetPool(_BaseCnxSet):
self.exception('error while closing %s, error: %s' % (cnxset, e))
def get_cnxset(source, size):
if not size:
def get_cnxset(config, source, bootstrap=False):
if not config['connections-pooler-enabled']:
return _BaseCnxSet(source)
return _CnxSetPool(source, min_size=1, max_size=size)
if bootstrap or config.quick_start:
max_size = 1
else:
max_size = config['connections-pool-size']
return _CnxSetPool(source, min_size=1, max_size=max_size)
class Repository(object):
......@@ -302,16 +306,9 @@ class Repository(object):
self.info('starting repository from %s', self.config.apphome)
self.shutting_down = False
config = self.config
# copy pool size here since config.init_cube() and config.load_schema()
# reload configuration from file and could reset a manually set pool
# size.
if config['connections-pooler-enabled']:
pool_size, min_pool_size = config['connections-pool-size'], 1
else:
pool_size = min_pool_size = None
# 0. init a cnxset that will be used to fetch bootstrap information from
# the database
self.cnxsets = get_cnxset(self.system_source, min_pool_size)
self.cnxsets = get_cnxset(config, self.system_source, bootstrap=True)
# 1. set used cubes
if config.creating or not config.read_instance_schema:
config.bootstrap_cubes()
......@@ -327,8 +324,6 @@ class Repository(object):
# the registry
config.cube_appobject_path = set(('hooks', 'entities'))
config.cubicweb_appobject_path = set(('hooks', 'entities'))
# limit connections pool size
pool_size = min_pool_size
if config.quick_start or config.creating or not config.read_instance_schema:
# load schema from the file system
if not config.creating:
......@@ -360,7 +355,7 @@ class Repository(object):
# 4. close initialization connection set and reopen fresh ones for
# proper initialization
self.cnxsets.close()
self.cnxsets = get_cnxset(self.system_source, pool_size)
self.cnxsets = get_cnxset(config, self.system_source)
# 5. call instance level initialisation hooks
self.hm.call_hooks('server_startup', repo=self)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment