Add retry decorator update_segment_host_mapping()

When multiple agents register at the same time there is
a possible race condition causing segment host mappings
updates to fail. StaleDataError raised by SQLAlchemy ORM.

Adding retry_if_session_inactive() decorator to the method
fixes the issue.

Also serialize the method with lockutils. It takes 25+
seconds to update segment host mappings for 10 agents with
the retry decorator alone. With the method serialized the
same operation completes in less than 1 second. The retry
decorator is still required for active/active scenarios.

Closes-Bug: #1743579
Change-Id: I616457f094d000a4016c610b454be8269d9b4948
This commit is contained in:
Harald Jensas 2018-01-16 21:15:22 +01:00
parent 01c99152f9
commit f84781f246
1 changed files with 3 additions and 0 deletions

View File

@ -20,6 +20,7 @@ from neutron_lib.callbacks import resources
from neutron_lib import constants
from neutron_lib import exceptions as n_exc
from neutron_lib.plugins import directory
from oslo_concurrency import lockutils
from oslo_db import exception as db_exc
from oslo_log import helpers as log_helpers
from oslo_utils import uuidutils
@ -180,6 +181,8 @@ class SegmentDbMixin(common_db_mixin.CommonDbMixin):
segment=segment_dict)
@db_api.retry_if_session_inactive()
@lockutils.synchronized('update_segment_host_mapping')
def update_segment_host_mapping(context, host, current_segment_ids):
with db_api.context_manager.writer.using(context):
segment_host_mapping = network.SegmentHostMapping.get_objects(