Skip to content

Commit 89eb9e4

Browse files
committed
Split Hash Ring probing from the maintenance task
This patch split out the Hash Ring probing out of the maitenance task into it's own thread. The idea is to speed up the start of probing by doing it right after adding a node to the Hash Ring. By doing that, we avoid the problem of delaying probing in case the connection with OVSDB takes longer than expected to connect and the hash ring nodes are considered dead as they weren't probed in time. The patch re-uses the same classes as before to start this new thread (instead of reusing the maintenance task thread). It adds a layer of synchronization with a lock to make sure that only one new Hash Ring probing thread is started. (cherry picked from commit 240f2c6) Closes-Bug: #1991655 Change-Id: Ic04493f20eb9aecda563942c51f343dc4202523a Signed-off-by: Lucas Alvares Gomes <[email protected]>
1 parent 3a0e2ba commit 89eb9e4

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import copy
1717
import datetime
1818
import functools
19+
import multiprocessing
1920
import operator
2021
import signal
2122
import threading
@@ -34,6 +35,7 @@
3435
from neutron_lib.plugins import directory
3536
from neutron_lib.plugins.ml2 import api
3637
from neutron_lib.utils import helpers
38+
from oslo_concurrency import lockutils
3739
from oslo_concurrency import processutils
3840
from oslo_config import cfg
3941
from oslo_db import exception as os_db_exc
@@ -110,6 +112,8 @@ def initialize(self):
110112
self._plugin_property = None
111113
self._ovn_client_inst = None
112114
self._maintenance_thread = None
115+
self._hash_ring_thread = None
116+
self._hash_ring_probe_event = multiprocessing.Event()
113117
self.node_uuid = None
114118
self.hash_ring_group = ovn_const.HASH_RING_ML2_GROUP
115119
self.sg_enabled = ovn_acl.is_sg_enabled()
@@ -326,6 +330,17 @@ def should_post_fork_initialize(worker_class):
326330
worker.MaintenanceWorker,
327331
service.RpcWorker)
328332

333+
@lockutils.synchronized('hash_ring_probe_lock', external=True)
334+
def _start_hash_ring_probe(self):
335+
if not self._hash_ring_probe_event.is_set():
336+
self._hash_ring_thread = maintenance.MaintenanceThread()
337+
self._hash_ring_thread.add_periodics(
338+
maintenance.HashRingHealthCheckPeriodics(
339+
self.hash_ring_group))
340+
self._hash_ring_thread.start()
341+
LOG.info("Hash Ring probing thread has started")
342+
self._hash_ring_probe_event.set()
343+
329344
def post_fork_initialize(self, resource, event, trigger, payload=None):
330345
# Initialize API/Maintenance workers with OVN IDL connections
331346
worker_class = ovn_utils.get_method_class(trigger)
@@ -339,6 +354,7 @@ def post_fork_initialize(self, resource, event, trigger, payload=None):
339354
admin_context = n_context.get_admin_context()
340355
self.node_uuid = ovn_hash_ring_db.add_node(admin_context,
341356
self.hash_ring_group)
357+
self._start_hash_ring_probe()
342358

343359
n_agent.AgentCache(self) # Initialize singleton agent cache
344360
self.nb_ovn, self.sb_ovn = impl_idl_ovn.get_ovn_idls(self, trigger)
@@ -383,10 +399,8 @@ def post_fork_initialize(self, resource, event, trigger, payload=None):
383399
self._maintenance_thread = maintenance.MaintenanceThread()
384400
self._maintenance_thread.add_periodics(
385401
maintenance.DBInconsistenciesPeriodics(self._ovn_client))
386-
self._maintenance_thread.add_periodics(
387-
maintenance.HashRingHealthCheckPeriodics(
388-
self.hash_ring_group))
389402
self._maintenance_thread.start()
403+
LOG.info("Maintenance task thread has started")
390404

391405
def _create_security_group_precommit(self, resource, event, trigger,
392406
payload):

0 commit comments

Comments
 (0)