Rollback db session in case of error during releasing quota reservation
Patch [1] changed to not fail if DBError will happend when releasing quota reservation. That may lead to the errors while commiting db transaction in the neutron/api/v2/base.py module when in same transaction Neutron commits reservation (which removes reservation from db) and then set resources dirty. In case if DB error happens in the commit_reservation() and we will simply pass this error and move on, transaction can't be commited without rollback. This patch adds handle of such DBErrors in the remove_reservation function so transaction can be rolled back in case of DB error happens. [1] https://review.opendev.org/c/openstack/neutron/+/805031 Closes-Bug: #1943714 Change-Id: I295a4f0eb1eaf0286f0e34b96db29c8f08340b84
This commit is contained in:
parent
d1a89af312
commit
f8f50397ca
@ -19,7 +19,6 @@ import datetime
|
|||||||
from neutron_lib.db import api as db_api
|
from neutron_lib.db import api as db_api
|
||||||
from oslo_db import exception as db_exc
|
from oslo_db import exception as db_exc
|
||||||
|
|
||||||
from neutron.common import utils
|
|
||||||
from neutron.objects import quota as quota_obj
|
from neutron.objects import quota as quota_obj
|
||||||
|
|
||||||
|
|
||||||
@ -202,21 +201,24 @@ def get_reservation(context, reservation_id):
|
|||||||
for delta in reserv_obj.resource_deltas))
|
for delta in reserv_obj.resource_deltas))
|
||||||
|
|
||||||
|
|
||||||
@utils.skip_exceptions(db_exc.DBError)
|
|
||||||
@db_api.CONTEXT_WRITER
|
@db_api.CONTEXT_WRITER
|
||||||
def remove_reservation(context, reservation_id, set_dirty=False):
|
def remove_reservation(context, reservation_id, set_dirty=False):
|
||||||
reservation = quota_obj.Reservation.get_object(context, id=reservation_id)
|
try:
|
||||||
if not reservation:
|
reservation = quota_obj.Reservation.get_object(context,
|
||||||
# TODO(salv-orlando): Raise here and then handle the exception?
|
id=reservation_id)
|
||||||
return
|
if not reservation:
|
||||||
tenant_id = reservation.project_id
|
# TODO(salv-orlando): Raise here and then handle the exception?
|
||||||
resources = [delta.resource for delta in reservation.resource_deltas]
|
return
|
||||||
reservation.delete()
|
tenant_id = reservation.project_id
|
||||||
if set_dirty:
|
resources = [delta.resource for delta in reservation.resource_deltas]
|
||||||
# quota_usage for all resource involved in this reservation must
|
reservation.delete()
|
||||||
# be marked as dirty
|
if set_dirty:
|
||||||
set_resources_quota_usage_dirty(context, resources, tenant_id)
|
# quota_usage for all resource involved in this reservation must
|
||||||
return 1
|
# be marked as dirty
|
||||||
|
set_resources_quota_usage_dirty(context, resources, tenant_id)
|
||||||
|
return 1
|
||||||
|
except db_exc.DBError:
|
||||||
|
context.session.rollback()
|
||||||
|
|
||||||
|
|
||||||
@db_api.retry_if_session_inactive()
|
@db_api.retry_if_session_inactive()
|
||||||
|
Loading…
Reference in New Issue
Block a user