]> git.proxmox.com Git - mirror_ovs.git/commitdiff
ovsdb-tool: Add a db consistency check to the ovsdb-tool check-cluster command.
authorFederico Paolinelli <fpaoline@redhat.com>
Thu, 30 Jul 2020 10:41:47 +0000 (12:41 +0200)
committerIlya Maximets <i.maximets@ovn.org>
Tue, 15 Sep 2020 22:11:27 +0000 (00:11 +0200)
There are some occurrences where the database ends up in an inconsistent
state. This happened in ovn-k8s and is described in [0].
Here we are adding a supported way to check that a given db is consistent,
which is less error prone than checking the logs.

Tested against both a valid db and a corrupted db attached to the
above bug [1]. Also, tested  with a fresh db that did not do a snapshot.

[0]: https://bugzilla.redhat.com/show_bug.cgi?id=1837953#c23
[1]: https://bugzilla.redhat.com/attachment.cgi?id=1697595

Signed-off-by: Federico Paolinelli <fpaoline@redhat.com>
Suggested-by: Dumitru Ceara <dceara@redhat.com>
Acked-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
ovsdb/ovsdb-tool.c

index 91662cab840476153c0e0dfa1920fe855b2774b3..30d0472b263e5984137ac3635ac170d4b12893b0 100644 (file)
@@ -1497,6 +1497,44 @@ do_check_cluster(struct ovs_cmdl_context *ctx)
         }
     }
 
+    /* Check for db consistency:
+     * The serverid must be in the servers list.
+     */
+
+    for (struct server *s = c.servers; s < &c.servers[c.n_servers]; s++) {
+        struct shash *servers_obj = json_object(s->snap->servers);
+        char *server_id = xasprintf(SID_FMT, SID_ARGS(&s->header.sid));
+        bool found = false;
+        const struct shash_node *node;
+
+        SHASH_FOR_EACH (node, servers_obj) {
+            if (!strncmp(server_id, node->name, SID_LEN)) {
+                found = true;
+            }
+        }
+
+        if (!found) {
+            for (struct raft_entry *e = s->entries;
+                 e < &s->entries[s->log_end - s->log_start]; e++) {
+                if (e->servers == NULL) {
+                    continue;
+                }
+                struct shash *log_servers_obj = json_object(e->servers);
+                SHASH_FOR_EACH (node, log_servers_obj) {
+                    if (!strncmp(server_id, node->name, SID_LEN)) {
+                        found = true;
+                    }
+                }
+            }
+        }
+
+        if (!found) {
+            ovs_fatal(0, "%s: server %s not found in server list",
+                      s->filename, server_id);
+        }
+        free(server_id);
+    }
+
     /* Clean up. */
 
     for (size_t i = 0; i < c.n_servers; i++) {