[ovs-dev] [PATCH ovn 3/3] ovn-northd-ddlog: Move 'delta' global variable into northd_ctx.

Ben Pfaff blp at ovn.org
Wed Mar 10 00:24:40 UTC 2021


Seems overall like a cleanup.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 northd/ovn-northd-ddlog.c | 58 ++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 25 deletions(-)

diff --git a/northd/ovn-northd-ddlog.c b/northd/ovn-northd-ddlog.c
index 80d3aa8d8aeb..4efdfa38749a 100644
--- a/northd/ovn-northd-ddlog.c
+++ b/northd/ovn-northd-ddlog.c
@@ -85,27 +85,29 @@ static void init_table_ids(void)
     NB_CFG_TIMESTAMP_ID = ddlog_get_table_id("NbCfgTimestamp");
 }
 
-/*
- * Accumulates DDlog delta to be sent to OVSDB.
- *
- * FIXME: There is currently no global northd state descriptor shared by NB and
- * SB connections.  We should probably introduce it and move this variable there
- * instead of declaring it as a global variable.
- */
-static ddlog_delta *delta;
-
-
 struct northd_ctx {
+    /* Shared between NB and SB database contexts. */
     ddlog_prog ddlog;
-    char *prefix;
+    ddlog_delta *delta;         /* Accumulated delta to send to OVSDB. */
+
+    /* Database info.
+     *
+     * The '*_relations' vectors are arrays of strings that contain DDlog
+     * relation names, terminated by a null pointer.  'prefix' is the prefix
+     * for the DDlog module that contains the relations. */
+    char *prefix;               /* e.g. "OVN_Northbound::" */
     const char **input_relations;
     const char **output_relations;
     const char **output_only_relations;
 
+    /* Whether this is the database that has the 'nb_cfg_timestamp' and
+     * 'sb_cfg_timestamp' columns in NB_Global.  True for the northbound
+     * database, false for the southbound database. */
     bool has_timestamp_columns;
 
+    /* OVSDB connection. */
     struct ovsdb_cs *cs;
-    struct json *request_id;
+    struct json *request_id; /* JSON request ID for outstanding txn if any.  */
     enum {
         /* Initial state, before the output-only data (if any) has been
          * requested. */
@@ -120,7 +122,7 @@ struct northd_ctx {
     } state;
 
     /* Database info. */
-    const char *db_name;
+    const char *db_name;        /* e.g. "OVN_Northbound". */
     struct json *output_only_data;
     const char *lock_name;      /* Name of lock we need, NULL if none. */
     bool paused;
@@ -154,7 +156,7 @@ static struct northd_ctx *
 northd_ctx_create(const char *server, const char *database,
                   const char *unixctl_command_prefix,
                   const char *lock_name,
-                  ddlog_prog ddlog,
+                  ddlog_prog ddlog, ddlog_delta *delta,
                   const char **input_relations,
                   const char **output_relations,
                   const char **output_only_relations)
@@ -162,6 +164,7 @@ northd_ctx_create(const char *server, const char *database,
     struct northd_ctx *ctx = xmalloc(sizeof *ctx);
     *ctx = (struct northd_ctx) {
         .ddlog = ddlog,
+        .delta = delta,
         .prefix = xasprintf("%s::", database),
         .input_relations = input_relations,
         .output_relations = output_relations,
@@ -317,7 +320,7 @@ warning_cb(uintptr_t arg OVS_UNUSED,
 }
 
 static int
-ddlog_commit(ddlog_prog ddlog)
+ddlog_commit(ddlog_prog ddlog, ddlog_delta *delta)
 {
     ddlog_delta *new_delta = ddlog_transaction_commit_dump_changes(ddlog);
     if (!delta) {
@@ -432,7 +435,7 @@ northd_parse_update(struct northd_ctx *ctx,
     }
 
     /* Commit changes to DDlog. */
-    if (ddlog_commit(ctx->ddlog)) {
+    if (ddlog_commit(ctx->ddlog, ctx->delta)) {
         goto error;
     }
     old_nb_cfg = new_nb_cfg;
@@ -575,7 +578,7 @@ northd_update_probe_interval(struct northd_ctx *nb, struct northd_ctx *sb)
      * database. */
     int probe_interval = 0;
     table_id tid = ddlog_get_table_id("Northd_Probe_Interval");
-    ddlog_delta *probe_delta = ddlog_delta_remove_table(delta, tid);
+    ddlog_delta *probe_delta = ddlog_delta_remove_table(nb->delta, tid);
     ddlog_delta_enumerate(probe_delta, northd_update_probe_interval_cb, (uintptr_t) &probe_interval);
     ddlog_free_delta(probe_delta);
 
@@ -596,7 +599,7 @@ northd_wait(struct northd_ctx *ctx)
 /* Generate OVSDB update command for delta-plus, delta-minus, and delta-update
  * tables. */
 static void
-ddlog_table_update_deltas(struct ds *ds, ddlog_prog ddlog,
+ddlog_table_update_deltas(struct ds *ds, ddlog_prog ddlog, ddlog_delta *delta,
                           const char *db, const char *table)
 {
     int error;
@@ -620,7 +623,7 @@ ddlog_table_update_deltas(struct ds *ds, ddlog_prog ddlog,
 
 /* Generate OVSDB update command for a output-only table. */
 static void
-ddlog_table_update_output(struct ds *ds, ddlog_prog ddlog,
+ddlog_table_update_output(struct ds *ds, ddlog_prog ddlog, ddlog_delta *delta,
                           const char *db, const char *table)
 {
     int error;
@@ -858,7 +861,8 @@ get_database_ops(struct northd_ctx *ctx)
     size_t start_len = ops_s.length;
 
     for (const char **p = ctx->output_relations; *p; p++) {
-        ddlog_table_update_deltas(&ops_s, ctx->ddlog, ctx->db_name, *p);
+        ddlog_table_update_deltas(&ops_s, ctx->ddlog, ctx->delta,
+                                  ctx->db_name, *p);
     }
 
     if (ctx->output_only_data) {
@@ -937,7 +941,8 @@ get_database_ops(struct northd_ctx *ctx)
             /* Discard any queued output to this table, since we just
              * did a full sync to it. */
             struct ds tmp = DS_EMPTY_INITIALIZER;
-            ddlog_table_update_output(&tmp, ctx->ddlog, ctx->db_name, table);
+            ddlog_table_update_output(&tmp, ctx->ddlog, ctx->delta,
+                                      ctx->db_name, table);
             ds_destroy(&tmp);
         }
 
@@ -945,7 +950,8 @@ get_database_ops(struct northd_ctx *ctx)
         ctx->output_only_data = NULL;
     } else {
         for (const char **p = ctx->output_only_relations; *p; p++) {
-            ddlog_table_update_output(&ops_s, ctx->ddlog, ctx->db_name, *p);
+            ddlog_table_update_output(&ops_s, ctx->ddlog, ctx->delta,
+                                      ctx->db_name, *p);
         }
     }
 
@@ -961,7 +967,8 @@ get_database_ops(struct northd_ctx *ctx)
     int64_t new_sb_cfg = old_sb_cfg;
     if (ctx->has_timestamp_columns) {
         table_id sb_cfg_tid = ddlog_get_table_id("SbCfg");
-        ddlog_delta *sb_cfg_delta = ddlog_delta_remove_table(delta, sb_cfg_tid);
+        ddlog_delta *sb_cfg_delta = ddlog_delta_remove_table(ctx->delta,
+                                                             sb_cfg_tid);
         ddlog_delta_enumerate(sb_cfg_delta, northd_update_sb_cfg_cb,
                               (uintptr_t) &new_sb_cfg);
         ddlog_free_delta(sb_cfg_delta);
@@ -1135,6 +1142,7 @@ main(int argc, char *argv[])
 
 
     ddlog_prog ddlog;
+    ddlog_delta *delta;
     ddlog = ddlog_run(1, false, ddlog_print_error, &delta);
     if (!ddlog) {
         ovs_fatal(0, "DDlog instance could not be created");
@@ -1160,10 +1168,10 @@ main(int argc, char *argv[])
     }
 
     struct northd_ctx *nb_ctx = northd_ctx_create(
-        ovnnb_db, "OVN_Northbound", "nb", NULL, ddlog,
+        ovnnb_db, "OVN_Northbound", "nb", NULL, ddlog, delta,
         nb_input_relations, nb_output_relations, nb_output_only_relations);
     struct northd_ctx *sb_ctx = northd_ctx_create(
-        ovnsb_db, "OVN_Southbound", "sb", "ovn_northd", ddlog,
+        ovnsb_db, "OVN_Southbound", "sb", "ovn_northd", ddlog, delta,
         sb_input_relations, sb_output_relations, sb_output_only_relations);
 
     unixctl_command_register("pause", "", 0, 0, ovn_northd_pause, sb_ctx);
-- 
2.29.2



More information about the dev mailing list