コード例 #1
0
ファイル: api.py プロジェクト: overcastcloud/oslo.db
        def wrapper(*args, **kwargs):
            next_interval = self.retry_interval
            remaining = self.max_retries
            db_error = self.db_error

            while True:
                try:
                    return f(*args, **kwargs)
                except db_error as e:
                    if remaining == 0:
                        LOG.exception(_LE('DB exceeded retry limit.'))
                        if isinstance(e, exception.RetryRequest):
                            six.reraise(type(e.inner_exc),
                                        e.inner_exc,
                                        sys.exc_info()[2])
                        raise e
                    if remaining != -1:
                        remaining -= 1
                        # RetryRequest is application-initated exception
                        # and not an error condition in case retries are
                        # not exceeded
                        if not isinstance(e, exception.RetryRequest):
                            LOG.exception(_LE('DB error.'))
                    # NOTE(vsergeyev): We are using patched time module, so
                    #                  this effectively yields the execution
                    #                  context to another green thread.
                    time.sleep(next_interval)
                    if self.inc_retry_interval:
                        next_interval = min(
                            next_interval * 2,
                            self.max_retry_interval
                        )
コード例 #2
0
ファイル: api.py プロジェクト: ropex/oslo.db
        def wrapper(*args, **kwargs):
            next_interval = self.retry_interval
            remaining = self.max_retries
            db_error = self.db_error

            while True:
                try:
                    return f(*args, **kwargs)
                except db_error as e:
                    if remaining == 0:
                        LOG.exception(_LE('DB exceeded retry limit.'))
                        if isinstance(e, exception.RetryRequest):
                            six.reraise(type(e.inner_exc), e.inner_exc,
                                        sys.exc_info()[2])
                        raise e
                    if remaining != -1:
                        remaining -= 1
                        LOG.exception(_LE('DB error.'))
                    # NOTE(vsergeyev): We are using patched time module, so
                    #                  this effectively yields the execution
                    #                  context to another green thread.
                    time.sleep(next_interval)
                    if self.inc_retry_interval:
                        next_interval = min(next_interval * 2,
                                            self.max_retry_interval)
コード例 #3
0
        def wrapper(*args, **kwargs):
            next_interval = self.retry_interval
            remaining = self.max_retries

            while True:
                try:
                    return f(*args, **kwargs)
                except Exception as e:
                    with excutils.save_and_reraise_exception() as ectxt:
                        if remaining > 0:
                            ectxt.reraise = not self._is_exception_expected(e)
                            if ectxt.reraise:
                                # We got an unexpected exception so stop
                                # retrying, log it and raise it up to the
                                # caller.
                                LOG.exception(_LE('DB error.'))
                        else:
                            LOG.exception(_LE('DB exceeded retry limit.'))
                            # if it's a RetryRequest, we need to unpack it
                            if isinstance(e, exception.RetryRequest):
                                ectxt.type_ = type(e.inner_exc)
                                ectxt.value = e.inner_exc
                    LOG.debug("Performing DB retry for function %s",
                              reflection.get_callable_name(f))
                    # NOTE(vsergeyev): We are using patched time module, so
                    #                  this effectively yields the execution
                    #                  context to another green thread.
                    time.sleep(next_interval)
                    if self.inc_retry_interval:
                        next_interval = min(next_interval * 2,
                                            self.max_retry_interval)
                    remaining -= 1
コード例 #4
0
ファイル: api.py プロジェクト: mangelajo/oslo.db
        def wrapper(*args, **kwargs):
            next_interval = self.retry_interval
            remaining = self.max_retries

            while True:
                try:
                    return f(*args, **kwargs)
                except Exception as e:
                    with excutils.save_and_reraise_exception() as ectxt:
                        if remaining > 0:
                            ectxt.reraise = not self._is_exception_expected(e)
                        else:
                            LOG.exception(_LE('DB exceeded retry limit.'))
                            # if it's a RetryRequest, we need to unpack it
                            if isinstance(e, exception.RetryRequest):
                                ectxt.type_ = type(e.inner_exc)
                                ectxt.value = e.inner_exc
                    LOG.debug("Performing DB retry for function %s",
                              reflection.get_callable_name(f))
                    # NOTE(vsergeyev): We are using patched time module, so
                    #                  this effectively yields the execution
                    #                  context to another green thread.
                    time.sleep(next_interval)
                    if self.inc_retry_interval:
                        next_interval = min(
                            next_interval * 2,
                            self.max_retry_interval
                        )
                    remaining -= 1
コード例 #5
0
    def migrate_up(self, version, with_data=False):
        """Migrate up to a new version of the db.

        :param version: id of revision to upgrade.
        :type version: str
        :keyword with_data: Whether to verify the applied changes with data,
            see :ref:`auxiliary-dynamic-methods <Auxiliary Methods>`.
        :type with_data: Bool
        """
        # NOTE(sdague): try block is here because it's impossible to debug
        # where a failed data migration happens otherwise
        try:
            if with_data:
                data = None
                pre_upgrade = getattr(self, "_pre_upgrade_%03d" % version,
                                      None)
                if pre_upgrade:
                    data = pre_upgrade(self.migrate_engine)

            self.migration_api.upgrade(self.migrate_engine, self.REPOSITORY,
                                       version)
            self.assertEqual(
                version,
                self.migration_api.db_version(self.migrate_engine,
                                              self.REPOSITORY))
            if with_data:
                check = getattr(self, "_check_%03d" % version, None)
                if check:
                    check(self.migrate_engine, data)
        except exc.DbMigrationError:
            msg = _LE("Failed to migrate to version %(ver)s on engine %(eng)s")
            LOG.error(msg, {"ver": version, "eng": self.migrate_engine})
            raise
