Spread OVN metadata agent heartbeat response in time

To avoid mass response of OVN metadata agents on
heartbeat update - event on OVN Southbound
SB_Global table nb_cfg entry increment, this patch postpone
Chassis/Chassis_Private table update for random number
of seconds in range of ( cfg.CONF.agent_down_time // 2 ).

Related-Bug: #1991817
Change-Id: I6373a3c213b24ec957e4d2ea7fc42524517d10d5
This commit is contained in:
labedz 2022-09-28 10:42:38 +00:00
parent 075fb6b874
commit 628442aed7

View File

@ -14,12 +14,14 @@
import collections import collections
import functools import functools
from random import randint
import re import re
import threading import threading
import uuid import uuid
from neutron_lib import constants as n_const from neutron_lib import constants as n_const
from oslo_concurrency import lockutils from oslo_concurrency import lockutils
from oslo_config import cfg
from oslo_log import log from oslo_log import log
from oslo_utils import netutils from oslo_utils import netutils
from ovsdbapp.backend.ovs_idl import event as row_event from ovsdbapp.backend.ovs_idl import event as row_event
@ -34,10 +36,12 @@ from neutron.agent.ovn.metadata import server as metadata_server
from neutron.common.ovn import constants as ovn_const from neutron.common.ovn import constants as ovn_const
from neutron.common.ovn import utils as ovn_utils from neutron.common.ovn import utils as ovn_utils
from neutron.common import utils from neutron.common import utils
from neutron.conf.agent.database import agents_db
from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as config from neutron.conf.plugins.ml2.drivers.ovn import ovn_conf as config
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
agents_db.register_db_agents_opts()
_SYNC_STATE_LOCK = lockutils.ReaderWriterLock() _SYNC_STATE_LOCK = lockutils.ReaderWriterLock()
CHASSIS_METADATA_LOCK = 'chassis_metadata_lock' CHASSIS_METADATA_LOCK = 'chassis_metadata_lock'
@ -184,14 +188,27 @@ class SbGlobalUpdateEvent(row_event.RowEvent):
events = (self.ROW_UPDATE,) events = (self.ROW_UPDATE,)
super(SbGlobalUpdateEvent, self).__init__(events, table, None) super(SbGlobalUpdateEvent, self).__init__(events, table, None)
self.event_name = self.__class__.__name__ self.event_name = self.__class__.__name__
self.first_run = True
def run(self, event, row, old): def run(self, event, row, old):
table = ('Chassis_Private' if self.agent.has_chassis_private
else 'Chassis') def _update_chassis(self, row):
self.agent.sb_idl.db_set( table = ('Chassis_Private' if self.agent.has_chassis_private
table, self.agent.chassis, ('external_ids', { else 'Chassis')
ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY: self.agent.sb_idl.db_set(
str(row.nb_cfg)})).execute() table, self.agent.chassis, ('external_ids', {
ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY:
str(row.nb_cfg)})).execute()
if self.first_run:
interval = 0
self.first_run = False
else:
interval = randint(0, cfg.CONF.agent_down_time // 2)
LOG.debug("Delaying updating chassis table for %s seconds", interval)
timer = threading.Timer(interval, _update_chassis, [self, row])
timer.start()
class MetadataAgent(object): class MetadataAgent(object):