2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 01:51:26 +00:00

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>
This commit is contained in:
Dumitru Ceara 2020-08-03 17:05:28 +02:00 committed by Ilya Maximets
parent 27dc7adf66
commit 7024ddf320
4 changed files with 53 additions and 0 deletions

3
NEWS
View File

@ -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

View File

@ -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. */
@ -1701,6 +1705,41 @@ ovsdb_server_get_sync_status(struct unixctl_conn *conn, int argc OVS_UNUSED,
ds_destroy(&ds);
}
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,

View File

@ -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)
{

View File

@ -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 *);