equal
deleted
inserted
replaced
249 cnxset.close(True) |
249 cnxset.close(True) |
250 except Exception as e: |
250 except Exception as e: |
251 self.exception('error while closing %s, error: %s' % (cnxset, e)) |
251 self.exception('error while closing %s, error: %s' % (cnxset, e)) |
252 |
252 |
253 |
253 |
254 def get_cnxset(source, size): |
254 def get_cnxset(config, source, bootstrap=False): |
255 if not size: |
255 if not config['connections-pooler-enabled']: |
256 return _BaseCnxSet(source) |
256 return _BaseCnxSet(source) |
257 return _CnxSetPool(source, min_size=1, max_size=size) |
257 if bootstrap or config.quick_start: |
|
258 max_size = 1 |
|
259 else: |
|
260 max_size = config['connections-pool-size'] |
|
261 return _CnxSetPool(source, min_size=1, max_size=max_size) |
258 |
262 |
259 |
263 |
260 class Repository(object): |
264 class Repository(object): |
261 """a repository provides access to a set of persistent storages for |
265 """a repository provides access to a set of persistent storages for |
262 entities and relations |
266 entities and relations |
291 |
295 |
292 def bootstrap(self): |
296 def bootstrap(self): |
293 self.info('starting repository from %s', self.config.apphome) |
297 self.info('starting repository from %s', self.config.apphome) |
294 self.shutting_down = False |
298 self.shutting_down = False |
295 config = self.config |
299 config = self.config |
296 # copy pool size here since config.init_cube() and config.load_schema() |
|
297 # reload configuration from file and could reset a manually set pool |
|
298 # size. |
|
299 if config['connections-pooler-enabled']: |
|
300 pool_size, min_pool_size = config['connections-pool-size'], 1 |
|
301 else: |
|
302 pool_size = min_pool_size = None |
|
303 # 0. init a cnxset that will be used to fetch bootstrap information from |
300 # 0. init a cnxset that will be used to fetch bootstrap information from |
304 # the database |
301 # the database |
305 self.cnxsets = get_cnxset(self.system_source, min_pool_size) |
302 self.cnxsets = get_cnxset(config, self.system_source, bootstrap=True) |
306 # 1. set used cubes |
303 # 1. set used cubes |
307 if config.creating or not config.read_instance_schema: |
304 if config.creating or not config.read_instance_schema: |
308 config.bootstrap_cubes() |
305 config.bootstrap_cubes() |
309 else: |
306 else: |
310 self.set_schema(self.config.load_bootstrap_schema(), resetvreg=False) |
307 self.set_schema(self.config.load_bootstrap_schema(), resetvreg=False) |
316 # |
313 # |
317 # restrict appobject_path to only load hooks and entity classes in |
314 # restrict appobject_path to only load hooks and entity classes in |
318 # the registry |
315 # the registry |
319 config.cube_appobject_path = set(('hooks', 'entities')) |
316 config.cube_appobject_path = set(('hooks', 'entities')) |
320 config.cubicweb_appobject_path = set(('hooks', 'entities')) |
317 config.cubicweb_appobject_path = set(('hooks', 'entities')) |
321 # limit connections pool size |
|
322 pool_size = min_pool_size |
|
323 if config.quick_start or config.creating or not config.read_instance_schema: |
318 if config.quick_start or config.creating or not config.read_instance_schema: |
324 # load schema from the file system |
319 # load schema from the file system |
325 if not config.creating: |
320 if not config.creating: |
326 self.info("set fs instance's schema") |
321 self.info("set fs instance's schema") |
327 self.set_schema(config.load_schema(expand_cubes=True)) |
322 self.set_schema(config.load_schema(expand_cubes=True)) |
349 if 'CWProperty' in self.schema: |
344 if 'CWProperty' in self.schema: |
350 self.vreg.init_properties(self.properties()) |
345 self.vreg.init_properties(self.properties()) |
351 # 4. close initialization connection set and reopen fresh ones for |
346 # 4. close initialization connection set and reopen fresh ones for |
352 # proper initialization |
347 # proper initialization |
353 self.cnxsets.close() |
348 self.cnxsets.close() |
354 self.cnxsets = get_cnxset(self.system_source, pool_size) |
349 self.cnxsets = get_cnxset(config, self.system_source) |
355 # 5. call instance level initialisation hooks |
350 # 5. call instance level initialisation hooks |
356 self.hm.call_hooks('server_startup', repo=self) |
351 self.hm.call_hooks('server_startup', repo=self) |
357 |
352 |
358 def source_by_uri(self, uri): |
353 def source_by_uri(self, uri): |
359 with self.internal_cnx() as cnx: |
354 with self.internal_cnx() as cnx: |