def __init__(self, **options): bus_name = dbus.service.BusName(DS_SERVICE, bus=dbus.SessionBus(), replace_existing=False, allow_replacement=False) dbus.service.Object.__init__(self, bus_name, DS_OBJECT_PATH) migrated, initiated = self._open_layout() self._metadata_store = MetadataStore() self._file_store = FileStore() self._optimizer = Optimizer(self._file_store, self._metadata_store) self._index_store = IndexStore() self._index_updating = False root_path = layoutmanager.get_instance().get_root_path() self._cleanflag = os.path.join(root_path, 'ds_clean') if initiated: logging.debug('Initiate datastore') self._rebuild_index() self._index_store.flush() self._mark_clean() return if migrated: self._rebuild_index() self._mark_clean() return rebuild = False stat = os.statvfs(root_path) da = stat.f_bavail * stat.f_bsize if not self._index_store.index_updated: logging.warn('Index is not up-to-date') rebuild = True elif not os.path.exists(self._cleanflag): logging.warn('DS state is not clean') rebuild = True elif da < MIN_INDEX_FREE_BYTES: logging.warn('Disk space tight for index') rebuild = True if rebuild: logging.warn('Trigger index rebuild') self._rebuild_index() else: # fast path try: self._index_store.open_index() except BaseException: logging.exception('Failed to open index') # try... self._rebuild_index() self._mark_clean() return