From 1dd0fd7d6781fada61416b74208f085ab55af6f5 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Tue, 23 Mar 2021 17:34:45 -0700 Subject: [PATCH] cephsqlite: add julian day offset in milliseconds This magic number was copied from another VFS but was not adjusted for the xCurrentTimeInt64 interface. Signed-off-by: Patrick Donnelly (cherry picked from commit 9107e1a34743167d8f0cf969a440f5aaed2848af) --- src/libcephsqlite.cc | 2 +- src/test/libcephsqlite/main.cc | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libcephsqlite.cc b/src/libcephsqlite.cc index aa2e42166b7..3db64a19f65 100644 --- a/src/libcephsqlite.cc +++ b/src/libcephsqlite.cc @@ -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); diff --git a/src/test/libcephsqlite/main.cc b/src/test/libcephsqlite/main.cc index a7a64556ea7..78ab0488825 100644 --- a/src/test/libcephsqlite/main.cc +++ b/src/test/libcephsqlite/main.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -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, ¤t)); + 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');" -- 2.47.3