summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDumitru Ceara <dceara@redhat.com>2020-08-03 17:05:28 +0200
committerIlya Maximets <i.maximets@ovn.org>2020-09-16 00:15:37 +0200
commit7024ddf3202646095adfbb1998904abd7b21f6e3 (patch)
treef16082d2ba8a35843792209f45c10638009ac4c4
parent27dc7adf66b1af88f238da46c6430e3d2eaa4da3 (diff)
downloadopenvswitch-7024ddf3202646095adfbb1998904abd7b21f6e3.tar.gz
ovsdb: Add unixctl command to show storage status.
If a database enters an error state, e.g., in case of RAFT when reading the DB file contents if applying the RAFT records triggers constraint violations, there's no way to determine this unless a client generates a write transaction. Such write transactions would fail with "ovsdb-error: inconsistent data". This commit adds a new command to show the status of the storage that's backing a database. Example, on an inconsistent database: $ ovs-appctl -t /tmp/test.ctl ovsdb-server/get-db-storage-status DB status: ovsdb error: inconsistent data Example, on a consistent database: $ ovs-appctl -t /tmp/test.ctl ovsdb-server/get-db-storage-status DB status: ok Signed-off-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Han Zhou <hzhou@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rw-r--r--NEWS3
-rw-r--r--ovsdb/ovsdb-server.c39
-rw-r--r--ovsdb/storage.c10
-rw-r--r--ovsdb/storage.h1
4 files changed, 53 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 2f67d5047..a9c50add2 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
Post-v2.14.0
---------------------
+ - OVSDB:
+ * New unixctl command 'ovsdb-server/get-db-storage-status' to show the
+ status of the storage that's backing a database.
v2.14.0 - 17 Aug 2020
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index fd7891a72..d772edbe0 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -90,6 +90,7 @@ static unixctl_cb_func ovsdb_server_set_active_ovsdb_server_probe_interval;
static unixctl_cb_func ovsdb_server_set_sync_exclude_tables;
static unixctl_cb_func ovsdb_server_get_sync_exclude_tables;
static unixctl_cb_func ovsdb_server_get_sync_status;
+static unixctl_cb_func ovsdb_server_get_db_storage_status;
struct server_config {
struct sset *remotes;
@@ -453,6 +454,9 @@ main(int argc, char *argv[])
unixctl_command_register("ovsdb-server/sync-status", "",
0, 0, ovsdb_server_get_sync_status,
&server_config);
+ unixctl_command_register("ovsdb-server/get-db-storage-status", "DB", 1, 1,
+ ovsdb_server_get_db_storage_status,
+ &server_config);
/* Simulate the behavior of OVS release prior to version 2.5 that
* does not support the monitor_cond method. */
@@ -1702,6 +1706,41 @@ ovsdb_server_get_sync_status(struct unixctl_conn *conn, int argc OVS_UNUSED,
}
static void
+ovsdb_server_get_db_storage_status(struct unixctl_conn *conn,
+ int argc OVS_UNUSED,
+ const char *argv[],
+ void *config_)
+{
+ struct server_config *config = config_;
+ struct shash_node *node;
+
+ node = shash_find(config->all_dbs, argv[1]);
+ if (!node) {
+ unixctl_command_reply_error(conn, "Failed to find the database.");
+ return;
+ }
+
+ struct db *db = node->data;
+
+ if (!db->db) {
+ unixctl_command_reply_error(conn, "Failed to find the database.");
+ return;
+ }
+
+ struct ds ds = DS_EMPTY_INITIALIZER;
+ char *error = ovsdb_storage_get_error(db->db->storage);
+
+ if (!error) {
+ ds_put_cstr(&ds, "status: ok");
+ } else {
+ ds_put_format(&ds, "status: %s", error);
+ free(error);
+ }
+ unixctl_command_reply(conn, ds_cstr(&ds));
+ ds_destroy(&ds);
+}
+
+static void
parse_options(int argc, char *argv[],
struct sset *db_filenames, struct sset *remotes,
char **unixctl_pathp, char **run_command,
diff --git a/ovsdb/storage.c b/ovsdb/storage.c
index 7b4ad16f6..f662e9056 100644
--- a/ovsdb/storage.c
+++ b/ovsdb/storage.c
@@ -198,6 +198,16 @@ ovsdb_storage_get_memory_usage(const struct ovsdb_storage *storage,
}
}
+char *
+ovsdb_storage_get_error(const struct ovsdb_storage *storage)
+{
+ if (storage->error) {
+ return ovsdb_error_to_string(storage->error);
+ }
+
+ return NULL;
+}
+
void
ovsdb_storage_run(struct ovsdb_storage *storage)
{
diff --git a/ovsdb/storage.h b/ovsdb/storage.h
index a22396891..02b6e7e6c 100644
--- a/ovsdb/storage.h
+++ b/ovsdb/storage.h
@@ -42,6 +42,7 @@ const struct uuid *ovsdb_storage_get_sid(const struct ovsdb_storage *);
uint64_t ovsdb_storage_get_applied_index(const struct ovsdb_storage *);
void ovsdb_storage_get_memory_usage(const struct ovsdb_storage *,
struct simap *usage);
+char *ovsdb_storage_get_error(const struct ovsdb_storage *);
void ovsdb_storage_run(struct ovsdb_storage *);
void ovsdb_storage_wait(struct ovsdb_storage *);