On Sep 11, 2013, at 10:41 PM, Ben Pfaff <b...@nicira.com> wrote:
> 
> This patch also needs your sign-off.

OK, included with sign-off and a check which I mysteriously left out of the 
original patch.

Thanks.

:: psi

--8<--------------------------cut here-------------------------->8--

From: Paul Ingram <ping...@nicira.com>
Date: Thu, 12 Sep 2013 18:51:35 -0700
Subject: [PATCH] ovsdb: timestamp database records to millisecond resolution.

The ovsdb-server compaction timing logic is written assuming milliscond
resolution timestamps but ovsdb-server wrote second resolution timestamps.

This commit changes ovsdb-server to write millisecond resolution timestamps
and ovsdb-tool to report millisecond timestamps.

This raises two compatibility issues:
1. When a new ovsdb-server or ovsdb-tool reads an old database, it will
multiply by 1000 any timestamp it reads which is less than 1<<31. Since
this date corresponds to Jan 16 1970 this is unlikely to cause a problem.
2. When an old ovsdb-tool reads a new database, it will interpret the
millisecond timestamps as seconds and report dates in the far future; the
time of this commit is reported as the year 45645 (each second since the
epoch is interpreted as 16 minutes). (When an old ovsdb-server reads a
new database there is no problem, it is already interpreting the timestamps
in milliseconds).

Signed-off-by: Paul Ingram <ping...@nicira.com>
---
 ovsdb/file.c       |    6 +++++-
 ovsdb/ovsdb-tool.c |   10 +++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/ovsdb/file.c b/ovsdb/file.c
index b02d5a3..5b79f8c 100644
--- a/ovsdb/file.c
+++ b/ovsdb/file.c
@@ -408,6 +408,10 @@ ovsdb_file_txn_from_json(struct ovsdb *db, const struct 
json *json,
             if (!strcmp(table_name, "_date")
                 && node_json->type == JSON_INTEGER) {
                 *date = json_integer(node_json);
+                if (*date < INT_MAX) {
+                    /* Older versions of ovsdb wrote timestamps in seconds. */
+                    *date *= 1000;
+                }
                 continue;
             } else if (!strcmp(table_name, "_comment") || converting) {
                 continue;
@@ -787,7 +791,7 @@ ovsdb_file_txn_commit(struct json *json, const char 
*comment,
     if (comment) {
         json_object_put_string(json, "_comment", comment);
     }
-    json_object_put(json, "_date", json_integer_create(time_wall()));
+    json_object_put(json, "_date", json_integer_create(time_wall_msec()));
 
     error = ovsdb_log_write(log, json);
     json_destroy(json);
diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index 8670127..ade3d87 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -518,9 +518,13 @@ do_show_log(int argc, char *argv[])
 
             date = shash_find_data(json_object(json), "_date");
             if (date && date->type == JSON_INTEGER) {
-                time_t t = json_integer(date);
-                char *s = xastrftime_msec(" %Y-%m-%d %H:%M:%S",
-                                          t * 1000LL, true);
+                long long int t = json_integer(date);
+                if (t < INT_MAX) {
+                    /* Older versions of ovsdb wrote timestamps in seconds. */
+                    t *= 1000;
+                }
+
+                char *s = xastrftime_msec(" %Y-%m-%d %H:%M:%S.###", t, true);
                 fputs(s, stdout);
                 free(s);
             }
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to