当前位置: 首页>>代码示例>>Python>>正文


Python exception.DBDeadlock方法代码示例

本文整理汇总了Python中oslo_db.exception.DBDeadlock方法的典型用法代码示例。如果您正苦于以下问题:Python exception.DBDeadlock方法的具体用法?Python exception.DBDeadlock怎么用?Python exception.DBDeadlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_db.exception的用法示例。


在下文中一共展示了exception.DBDeadlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _deadlock_error

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def _deadlock_error(operational_error, match, engine_name, is_disconnect):
    """Filter for MySQL or Postgresql deadlock error.

    NOTE(comstud): In current versions of DB backends, Deadlock violation
    messages follow the structure:

    mysql+mysqldb:
    (OperationalError) (1213, 'Deadlock found when trying to get lock; try '
                         'restarting transaction') <query_str> <query_args>

    mysql+mysqlconnector:
    (InternalError) 1213 (40001): Deadlock found when trying to get lock; try
                         restarting transaction

    postgresql:
    (TransactionRollbackError) deadlock detected <deadlock_details>


    ibm_db_sa:
    SQL0911N The current transaction has been rolled back because of a
    deadlock or timeout <deadlock details>

    """
    raise exception.DBDeadlock(operational_error) 
开发者ID:openstack,项目名称:oslo.db,代码行数:26,代码来源:exc_filters.py

示例2: __init__

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def __init__(self, retry_interval=1, max_retries=20,
                 inc_retry_interval=True,
                 max_retry_interval=10, retry_on_disconnect=False,
                 retry_on_deadlock=False,
                 exception_checker=lambda exc: False,
                 jitter=False):
        super(wrap_db_retry, self).__init__()

        self.jitter = jitter
        self.db_error = (exception.RetryRequest, )
        # default is that we re-raise anything unexpected
        self.exception_checker = exception_checker
        if retry_on_disconnect:
            self.db_error += (exception.DBConnectionError, )
        if retry_on_deadlock:
            self.db_error += (exception.DBDeadlock, )
        self.retry_interval = retry_interval
        self.max_retries = max_retries
        self.inc_retry_interval = inc_retry_interval
        self.max_retry_interval = max_retry_interval 
开发者ID:openstack,项目名称:oslo.db,代码行数:22,代码来源:api.py

示例3: test_health_check_stale_amphora

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def test_health_check_stale_amphora(self, session_mock, get_stale_amp_mock,
                                        failover_mockv2, failover_mock,
                                        db_wait_mock):
        conf = oslo_fixture.Config(cfg.CONF)
        conf.config(group="health_manager", heartbeat_timeout=5)
        amphora_health = mock.MagicMock()
        amphora_health.amphora_id = AMPHORA_ID

        get_stale_amp_mock.side_effect = [amphora_health, None]

        exit_event = threading.Event()
        hm = healthmanager.HealthManager(exit_event)

        hm.health_check()

        # Test DBDeadlock and RetryRequest exceptions
        session_mock.reset_mock()
        get_stale_amp_mock.reset_mock()
        mock_session = mock.MagicMock()
        session_mock.return_value = mock_session
        get_stale_amp_mock.side_effect = [
            db_exc.DBDeadlock,
            db_exc.RetryRequest(Exception('retry_test')),
            db_exc.DBConnectionError,
            TestException('test')]
        # Test that a DBDeadlock does not raise an exception
        self.assertIsNone(hm.health_check())
        # Test that a RetryRequest does not raise an exception
        self.assertIsNone(hm.health_check())
        # Test that a DBConnectionError does not raise an exception
        self.assertIsNone(hm.health_check())
        # ... and that it waits for DB reconnection
        db_wait_mock.assert_called_once()
        # Other exceptions should raise
        self.assertRaises(TestException, hm.health_check)
        self.assertEqual(4, mock_session.rollback.call_count) 
开发者ID:openstack,项目名称:octavia,代码行数:38,代码来源:test_health_manager.py

