From 39d751a33265e8780828b3aca10a781726d0a300 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Sun, 15 May 2022 01:28:32 +0000 Subject: [PATCH] Refactor the OVN revision module to access the DB correctly Method ``_ensure_revision_row_exist`` creates a DB reader context when called from ``bump_revision``. This call is always done from inside a DB write context. This method removes the unneded reader context. Closes-Bug: #1975837 Change-Id: Ifb500eef5513e930bf3a22d99183ca348e5fc427 --- neutron/db/ovn_revision_numbers_db.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/neutron/db/ovn_revision_numbers_db.py b/neutron/db/ovn_revision_numbers_db.py index f9a67711097..788d605331d 100644 --- a/neutron/db/ovn_revision_numbers_db.py +++ b/neutron/db/ovn_revision_numbers_db.py @@ -136,17 +136,18 @@ def _ensure_revision_row_exist(context, resource, resource_type, std_attr_id): # deal with objects that already existed before the sync work. I believe # that we can remove this method after few development cycles. Or, # if we decide to make a migration script as well. - with db_api.CONTEXT_READER.using(context): - if not context.session.query(ovn_models.OVNRevisionNumbers).filter_by( - resource_uuid=resource['id'], - resource_type=resource_type).one_or_none(): - LOG.warning( - 'No revision row found for %(res_uuid)s (type: ' - '%(res_type)s) when bumping the revision number. ' - 'Creating one.', {'res_uuid': resource['id'], - 'res_type': resource_type}) - create_initial_revision(context, resource['id'], resource_type, - std_attr_id=std_attr_id) + if context.session.query(ovn_models.OVNRevisionNumbers).filter_by( + resource_uuid=resource['id'], + resource_type=resource_type).one_or_none(): + return + + LOG.warning( + 'No revision row found for %(res_uuid)s (type: ' + '%(res_type)s) when bumping the revision number. ' + 'Creating one.', {'res_uuid': resource['id'], + 'res_type': resource_type}) + create_initial_revision(context, resource['id'], resource_type, + std_attr_id=std_attr_id) @db_api.retry_if_session_inactive()