[PATCH 7 of 9 cubicweb] [server] move connection pooler initialization logic to get_cnxset()

Philippe Pepiot ph at itsalwaysdns.eu
Tue Mar 31 18:29:02 CEST 2020


# HG changeset patch
# User Philippe Pepiot <ph at itsalwaysdns.eu>
# Date 1585664234 -7200
#      Tue Mar 31 16:17:14 2020 +0200
# Node ID 27323f7200fca2271f6e3a6027fb18da9348807b
# Parent  e49e03b590e087b88d1d79f0472ccf5eac62c0e2
# Available At https://philpep.org/pub/hg/cubicweb
#              hg pull https://philpep.org/pub/hg/cubicweb -r 27323f7200fc
[server] move connection pooler initialization logic to get_cnxset()

This avoid complex logic in Repository initialization.

diff --git a/cubicweb/server/repository.py b/cubicweb/server/repository.py
--- a/cubicweb/server/repository.py
+++ b/cubicweb/server/repository.py
@@ -251,10 +251,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):
@@ -293,16 +297,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()
@@ -318,8 +315,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:
@@ -351,7 +346,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)
 



More information about the cubicweb-devel mailing list