Skip to content

Commit e2a2cc2

Browse files
committed
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 (cherry picked from commit 39d751a)
1 parent 5cc41f0 commit e2a2cc2

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

neutron/db/ovn_revision_numbers_db.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,18 @@ def _ensure_revision_row_exist(context, resource, resource_type, std_attr_id):
136136
# deal with objects that already existed before the sync work. I believe
137137
# that we can remove this method after few development cycles. Or,
138138
# if we decide to make a migration script as well.
139-
with db_api.CONTEXT_READER.using(context):
140-
if not context.session.query(ovn_models.OVNRevisionNumbers).filter_by(
141-
resource_uuid=resource['id'],
142-
resource_type=resource_type).one_or_none():
143-
LOG.warning(
144-
'No revision row found for %(res_uuid)s (type: '
145-
'%(res_type)s) when bumping the revision number. '
146-
'Creating one.', {'res_uuid': resource['id'],
147-
'res_type': resource_type})
148-
create_initial_revision(context, resource['id'], resource_type,
149-
std_attr_id=std_attr_id)
139+
if context.session.query(ovn_models.OVNRevisionNumbers).filter_by(
140+
resource_uuid=resource['id'],
141+
resource_type=resource_type).one_or_none():
142+
return
143+
144+
LOG.warning(
145+
'No revision row found for %(res_uuid)s (type: '
146+
'%(res_type)s) when bumping the revision number. '
147+
'Creating one.', {'res_uuid': resource['id'],
148+
'res_type': resource_type})
149+
create_initial_revision(context, resource['id'], resource_type,
150+
std_attr_id=std_attr_id)
150151

151152

152153
@db_api.retry_if_session_inactive()

0 commit comments

Comments
 (0)