]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephsqlite: add julian day offset in milliseconds 40317/head
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 24 Mar 2021 00:34:45 +0000 (17:34 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 24 Mar 2021 14:36:08 +0000 (07:36 -0700)
This magic number was copied from another VFS but was not adjusted for
the xCurrentTimeInt64 interface.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
(cherry picked from commit 9107e1a34743167d8f0cf969a440f5aaed2848af)

src/libcephsqlite.cc
src/test/libcephsqlite/main.cc

index aa2e42166b729a0518999427c991368148868a30..3db64a19f65241074d79c6ce167aa05307f69c2b 100644 (file)
@@ -690,7 +690,7 @@ static int CurrentTime(sqlite3_vfs* vfs, sqlite3_int64* time)
   dv(5) << time << dendl;
 
   auto t = ceph_clock_now();
-  *time = t.to_msec() + 2440587.5;
+  *time = t.to_msec() + 2440587.5*86400000; /* julian days since 1970 converted to ms */
 
   auto end = ceph::coarse_mono_clock::now();
   getdata(vfs).logger->tinc(P_OP_CURRENTTIME, end-start);
index a7a64556ea74ed7ae462291b7147c02cce59e629..78ab04888257f6d7e22bb4ab9fe53df26de7279b 100644 (file)
@@ -18,6 +18,7 @@
 #include <string>
 #include <string_view>
 
+#include <stdlib.h>
 #include <string.h>
 
 #include <sqlite3.h>
@@ -1030,6 +1031,32 @@ out:
   ASSERT_EQ(0, rc);
 }
 
+TEST_F(CephSQLiteTest, CurrentTime) {
+  static const char SQL[] =
+    "SELECT strftime('%s', 'now');"
+    ;
+
+  int rc;
+  const char *current = SQL;
+  sqlite3_stmt *stmt = NULL;
+
+  std::cout << SQL << std::endl;
+  sqlcatch(sqlite3_prepare_v2(db, current, -1, &stmt, &current));
+  sqlcatchcode(sqlite3_step(stmt), SQLITE_ROW);
+  {
+    time_t now = time(0);
+    auto t = sqlite3_column_int64(stmt, 0);
+    ASSERT_LT(abs(now-t), 5);
+  }
+  sqlcatch(sqlite3_finalize(stmt); stmt = NULL);
+
+  rc = 0;
+out:
+  sqlite3_finalize(stmt);
+  ASSERT_EQ(0, rc);
+}
+
+
 TEST_F(CephSQLiteTest, StatusFields) {
   static const char SQL[] =
     "SELECT json_extract(ceph_status(), '$.addr');"