Browse Source

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

Zuul 2 months ago
parent
commit
49c5aaf2b2

+ 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

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

Loading…
Cancel
Save