Merge "Fast exit when initially creating tunnel allocations"

This commit is contained in:
Zuul 2024-12-18 15:20:51 +00:00 committed by Gerrit Code Review
commit 559672f777
2 changed files with 14 additions and 1 deletions

View File

@ -199,6 +199,17 @@ class _TunnelTypeDriverBase(helpers.SegmentTypeDriver, metaclass=abc.ABCMeta):
tunnel_col = getattr(self.model, self.segmentation_key)
ctx = context.get_admin_context()
with db_api.CONTEXT_WRITER.using(ctx):
# Check if the allocations are updated: if the total number of
# allocations for this tunnel type matches the allocations of the
# specific IDs, fast exit in that case.
# If another worker handled that before or the table was updated
# in a previous Neutron API restart, this section will end here.
num_allocs = ctx.session.query(self.model).filter(
tunnel_col.in_(tunnel_ids)).count()
num_allocs_total = ctx.session.query(self.model).count()
if len(tunnel_ids) == num_allocs == num_allocs_total:
return
# remove from table unallocated tunnels not currently allocatable
# fetch results as list via all() because we'll be iterating
# through them twice

View File

@ -127,7 +127,9 @@ class TunnelTypeTestMixin:
with mock.patch.object(
type_tunnel, 'chunks', side_effect=verify_no_chunk) as chunks:
self.driver.sync_allocations()
self.assertEqual(2, len(chunks.mock_calls))
# No writing operation is done, fast exit: current allocations
# already present.
self.assertEqual(0, len(chunks.mock_calls))
def test_partial_segment_is_partial_segment(self):
segment = {api.NETWORK_TYPE: self.TYPE,