188 # shutdown flag |
188 # shutdown flag |
189 self.shutting_down = False |
189 self.shutting_down = False |
190 # sources (additional sources info in the system database) |
190 # sources (additional sources info in the system database) |
191 self.system_source = self.get_source('native', 'system', |
191 self.system_source = self.get_source('native', 'system', |
192 config.sources()['system'].copy()) |
192 config.sources()['system'].copy()) |
193 self.sources = [self.system_source] |
|
194 self.sources_by_uri = {'system': self.system_source} |
193 self.sources_by_uri = {'system': self.system_source} |
195 # querier helper, need to be created after sources initialization |
194 # querier helper, need to be created after sources initialization |
196 self.querier = querier.QuerierHelper(self, self.schema) |
195 self.querier = querier.QuerierHelper(self, self.schema) |
197 # cache eid -> (type, physical source, extid, actual source) |
196 # cache eid -> (type, physical source, extid, actual source) |
198 self._type_source_cache = {} |
197 self._type_source_cache = {} |
218 """should be called bootstrap_repository, as this is what it does""" |
217 """should be called bootstrap_repository, as this is what it does""" |
219 config = self.config |
218 config = self.config |
220 self._cnxsets_pool = Queue.Queue() |
219 self._cnxsets_pool = Queue.Queue() |
221 # 0. init a cnxset that will be used to fetch bootstrap information from |
220 # 0. init a cnxset that will be used to fetch bootstrap information from |
222 # the database |
221 # the database |
223 self._cnxsets_pool.put_nowait(pool.ConnectionsSet(self.sources)) |
222 self._cnxsets_pool.put_nowait(pool.ConnectionsSet(self.system_source)) |
224 # 1. set used cubes |
223 # 1. set used cubes |
225 if config.creating or not config.read_instance_schema: |
224 if config.creating or not config.read_instance_schema: |
226 config.bootstrap_cubes() |
225 config.bootstrap_cubes() |
227 else: |
226 else: |
228 self.set_schema(self.config.load_bootstrap_schema(), resetvreg=False) |
227 self.set_schema(self.config.load_bootstrap_schema(), resetvreg=False) |
249 self.set_schema(self.deserialize_schema()) |
248 self.set_schema(self.deserialize_schema()) |
250 # 3. initialize data sources |
249 # 3. initialize data sources |
251 if config.creating: |
250 if config.creating: |
252 # call init_creating so that for instance native source can |
251 # call init_creating so that for instance native source can |
253 # configurate tsearch according to postgres version |
252 # configurate tsearch according to postgres version |
254 for source in self.sources: |
253 self.system_source.init_creating() |
255 source.init_creating() |
|
256 else: |
254 else: |
257 self.init_sources_from_database() |
255 self.init_sources_from_database() |
258 if 'CWProperty' in self.schema: |
256 if 'CWProperty' in self.schema: |
259 self.vreg.init_properties(self.properties()) |
257 self.vreg.init_properties(self.properties()) |
260 # 4. close initialization connection set and reopen fresh ones for |
258 # 4. close initialization connection set and reopen fresh ones for |
261 # proper initialization |
259 # proper initialization |
262 self._get_cnxset().close(True) |
260 self._get_cnxset().close(True) |
263 self.cnxsets = [] # list of available cnxsets (can't iterate on a Queue) |
261 self.cnxsets = [] # list of available cnxsets (can't iterate on a Queue) |
264 for i in xrange(config['connections-pool-size']): |
262 for i in xrange(config['connections-pool-size']): |
265 self.cnxsets.append(pool.ConnectionsSet(self.sources)) |
263 self.cnxsets.append(pool.ConnectionsSet(self.system_source)) |
266 self._cnxsets_pool.put_nowait(self.cnxsets[-1]) |
264 self._cnxsets_pool.put_nowait(self.cnxsets[-1]) |
267 |
265 |
268 # internals ############################################################### |
266 # internals ############################################################### |
269 |
267 |
270 def init_sources_from_database(self): |
268 def init_sources_from_database(self): |
284 self.system_source.init(True, sourceent) |
282 self.system_source.init(True, sourceent) |
285 continue |
283 continue |
286 self.add_source(sourceent) |
284 self.add_source(sourceent) |
287 |
285 |
288 def _clear_planning_caches(self): |
286 def _clear_planning_caches(self): |
289 for cache in ('source_defs', 'is_multi_sources_relation'): |
287 clear_cache(self, 'source_defs') |
290 clear_cache(self, cache) |
|
291 |
288 |
292 def add_source(self, sourceent): |
289 def add_source(self, sourceent): |
293 source = self.get_source(sourceent.type, sourceent.name, |
290 source = self.get_source(sourceent.type, sourceent.name, |
294 sourceent.host_config, sourceent.eid) |
291 sourceent.host_config, sourceent.eid) |
295 self.sources_by_eid[sourceent.eid] = source |
292 self.sources_by_eid[sourceent.eid] = source |
322 # trigger full reload of all appobjects |
319 # trigger full reload of all appobjects |
323 self.vreg.set_schema(schema) |
320 self.vreg.set_schema(schema) |
324 else: |
321 else: |
325 self.vreg._set_schema(schema) |
322 self.vreg._set_schema(schema) |
326 self.querier.set_schema(schema) |
323 self.querier.set_schema(schema) |
327 # don't use self.sources, we may want to give schema even to disabled |
|
328 # sources |
|
329 for source in self.sources_by_uri.itervalues(): |
324 for source in self.sources_by_uri.itervalues(): |
330 source.set_schema(schema) |
325 source.set_schema(schema) |
331 self.schema = schema |
326 self.schema = schema |
332 |
327 |
333 def deserialize_schema(self): |
328 def deserialize_schema(self): |
994 rqlcache.pop( ('%s X WHERE X eid %s' % (etype, eid),), None) |
989 rqlcache.pop( ('%s X WHERE X eid %s' % (etype, eid),), None) |
995 extidcache.pop((extid, uri), None) |
990 extidcache.pop((extid, uri), None) |
996 except KeyError: |
991 except KeyError: |
997 etype = None |
992 etype = None |
998 rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None) |
993 rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None) |
999 for source in self.sources: |
994 self.system_source.clear_eid_cache(eid, etype) |
1000 source.clear_eid_cache(eid, etype) |
|
1001 |
995 |
1002 def type_from_eid(self, eid, session=None): |
996 def type_from_eid(self, eid, session=None): |
1003 """return the type of the entity with id <eid>""" |
997 """return the type of the entity with id <eid>""" |
1004 return self.type_and_source_from_eid(eid, session)[0] |
998 return self.type_and_source_from_eid(eid, session)[0] |
1005 |
999 |
1502 from logilab.common import pyro_ext as pyro |
1496 from logilab.common import pyro_ext as pyro |
1503 pyro.ns_reregister(self.pyro_appid, nshost=self.config['pyro-ns-host']) |
1497 pyro.ns_reregister(self.pyro_appid, nshost=self.config['pyro-ns-host']) |
1504 self.info('repository re-registered as a pyro object %s', |
1498 self.info('repository re-registered as a pyro object %s', |
1505 self.pyro_appid) |
1499 self.pyro_appid) |
1506 |
1500 |
1507 # multi-sources planner helpers ########################################### |
|
1508 |
|
1509 @cached |
|
1510 def is_multi_sources_relation(self, rtype): |
|
1511 warn('[3.18] old multi-source system will go away in the next version', |
|
1512 DeprecationWarning) |
|
1513 return any(source for source in self.sources |
|
1514 if not source is self.system_source |
|
1515 and source.support_relation(rtype)) |
|
1516 |
1501 |
1517 # these are overridden by set_log_methods below |
1502 # these are overridden by set_log_methods below |
1518 # only defining here to prevent pylint from complaining |
1503 # only defining here to prevent pylint from complaining |
1519 info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
1504 info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
1520 |
1505 |