示例4: test_update_zone_deadlock_retry

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def test_update_zone_deadlock_retry(self):
        # Create a zone
        zone = self.create_zone(name='example.org.')
        original_serial = zone.serial

        # Update the Object
        zone.email = 'info@example.net'

        # Due to Python's scoping of i - we need to make it a mutable type
        # for the counter to work.. In Py3, we can use the nonlocal keyword.
        i = [False]

        def fail_once_then_pass():
            if i[0] is True:
                return self.central_service.storage.session.commit()
            else:
                i[0] = True
                raise db_exception.DBDeadlock()

        with mock.patch.object(self.central_service.storage, 'commit',
                          side_effect=fail_once_then_pass):
            # Perform the update
            zone = self.central_service.update_zone(
                self.admin_context, zone)

        # Ensure i[0] is True, indicating the side_effect code above was
        # triggered
        self.assertTrue(i[0])

        # Ensure the zone was updated correctly
        self.assertGreater(zone.serial, original_serial)
        self.assertEqual('info@example.net', zone.email) 
开发者ID:openstack,项目名称:designate,代码行数:34,代码来源:test_service.py

示例5: test_update_recordset_deadlock_retry

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def test_update_recordset_deadlock_retry(self):
        # Create a zone
        zone = self.create_zone()

        # Create a recordset
        recordset = self.create_recordset(zone)

        # Update the recordset
        recordset.ttl = 1800

        # Due to Python's scoping of i - we need to make it a mutable type
        # for the counter to work.. In Py3, we can use the nonlocal keyword.
        i = [False]

        def fail_once_then_pass():
            if i[0] is True:
                return self.central_service.storage.session.commit()
            else:
                i[0] = True
                raise db_exception.DBDeadlock()

        with mock.patch.object(self.central_service.storage, 'commit',
                               side_effect=fail_once_then_pass):
            # Perform the update
            recordset = self.central_service.update_recordset(
                self.admin_context, recordset)

        # Ensure i[0] is True, indicating the side_effect code above was
        # triggered
        self.assertTrue(i[0])

        # Ensure the recordset was updated correctly
        self.assertEqual(1800, recordset.ttl) 
开发者ID:openstack,项目名称:designate,代码行数:35,代码来源:test_service.py

示例6: _retry_on_deadlock

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def _retry_on_deadlock(exc):
    """Filter to trigger retry a when a Deadlock is received."""
    # TODO(kiall): This is a total leak of the SQLA Driver, we'll need a better
    #              way to handle this.
    if isinstance(exc, db_exception.DBDeadlock):
        LOG.warning("Deadlock detected. Retrying...")
        return True
    return False 
开发者ID:openstack,项目名称:designate,代码行数:10,代码来源:__init__.py

示例7: _run_deadlock_detect_test

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def _run_deadlock_detect_test(
        self, dialect_name, message,
        orig_exception_cls=TestsExceptionFilter.OperationalError):
        self._run_test(
            dialect_name, self.statement,
            orig_exception_cls(message),
            exception.DBDeadlock,
            params=self.params
        ) 
开发者ID:openstack,项目名称:oslo.db,代码行数:11,代码来源:test_exc_filters.py

示例8: test_retry_wrapper_deadlock

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def test_retry_wrapper_deadlock(self, mock_sleep):

        # Tests that jitter is False, if the retry wrapper hits a
        # non-deadlock error
        @api.wrap_db_retry(max_retries=1, retry_on_deadlock=True)
        def some_method_no_deadlock():
            raise exception.RetryRequest(ValueError())
        with mock.patch(
                'oslo_db.api.wrap_db_retry._get_inc_interval') as mock_get:
            mock_get.return_value = 2, 2
            self.assertRaises(ValueError, some_method_no_deadlock)
            mock_get.assert_called_once_with(1, False)

        # Tests that jitter is True, if the retry wrapper hits a deadlock
        # error.
        @api.wrap_db_retry(max_retries=1, retry_on_deadlock=True)
        def some_method_deadlock():
            raise exception.DBDeadlock('test')
        with mock.patch(
                'oslo_db.api.wrap_db_retry._get_inc_interval') as mock_get:
            mock_get.return_value = 0.1, 2
            self.assertRaises(exception.DBDeadlock, some_method_deadlock)
            mock_get.assert_called_once_with(1, True)

        # Tests that jitter is True, if the jitter is enable by user
        @api.wrap_db_retry(max_retries=1, retry_on_deadlock=True, jitter=True)
        def some_method_no_deadlock_exp():
            raise exception.RetryRequest(ValueError())
        with mock.patch(
                'oslo_db.api.wrap_db_retry._get_inc_interval') as mock_get:
            mock_get.return_value = 0.1, 2
            self.assertRaises(ValueError, some_method_no_deadlock_exp)
            mock_get.assert_called_once_with(1, True) 
