Browse Source

Increase nb_cfg when needed only (reducing the # of transactions)

Prior to this patch, any transaction to NBDB would result in the nb_cfg
from NBDB being increased by 1. That would propagated to the SBDB and
the metadata agent would get an event which would result in yet another
transaction being created to update the Chassis' external_ids (SBDB)
column to inform that the agent was alive.

This patch is changing that behavior to bump the nb_cfg only when
the get_agents() API call is invoked which would reduce the number
of transactions created in the SBDB due to our current health check
mechanism.

Closes-Bug: #1814698
Change-Id: I6f91955444e0601f10f2d5e509d4a4453def5f2b
Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
tags/6.0.0.0b1
Lucas Alvares Gomes 3 months ago
parent
commit
9ee16bf283

+ 4
- 1
networking_ovn/ml2/mech_driver.py View File

@@ -986,7 +986,10 @@ class OVNMechanismDriver(api.MechanismDriver):
986 986
 
987 987
     def ping_chassis(self):
988 988
         """Update NB_Global.nb_cfg so that Chassis.nb_cfg will increment"""
989
-        self._nb_ovn.check_liveness().execute(check_error=True)
989
+
990
+        with self._nb_ovn.create_transaction(check_error=True,
991
+                                             bump_nb_cfg=True) as txn:
992
+            txn.add(self._nb_ovn.check_liveness())
990 993
 
991 994
 
992 995
 def get_agents(self, context, filters=None, fields=None, _driver=None):

+ 12
- 2
networking_ovn/ovsdb/impl_idl_ovn.py View File

@@ -41,7 +41,16 @@ LOG = log.getLogger(__name__)
41 41
 
42 42
 
43 43
 class OvnNbTransaction(idl_trans.Transaction):
44
+
45
+    def __init__(self, *args, **kwargs):
46
+        # NOTE(lucasagomes): The bump_nb_cfg parameter is only used by
47
+        # the agents health status check
48
+        self.bump_nb_cfg = kwargs.pop('bump_nb_cfg', False)
49
+        super(OvnNbTransaction, self).__init__(*args, **kwargs)
50
+
44 51
     def pre_commit(self, txn):
52
+        if not self.bump_nb_cfg:
53
+            return
45 54
         self.api.nb_global.increment('nb_cfg')
46 55
 
47 56
 
@@ -156,10 +165,11 @@ class OvsdbNbOvnIdl(nb_impl_idl.OvnNbApiIdlImpl, Backend):
156 165
     def nb_global(self):
157 166
         return next(iter(self.tables['NB_Global'].rows.values()))
158 167
 
159
-    def create_transaction(self, check_error=False, log_errors=True):
168
+    def create_transaction(self, check_error=False, log_errors=True,
169
+                           bump_nb_cfg=False):
160 170
         return OvnNbTransaction(
161 171
             self, self.ovsdb_connection, self.ovsdb_connection.timeout,
162
-            check_error, log_errors)
172
+            check_error, log_errors, bump_nb_cfg=bump_nb_cfg)
163 173
 
164 174
     @contextlib.contextmanager
165 175
     def transaction(self, *args, **kwargs):

+ 9
- 10
networking_ovn/tests/functional/test_metadata_agent.py View File

@@ -106,18 +106,17 @@ class TestMetadataAgent(base.TestOVNFunctionalBase):
106 106
         self.assertNotIn(ovn_const.OVN_AGENT_METADATA_SB_CFG_KEY,
107 107
                          chassis_row['external_ids'])
108 108
 
109
-        # Let's create a network to force a transaction (actually 2: one for
110
-        # the logical switch and another one for the metadata port) on NB db
111
-        # which will automatically increment the nb_cfg counter on NB_Global
112
-        # and make ovn-controller copy it over to SB_Global. Upon this event,
113
-        # Metadata agent will update the external_ids on its Chassis row to
114
-        # signal that it's healthy.
115
-        row_event = MetadataAgentHealthEvent(self.chassis_name, 2)
109
+        # Let's list the agents to force the nb_cfg to be bumped on NB
110
+        # db, which will automatically increment the nb_cfg counter on
111
+        # NB_Global and make ovn-controller copy it over to SB_Global. Upon
112
+        # this event, Metadata agent will update the external_ids on its
113
+        # Chassis row to signal that it's healthy.
114
+
115
+        row_event = MetadataAgentHealthEvent(self.chassis_name, 1)
116 116
         self.handler.watch_event(row_event)
117
-        self._make_network(self.fmt, 'n1', True)
117
+        self.new_list_request('agents').get_response(self.api)
118 118
 
119 119
         # If we do not time out waiting for the event, then we are assured
120 120
         # that the metadata agent has populated the external_ids from the
121
-        # chassis with the nb_cfg, 2 revisions, one for the network transaction
122
-        # and another one for the port
121
+        # chassis with the nb_cfg, 1 revisions when listing the agents.
123 122
         self.assertTrue(row_event.wait())

Loading…
Cancel
Save