From 59520d6006ce3d6eccda25d81a5155d5328fbd96 Mon Sep 17 00:00:00 2001 From: Harald Jensas Date: Tue, 16 Jan 2018 21:15:22 +0100 Subject: [PATCH] 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 (cherry picked from commit f84781f246004651e0636f8b6507ee1e48bac6b0) --- neutron/services/segments/db.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/neutron/services/segments/db.py b/neutron/services/segments/db.py index ef383d03cde..a2ff5bc8748 100644 --- a/neutron/services/segments/db.py +++ b/neutron/services/segments/db.py @@ -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(