开发者ID:openstack,项目名称:oslo.db,代码行数:35,代码来源:test_api.py

示例9: _retry_on_deadlock

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def _retry_on_deadlock(f):
    """Decorator to retry a DB API call if Deadlock was received."""
    @functools.wraps(f)
    def wrapped(*args, **kwargs):
        while True:
            try:
                return f(*args, **kwargs)
            except db_exc.DBDeadlock:
                LOG.warning("Deadlock detected when running '%(func_name)s':"
                            " Retrying...", dict(func_name=f.__name__))
                # Retry!
                time.sleep(0.5)
                continue
    functools.update_wrapper(wrapped, f)
    return wrapped 
开发者ID:openstack,项目名称:karbor,代码行数:17,代码来源:api.py

示例10: is_retriable

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def is_retriable(exception):
    """Determine if the said exception is retriable.

    :param exception: The exception to check.
    :returns: True if 'exception' is retriable, otherwise False.
    """
    if _is_nested_instance(exception,
                           (db_exc.DBDeadlock, exc.StaleDataError,
                            db_exc.DBConnectionError,
                            db_exc.DBDuplicateEntry, db_exc.RetryRequest)):
        return True
    # Look for savepoints mangled by deadlocks. See bug/1590298 for details.
    return (_is_nested_instance(exception, db_exc.DBError) and
            '1305' in str(exception)) 
开发者ID:openstack,项目名称:neutron-lib,代码行数:16,代码来源:utils.py

示例11: is_retriable

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def is_retriable(e):
    """Determine if the exception is retriable.

    :param e: The exception to check.
    :returns: True if e is retriable and False otherwise.
    """
    if getattr(e, '_RETRY_EXCEEDED', False):
        return False
    if _is_nested_instance(e, (db_exc.DBDeadlock, exc.StaleDataError,
                               db_exc.DBConnectionError,
                               db_exc.DBDuplicateEntry, db_exc.RetryRequest,
                               obj_exc.NeutronDbObjectDuplicateEntry)):
        return True
    # looking savepoints mangled by deadlocks. see bug/1590298 for details.
    return _is_nested_instance(e, db_exc.DBError) and '1305' in str(e) 
开发者ID:openstack,项目名称:neutron-lib,代码行数:17,代码来源:api.py

示例12: test_multi_exception_contains_deadlock

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def test_multi_exception_contains_deadlock(self):
        e = exceptions.MultipleExceptions([ValueError(), db_exc.DBDeadlock()])
        self.assertIsNone(self._decorated_function(1, e)) 
开发者ID:openstack,项目名称:neutron-lib,代码行数:5,代码来源:test_api.py

示例13: test_multi_nested_exception_contains_deadlock

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def test_multi_nested_exception_contains_deadlock(self):
        i = exceptions.MultipleExceptions([ValueError(), db_exc.DBDeadlock()])
        e = exceptions.MultipleExceptions([ValueError(), i])
        self.assertIsNone(self._decorated_function(1, e)) 
开发者ID:openstack,项目名称:neutron-lib,代码行数:6,代码来源:test_api.py

示例14: test_multi_exception_raised_on_exceed

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def test_multi_exception_raised_on_exceed(self):
        # limit retries so this doesn't take 40 seconds
        retry_fixture = fixture.DBRetryErrorsFixture(max_retries=2)
        retry_fixture.setUp()
        e = exceptions.MultipleExceptions([ValueError(), db_exc.DBDeadlock()])
        with testtools.ExpectedException(exceptions.MultipleExceptions):
            self._decorated_function(db_api.MAX_RETRIES + 1, e)
        retry_fixture.cleanUp() 
开发者ID:openstack,项目名称:neutron-lib,代码行数:10,代码来源:test_api.py

示例15: test_all_deadlock_time_elapsed

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBDeadlock [as 别名]
def test_all_deadlock_time_elapsed(self):
        self._test_retry_time_cost(db_exc.DBDeadlock) 
开发者ID:openstack,项目名称:neutron-lib,代码行数:4,代码来源:test_api.py


注:本文中的oslo_db.exception.DBDeadlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。