summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Lin <ricolin@ricolky.com>2020-09-20 14:05:56 +0800
committerRico Lin <ricolin@ricolky.com>2021-02-27 15:42:07 +0800
commit8daa7e938985e0fc34f603debf3a8ba1413d8ff7 (patch)
tree66cf6b6bc2de4cbd068fedd9b0c4317410ba8e45
parent5609e257652a1f6fb87891965c7fafa7194c5575 (diff)
downloadheat-8daa7e938985e0fc34f603debf3a8ba1413d8ff7.tar.gz
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
-rw-r--r--config-generator.conf1
-rw-r--r--heat/common/config.py2
-rw-r--r--heat/db/sqlalchemy/api.py18
-rw-r--r--heat/tests/db/test_sqlalchemy_api.py6
-rw-r--r--releasenotes/notes/honoring_oslo_db_config-bf32711bf99a2e47.yaml13
5 files changed, 31 insertions, 9 deletions
diff --git a/config-generator.conf b/config-generator.conf
index 752851d66..e6e8c910c 100644
--- a/config-generator.conf
+++ b/config-generator.conf
@@ -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
diff --git a/heat/common/config.py b/heat/common/config.py
index 06db5eaab..d0f46b721 100644
--- a/heat/common/config.py
+++ b/heat/common/config.py
@@ -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)
diff --git a/heat/db/sqlalchemy/api.py b/heat/db/sqlalchemy/api.py
index d427c34ac..3672ce036 100644
--- a/heat/db/sqlalchemy/api.py
+++ b/heat/db/sqlalchemy/api.py
@@ -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:
diff --git a/heat/tests/db/test_sqlalchemy_api.py b/heat/tests/db/test_sqlalchemy_api.py
index b7d3f84b5..21fb8b55c 100644
--- a/heat/tests/db/test_sqlalchemy_api.py
+++ b/heat/tests/db/test_sqlalchemy_api.py
@@ -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):
diff --git a/releasenotes/notes/honoring_oslo_db_config-bf32711bf99a2e47.yaml b/releasenotes/notes/honoring_oslo_db_config-bf32711bf99a2e47.yaml
new file mode 100644
index 000000000..8de9ef7d9
--- /dev/null
+++ b/releasenotes/notes/honoring_oslo_db_config-bf32711bf99a2e47.yaml
@@ -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