]> source.dussan.org Git - rspamd.git/commitdiff
Add dedicated function to checkpoint sqlite
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Jan 2016 16:45:18 +0000 (16:45 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Jan 2016 16:45:18 +0000 (16:45 +0000)
src/libutil/sqlite_utils.c
src/libutil/sqlite_utils.h

index 76a7085939f6c7aee24e1ca00161b025f4cf72a1..0d0d565c375b68c2b3f6cb1eec7ca4fd572d3df6 100644 (file)
@@ -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;
+}
index fba1b0091be8a6670d5c7d47eb2be7b0d9568a6a..84b3180b967d3f20912296b3b526aa0d4870e26c 100644 (file)
@@ -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_ */