[ovs-dev] [PATCH 5/7] ovsdb-tool: Read server headers first, before full logs, in "check-cluster".

Ben Pfaff blp at ovn.org
Thu Jul 26 17:09:44 UTC 2018


Having the headers available before reading the complete logs means that
server IDs can be associated with the server file names earlier, which can
improve error messages in some cases.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 ovsdb/ovsdb-tool.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index 13df11014374..6832ef7c17c0 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -1001,6 +1001,7 @@ do_show_log(struct ovs_cmdl_context *ctx)
 }
 
 struct server {
+    struct ovsdb_log *log;
     const char *filename;
     const char *nickname;
 
@@ -1164,17 +1165,17 @@ do_check_cluster(struct ovs_cmdl_context *ctx)
         struct server *s = &c.servers[c.n_servers];
         s->filename = ctx->argv[i];
 
-        struct ovsdb_log *log;
         check_ovsdb_error(ovsdb_log_open(s->filename, RAFT_MAGIC,
-                                         OVSDB_LOG_READ_ONLY, -1, &log));
+                                         OVSDB_LOG_READ_ONLY, -1, &s->log));
 
         struct json *json;
-        check_ovsdb_error(ovsdb_log_read(log, &json));
+        check_ovsdb_error(ovsdb_log_read(s->log, &json));
         check_ovsdb_error(raft_header_from_json(&s->header, json));
         json_destroy(json);
 
         if (s->header.joining) {
             printf("%s has not joined the cluster, omitting\n", s->filename);
+            ovsdb_log_close(s->log);
             continue;
         }
         if (c.n_servers > 0) {
@@ -1191,6 +1192,10 @@ do_check_cluster(struct ovs_cmdl_context *ctx)
                           s->filename, s->header.name);
             }
         }
+        c.n_servers++;
+    }
+
+    for (struct server *s = c.servers; s < &c.servers[c.n_servers]; s++) {
         s->snap = &s->header.snap;
         s->log_start = s->log_end = s->header.snap_index + 1;
 
@@ -1209,7 +1214,9 @@ do_check_cluster(struct ovs_cmdl_context *ctx)
                 s->records = x2nrealloc(s->records, &allocated_records,
                                         sizeof *s->records);
             }
-            check_ovsdb_error(ovsdb_log_read(log, &json));
+
+            struct json *json;
+            check_ovsdb_error(ovsdb_log_read(s->log, &json));
             if (!json) {
                 break;
             }
@@ -1230,7 +1237,6 @@ do_check_cluster(struct ovs_cmdl_context *ctx)
                 max_term = term;
             }
 
-
             switch (r->type) {
             case RAFT_REC_ENTRY:
                 if (r->entry.index < commit_index) {
@@ -1359,9 +1365,8 @@ do_check_cluster(struct ovs_cmdl_context *ctx)
             }
         }
 
-        ovsdb_log_close(log);
-
-        c.n_servers++;
+        ovsdb_log_close(s->log);
+        s->log = NULL;
     }
 
     /* Check the Leader Completeness property from Figure 3.2: If a log entry
-- 
2.16.1



More information about the dev mailing list