コード例 #6
0
        def wrapper(*args, **kwargs):
            next_interval = self.retry_interval
            remaining = self.max_retries

            while True:
                try:
                    return f(*args, **kwargs)
                except Exception as e:
                    with excutils.save_and_reraise_exception() as ectxt:
                        if remaining > 0:
                            ectxt.reraise = not self._is_exception_expected(e)
                        else:
                            LOG.exception(_LE('DB exceeded retry limit.'))
                            # if it's a RetryRequest, we need to unpack it
                            if isinstance(e, exception.RetryRequest):
                                ectxt.type_ = type(e.inner_exc)
                                ectxt.value = e.inner_exc
                    # NOTE(vsergeyev): We are using patched time module, so
                    #                  this effectively yields the execution
                    #                  context to another green thread.
                    time.sleep(next_interval)
                    if self.inc_retry_interval:
                        next_interval = min(
                            next_interval * 2,
                            self.max_retry_interval
                        )
                    remaining -= 1
コード例 #7
0
    def migrate_up(self, version, with_data=False):
        """Migrate up to a new version of the db.

        :param version: id of revision to upgrade.
        :type version: str
        :keyword with_data: Whether to verify the applied changes with data,
            see :ref:`auxiliary-dynamic-methods <Auxiliary Methods>`.
        :type with_data: Bool
        """
        # NOTE(sdague): try block is here because it's impossible to debug
        # where a failed data migration happens otherwise
        try:
            if with_data:
                data = None
                pre_upgrade = getattr(
                    self, "_pre_upgrade_%03d" % version, None)
                if pre_upgrade:
                    data = pre_upgrade(self.migrate_engine)

            self.migration_api.upgrade(self.migrate_engine,
                                       self.REPOSITORY, version)
            self.assertEqual(version,
                             self.migration_api.db_version(self.migrate_engine,
                                                           self.REPOSITORY))
            if with_data:
                check = getattr(self, "_check_%03d" % version, None)
                if check:
                    check(self.migrate_engine, data)
        except exc.DbMigrationError:
            msg = _LE("Failed to migrate to version %(ver)s on engine %(eng)s")
            LOG.error(msg, {"ver": version, "eng": self.migrate_engine})
            raise
コード例 #8
0
ファイル: api.py プロジェクト: mangelajo/oslo.db
 def _is_exception_expected(self, exc):
     if isinstance(exc, self.db_error):
         # RetryRequest is application-initated exception
         # and not an error condition in case retries are
         # not exceeded
         if not isinstance(exc, exception.RetryRequest):
             LOG.exception(_LE('DB error.'))
         return True
     return self.exception_checker(exc)
コード例 #9
0
 def _is_exception_expected(self, exc):
     if isinstance(exc, self.db_error):
         # RetryRequest is application-initated exception
         # and not an error condition in case retries are
         # not exceeded
         if not isinstance(exc, exception.RetryRequest):
             LOG.exception(_LE('DB error.'))
         return True
     return self.exception_checker(exc)
コード例 #10
0
def _raise_for_remaining_DBAPIError(error, match, engine_name, is_disconnect):
    """Filter for remaining DBAPIErrors.

    Filter for remaining DBAPIErrors and wrap if they represent
    a disconnect error.
    """
    if is_disconnect:
        raise exception.DBConnectionError(error)
    else:
        LOG.exception(_LE('DBAPIError exception wrapped from %s') % error)
        raise exception.DBError(error)
コード例 #11
0
def _raise_for_remaining_DBAPIError(error, match, engine_name, is_disconnect):
    """Filter for remaining DBAPIErrors.

    Filter for remaining DBAPIErrors and wrap if they represent
    a disconnect error.
    """
    if is_disconnect:
        raise exception.DBConnectionError(error)
    else:
        LOG.exception(
            _LE('DBAPIError exception wrapped from %s') % error)
        raise exception.DBError(error)
コード例 #12
0
 def downgrade(self, version):
     try:
         # version for migrate should be valid int - else skip
         if version in ('base', None):
             version = self.init_version
         version = int(version)
         return migration.db_sync(
             self.engine, self.repository, version,
             init_version=self.init_version)
     except ValueError:
         LOG.error(
             _LE('Migration number for migrate plugin must be valid '
                 'integer or empty, if you want to downgrade '
                 'to initial state')
         )
         raise
コード例 #13
0
ファイル: concurrency.py プロジェクト: DinaBelova/oslo.db
 def _api(self):
     if not self._db_api:
         with self._lock:
             if not self._db_api:
                 db_api = api.DBAPI.from_config(
                     conf=self._conf, backend_mapping=self._backend_mapping)
                 if self._conf.database.use_tpool:
                     try:
                         from eventlet import tpool
                     except ImportError:
                         LOG.exception(_LE("'eventlet' is required for "
                                           "TpoolDbapiWrapper."))
                         raise
                     self._db_api = tpool.Proxy(db_api)
                 else:
                     self._db_api = db_api
     return self._db_api
コード例 #14
0
def _raise_for_all_others(error, match, engine_name, is_disconnect):
    LOG.exception(_LE('DB exception wrapped.'))
    raise exception.DBError(error)
コード例 #15
0
def _raise_for_all_others(error, match, engine_name, is_disconnect):
    LOG.exception(_LE('DB exception wrapped.'))
    raise exception.DBError(error)