Allow using database configs on db retry

Allow following db configs when calling wrap_db_retry:
    * database.db_max_retries
    * database.db_retry_interval
    * database.db_inc_retry_interval
    * database.db_max_retry_interval
So database cofig can now control db retries.
Please reference [1] for what each config options can do.

[1] https://opendev.org/openstack/oslo.db/src/branch/master/oslo_db/options.py

Change-Id: I034625733c2d22f0f5635f58e9df3d5785e58cf5
This commit is contained in:
Rico Lin 2020-09-20 14:05:56 +08:00
parent 5609e25765
commit 8daa7e9389
5 changed files with 31 additions and 9 deletions

View File

@ -13,7 +13,6 @@ namespace = heat.api.aws.ec2token
namespace = keystonemiddleware.auth_token
namespace = oslo.messaging
namespace = oslo.middleware
namespace = oslo.db
namespace = oslo.log
namespace = oslo.policy
namespace = oslo.service.service

View File

@ -16,6 +16,7 @@ import os
from eventlet.green import socket
from oslo_config import cfg
from oslo_db import options as oslo_db_ops
from oslo_log import log as logging
from oslo_middleware import cors
from osprofiler import opts as profiler
@ -469,6 +470,7 @@ def list_opts():
yield 'clients_keystone', keystone_client_opts
yield 'clients_nova', client_http_log_debug_opts
yield 'clients_cinder', client_http_log_debug_opts
yield oslo_db_ops.list_opts()[0]
cfg.CONF.register_group(paste_deploy_group)

View File

@ -49,6 +49,12 @@ CONF = cfg.CONF
CONF.import_opt('hidden_stack_tags', 'heat.common.config')
CONF.import_opt('max_events_per_stack', 'heat.common.config')
CONF.import_group('profiler', 'heat.common.config')
CONF.import_opt('db_max_retries', 'oslo_db.options', group='database')
CONF.import_opt('db_retry_interval', 'oslo_db.options', group='database')
CONF.import_opt(
'db_inc_retry_interval', 'oslo_db.options', group='database')
CONF.import_opt(
'db_max_retry_interval', 'oslo_db.options', group='database')
options.set_defaults(CONF)
@ -94,11 +100,13 @@ def retry_on_db_error(func):
def try_func(context, *args, **kwargs):
if (context.session.transaction is None or
not context.session.autocommit):
wrapped = oslo_db_api.wrap_db_retry(max_retries=3,
retry_on_deadlock=True,
retry_on_disconnect=True,
retry_interval=0.5,
inc_retry_interval=True)(func)
wrapped = oslo_db_api.wrap_db_retry(
max_retries=CONF.database.db_max_retries,
retry_on_deadlock=True,
retry_on_disconnect=True,
retry_interval=CONF.database.db_retry_interval,
inc_retry_interval=CONF.database.db_inc_retry_interval,
max_retry_interval=CONF.database.db_max_retry_interval)(func)
return wrapped(context, *args, **kwargs)
else:
try:

View File

@ -1835,7 +1835,7 @@ class DBAPIStackTest(common.HeatTestCase):
side_effect=db_exception.DBDeadlock) as mock_update:
self.assertRaises(db_exception.DBDeadlock,
db_api.stack_update, self.ctx, stack.id, {})
self.assertEqual(4, mock_update.call_count)
self.assertEqual(21, mock_update.call_count)
def test_stack_set_status_release_lock(self):
stack = create_stack(self.ctx, self.template, self.user_creds)
@ -2619,7 +2619,7 @@ class DBAPIResourceTest(common.HeatTestCase):
self.assertRaises(db_exception.DBDeadlock,
db_api.resource_purge_deleted,
self.ctx, self.stack.id)
self.assertEqual(4, mock_delete.call_count)
self.assertEqual(21, mock_delete.call_count)
def test_engine_get_all_locked_by_stack(self):
values = [
@ -3380,7 +3380,7 @@ class DBAPISyncPointTest(common.HeatTestCase):
self.ctx, entity_id=str(res.id),
stack_id=self.stack.id,
traversal_id=self.stack.current_traversal)
self.assertEqual(len(self.resources) * 4, add.call_count)
self.assertEqual(len(self.resources) * 21, add.call_count)
class DBAPIMigratePropertiesDataTest(common.HeatTestCase):

View File

@ -0,0 +1,13 @@
---
fixes:
- |
Oslo db config is able to control wrap_db_retry call in heat.
We remove hard coded settings for wrap_db_retry and use following
configs from oslo_db instead.
* database.db_max_retries
* database.db_retry_interval
* database.db_inc_retry_interval
* database.db_max_retry_interval
So database cofig can now control db retries.
Please reference [1] for what each config options can do.
[1] https://opendev.org/openstack/oslo.db/src/branch/master/oslo_db/options.py