On Mon, Aug 3, 2020 at 8:05 AM Dumitru Ceara <[email protected]> wrote: > > 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 <[email protected]> > --- > ovsdb/ovsdb-server.c | 39 +++++++++++++++++++++++++++++++++++++++ > ovsdb/storage.c | 10 ++++++++++ > ovsdb/storage.h | 1 + > 3 files changed, 50 insertions(+) > > diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c > index ef4e996..52107f0 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. */ > @@ -1697,6 +1701,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 7b4ad16..f662e90 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 a223968..02b6e7e 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 *); > -- > 1.8.3.1 > > _______________________________________________ > dev mailing list > [email protected] > https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Thanks Dumitru! Acked-by: Han Zhou <[email protected]> _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
