aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-21 16:45:18 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-01-21 16:45:18 +0000
commit7895577bd6c4d4bf98fa2933cbee42ea5c6a95a2 (patch)
treeffc8c2aa5a4bd99024c10d383354807e33e3f249
parentab479b021bd9a6c5a452bef9ea036a5a98fe45ab (diff)
downloadrspamd-7895577bd6c4d4bf98fa2933cbee42ea5c6a95a2.tar.gz
rspamd-7895577bd6c4d4bf98fa2933cbee42ea5c6a95a2.zip
Add dedicated function to checkpoint sqlite
-rw-r--r--src/libutil/sqlite_utils.c34
-rw-r--r--src/libutil/sqlite_utils.h7
2 files changed, 41 insertions, 0 deletions
diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c
index 76a708593..0d0d565c3 100644
--- a/src/libutil/sqlite_utils.c
+++ b/src/libutil/sqlite_utils.c
@@ -431,3 +431,37 @@ rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
return sqlite;
}
+
+gboolean
+rspamd_sqlite3_sync (sqlite3 *db, gint *wal_frames, gint *wal_checkpoints)
+{
+ gint wf = 0, wc = 0, mode;
+
+#ifdef SQLITE_OPEN_WAL
+#ifdef SQLITE_CHECKPOINT_TRUNCATE
+ mode = SQLITE_CHECKPOINT_TRUNCATE;
+#elif defined(SQLITE_CHECKPOINT_RESTART)
+ mode = SQLITE_CHECKPOINT_RESTART;
+#elif defined(SQLITE_CHECKPOINT_FULL)
+ mode = SQLITE_CHECKPOINT_FULL;
+#endif
+ /* Perform wal checkpoint (might be long) */
+ if (sqlite3_wal_checkpoint_v2 (db,
+ NULL,
+ mode,
+ &wf,
+ &wc) != SQLITE_OK) {
+ return FALSE;
+
+ }
+#endif
+
+ if (wal_frames) {
+ *wal_frames = wf;
+ }
+ if (wal_checkpoints) {
+ *wal_checkpoints = wc;
+ }
+
+ return TRUE;
+}
diff --git a/src/libutil/sqlite_utils.h b/src/libutil/sqlite_utils.h
index fba1b0091..84b3180b9 100644
--- a/src/libutil/sqlite_utils.h
+++ b/src/libutil/sqlite_utils.h
@@ -81,4 +81,11 @@ void rspamd_sqlite3_close_prstmt (sqlite3 *db, GArray *stmts);
sqlite3 * rspamd_sqlite3_open_or_create (rspamd_mempool_t *pool, const gchar *path, const
gchar *create_sql, GError **err);
+
+/**
+ * Sync sqlite3 db ensuring that all wal things are done
+ * @param db
+ */
+gboolean rspamd_sqlite3_sync (sqlite3 *db, gint *wal_frames, gint *wal_checkpoints);
+
#endif /* SRC_LIBUTIL_SQLITE_UTILS_H_ */