[tracker/wip/carlosg/domain-ontologies: 19/30] libtracker-data: Pass TrackerDBInterface to wal hook



commit 2338fa4c2e807fa5e92b0b838559196d3d68cca2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Jun 3 00:30:12 2017 +0200

    libtracker-data: Pass TrackerDBInterface to wal hook
    
    So there's at least some context to pull the DBManager from, Otherwise
    we're down to DBManager singleton lookups, which might not hold true
    forever.

 src/libtracker-data/libtracker-data.vapi          |    3 +-
 src/libtracker-data/tracker-db-interface-sqlite.c |   30 +++++++++++++++++++-
 src/libtracker-data/tracker-db-interface-sqlite.h |    7 ++++-
 src/tracker-store/tracker-store.vala              |    2 +-
 4 files changed, 37 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 9d9c06e..b6337ab 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -58,7 +58,7 @@ namespace Tracker {
        }
 
        [CCode (has_target = false, cheader_filename = "libtracker-data/tracker-db-interface-sqlite.h")]
-       public delegate void DBWalCallback (int n_pages);
+       public delegate void DBWalCallback (DBInterface iface, int n_pages);
 
        [CCode (cheader_filename = "libtracker-data/tracker-db-interface.h")]
        public interface DBInterface : GLib.Object {
@@ -68,6 +68,7 @@ namespace Tracker {
                public void execute_query (...) throws DBInterfaceError;
                [CCode (cheader_filename = "libtracker-data/tracker-db-interface-sqlite.h")]
                public void sqlite_wal_hook (DBWalCallback callback);
+               public void sqlite_wal_checkpoint (bool blocking) throws DBInterfaceError;
        }
 
        [CCode (cheader_filename = "libtracker-data/tracker-data-update.h")]
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c 
b/src/libtracker-data/tracker-db-interface-sqlite.c
index 66e6487..1af9d51 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -98,6 +98,9 @@ struct TrackerDBInterface {
        /* Used if TRACKER_DB_MANAGER_ENABLE_MUTEXES is set */
        GMutex mutex;
        guint use_mutex;
+
+       /* Wal */
+       TrackerDBWalCallback wal_hook;
 };
 
 struct TrackerDBInterfaceClass {
@@ -1854,8 +1857,9 @@ wal_hook (gpointer     user_data,
           const gchar *db_name,
           gint         n_pages)
 {
-       ((TrackerDBWalCallback) user_data) (n_pages);
+       TrackerDBInterface *iface = user_data;
 
+       iface->wal_hook (iface, n_pages);
        return SQLITE_OK;
 }
 
@@ -1863,9 +1867,31 @@ void
 tracker_db_interface_sqlite_wal_hook (TrackerDBInterface   *interface,
                                       TrackerDBWalCallback  callback)
 {
-       sqlite3_wal_hook (interface->db, wal_hook, callback);
+       interface->wal_hook = callback;
+       sqlite3_wal_hook (interface->db, wal_hook, interface);
 }
 
+gboolean
+tracker_db_interface_sqlite_wal_checkpoint (TrackerDBInterface  *interface,
+                                            gboolean             blocking,
+                                            GError             **error)
+{
+       int return_val;
+
+       return_val = sqlite3_wal_checkpoint_v2 (interface->db, NULL,
+                                               blocking ? SQLITE_CHECKPOINT_FULL : SQLITE_CHECKPOINT_PASSIVE,
+                                               NULL, NULL);
+
+       if (return_val != SQLITE_OK) {
+               g_set_error (error,
+                            TRACKER_DB_INTERFACE_ERROR,
+                            TRACKER_DB_QUERY_ERROR,
+                            sqlite3_errstr (return_val));
+               return FALSE;
+       }
+
+       return TRUE;
+}
 
 static void
 tracker_db_interface_sqlite_finalize (GObject *object)
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h 
b/src/libtracker-data/tracker-db-interface-sqlite.h
index a612296..8f638c9 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -32,7 +32,8 @@ G_BEGIN_DECLS
 
 #define TRACKER_COLLATION_NAME "TRACKER"
 
-typedef void (*TrackerDBWalCallback) (gint n_pages);
+typedef void (*TrackerDBWalCallback) (TrackerDBInterface *iface,
+                                      gint                n_pages);
 
 TrackerDBInterface *tracker_db_interface_sqlite_new                    (const gchar              *filename,
                                                                         gboolean                  readonly,
@@ -46,6 +47,10 @@ void                tracker_db_interface_sqlite_fts_init               (TrackerD
 void                tracker_db_interface_sqlite_reset_collator         (TrackerDBInterface       *interface);
 void                tracker_db_interface_sqlite_wal_hook               (TrackerDBInterface       *interface,
                                                                         TrackerDBWalCallback      callback);
+gboolean            tracker_db_interface_sqlite_wal_checkpoint         (TrackerDBInterface       *interface,
+                                                                        gboolean                  blocking,
+                                                                        GError                  **error);
+
 
 #if HAVE_TRACKER_FTS
 void                tracker_db_interface_sqlite_fts_alter_table        (TrackerDBInterface       *interface,
diff --git a/src/tracker-store/tracker-store.vala b/src/tracker-store/tracker-store.vala
index ef0598c..1e9f028 100644
--- a/src/tracker-store/tracker-store.vala
+++ b/src/tracker-store/tracker-store.vala
@@ -260,7 +260,7 @@ public class Tracker.Store {
 
        static int checkpointing;
 
-       static void wal_hook (int n_pages) {
+       static void wal_hook (DBInterface iface, int n_pages) {
                // run in update thread
 
                debug ("WAL: %d pages", n_pages);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]