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
This commit is contained in:
@@ -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
|
# deal with objects that already existed before the sync work. I believe
|
||||||
# that we can remove this method after few development cycles. Or,
|
# that we can remove this method after few development cycles. Or,
|
||||||
# if we decide to make a migration script as well.
|
# if we decide to make a migration script as well.
|
||||||
with db_api.CONTEXT_READER.using(context):
|
if context.session.query(ovn_models.OVNRevisionNumbers).filter_by(
|
||||||
if not context.session.query(ovn_models.OVNRevisionNumbers).filter_by(
|
resource_uuid=resource['id'],
|
||||||
resource_uuid=resource['id'],
|
resource_type=resource_type).one_or_none():
|
||||||
resource_type=resource_type).one_or_none():
|
return
|
||||||
LOG.warning(
|
|
||||||
'No revision row found for %(res_uuid)s (type: '
|
LOG.warning(
|
||||||
'%(res_type)s) when bumping the revision number. '
|
'No revision row found for %(res_uuid)s (type: '
|
||||||
'Creating one.', {'res_uuid': resource['id'],
|
'%(res_type)s) when bumping the revision number. '
|
||||||
'res_type': resource_type})
|
'Creating one.', {'res_uuid': resource['id'],
|
||||||
create_initial_revision(context, resource['id'], resource_type,
|
'res_type': resource_type})
|
||||||
std_attr_id=std_attr_id)
|
create_initial_revision(context, resource['id'], resource_type,
|
||||||
|
std_attr_id=std_attr_id)
|
||||||
|
|
||||||
|
|
||||||
@db_api.retry_if_session_inactive()
|
@db_api.retry_if_session_inactive()
|
||||||
|
Reference in New Issue
Block a user