ovsdb-tool: Add "show-log" command for use in debugging.
authorBen Pfaff <blp@nicira.com>
Wed, 16 Dec 2009 21:58:33 +0000 (13:58 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 16 Dec 2009 21:58:33 +0000 (13:58 -0800)
ovsdb/ovsdb-tool.1.in
ovsdb/ovsdb-tool.c

index 5671310..b96bdd7 100644 (file)
@@ -18,6 +18,8 @@ ovsdb\-tool \- Open vSwitch database management utility
 .br
 \fBovsdb\-tool \fR[\fIoptions\fR] \fBtransact\fI db transaction\fR
 .br
+\fBovsdb\-tool \fR[\fIoptions\fR] \fBshow\-log\fI db\fR
+.br
 \fBovsdb\-tool help\fR
 .so lib/vlog-syn.man
 .so lib/common-syn.man
@@ -50,7 +52,7 @@ safely run concurrently with other database activity, including
 may specify database modifications, but these will have no effect on
 \fIdb\fR.
 .
-.IQ "\fBtransact\fI db transaction\fR"
+.IP "\fBtransact\fI db transaction\fR"
 Opens \fIdb\fR, executes \fItransaction\fR on it, prints the results,
 and commits any changes to \fIdb\fR.  The \fItransaction\fR must be a
 JSON array in the format of the \fBparams\fR array for the JSON-RPC
@@ -62,6 +64,11 @@ process, including \fBovsdb-server\fR(1).  Use \fBovsdb\-client\fR(1),
 instead, to write to a database that is served by
 \fBovsdb-server\fR(1).
 .
+.IP "\fBshow-log\fI db\fR"
+Prints a summary of the records in \fBdb\fR's log, including the time
+and date at which each database change occurred and any associated
+comment.  This may be useful for debugging.
+.
 .SH OPTIONS
 .SS "Logging Options"
 .so lib/vlog.man
index 61aea75..c318be5 100644 (file)
@@ -103,7 +103,8 @@ usage(void)
            "  compact DB [DST]   compact DB in-place (or to DST)\n"
            "  extract-schema DB  print DB's schema on stdout\n"
            "  query DB TRNS      execute read-only transaction on DB\n"
-           "  transact DB TRNS   execute read/write transaction on DB\n",
+           "  transact DB TRNS   execute read/write transaction on DB\n"
+           "  show-log DB        prints information about DB's log entries\n",
            program_name, program_name);
     vlog_usage();
     printf("\nOther options:\n"
@@ -190,6 +191,45 @@ do_transact(int argc UNUSED, char *argv[])
     transact(false, argv[1], argv[2]);
 }
 
+static void
+do_show_log(int argc UNUSED, char *argv[])
+{
+    const char *db_file_name = argv[1];
+    struct ovsdb_log *log;
+    unsigned int i;
+
+    check_ovsdb_error(ovsdb_log_open(db_file_name, O_RDONLY, &log));
+    for (i = 0; ; i++) {
+        struct json *json;
+
+        check_ovsdb_error(ovsdb_log_read(log, &json));
+        if (!json) {
+            break;
+        }
+
+        printf("record %u:", i);
+        if (json->type == JSON_OBJECT) {
+            struct json *date, *comment;
+
+            date = shash_find_data(json_object(json), "_date");
+            if (date && date->type == JSON_INTEGER) {
+                time_t t = json_integer(date);
+                char s[128];
+
+                strftime(s, sizeof s, "%Y-%m-%d %H:%M:%S", localtime(&t));
+                printf(" %s", s);
+            }
+
+            comment = shash_find_data(json_object(json), "_comment");
+            if (comment && comment->type == JSON_STRING) {
+                printf(" \"%s\"", json_string(comment));
+            }
+        }
+        json_destroy(json);
+        putchar('\n');
+    }
+}
+
 static void
 do_help(int argc UNUSED, char *argv[] UNUSED)
 {
@@ -200,6 +240,7 @@ static const struct command all_commands[] = {
     { "create", 2, 2, do_create },
     { "query", 2, 2, do_query },
     { "transact", 2, 2, do_transact },
+    { "show-log", 1, 1, do_show_log },
     { "help", 0, INT_MAX, do_help },
     { NULL, 0, 0, NULL },
 };