[tracker/binary-log-2: 3/56] Added stub API for new journal



commit 176efdf45f12afe3ca36427646136486f7be6c6d
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Dec 29 13:47:10 2009 +0100

    Added stub API for new journal

 src/libtracker-db/tracker-db-journal.c |  119 +++++++++++++++-----------------
 src/libtracker-db/tracker-db-journal.h |   42 +++++++-----
 src/tracker-store/tracker-backup.c     |    4 -
 src/tracker-store/tracker-main.c       |    5 +-
 src/tracker-store/tracker-resources.c  |    4 -
 src/tracker-store/tracker-store.c      |   78 +--------------------
 src/tracker-store/tracker-store.h      |    4 +-
 7 files changed, 87 insertions(+), 169 deletions(-)
---
diff --git a/src/libtracker-db/tracker-db-journal.c b/src/libtracker-db/tracker-db-journal.c
index bec8d8c..86100b6 100644
--- a/src/libtracker-db/tracker-db-journal.c
+++ b/src/libtracker-db/tracker-db-journal.c
@@ -33,7 +33,6 @@
 
 static gchar *filename = NULL;
 static FILE *journal = NULL;
-static GMappedFile *mapped = NULL;
 static gsize current_size = 0;
 
 #define TRACKER_DB_JOURNAL_LOG_FILENAME                 "log.sparql.txt"
@@ -77,93 +76,85 @@ tracker_db_journal_open (void)
 	}
 }
 
+
+//void
+//tracker_db_journal_log (const gchar *query)
+//{
+//	if (journal) {
+//		size_t len = strlen (query);
+//		write (fileno (journal), query, len);
+//		write (fileno (journal), "\n\0", 2);
+//		current_size += (len + 2);
+//	}
+//}
+
 void
-tracker_db_journal_log (const gchar *query)
+tracker_db_journal_start_transaction (void)
 {
-	if (journal) {
-		size_t len = strlen (query);
-		write (fileno (journal), query, len);
-		write (fileno (journal), "\n\0", 2);
-		current_size += (len + 2);
-	}
 }
 
-void 
-tracker_db_journal_fsync (void)
+void
+tracker_db_journal_append_delete_statement (guint32      s_code,
+                                            guint32      p_code,
+                                            const gchar *object)
 {
-	if (journal) {
-		fsync (fileno (journal));
-	}
 }
 
+
 void
-tracker_db_journal_truncate (void)
+tracker_db_journal_append_delete_statement_code (guint32 s_code,
+                                                 guint32 p_code,
+                                                 guint32 o_code)
 {
-	if (journal) {
-		ftruncate(fileno (journal), 0);
-		current_size = 0;
-		fsync (fileno (journal));
-	}
 }
 
 void
-tracker_db_journal_close (void)
+tracker_db_journal_append_insert_statement (guint32      s_code, 
+                                            guint32      p_code, 
+                                            const gchar *object)
 {
-	if (journal) {
-		fclose (journal);
-		journal = NULL;
-	}
-
-	g_free (filename);
-	filename = NULL;
 }
 
-TrackerJournalContents*
-tracker_db_journal_get_contents (guint transaction_size)
+void
+tracker_db_journal_append_insert_statement_code (guint32 s_code,
+                                                 guint32 p_code,
+                                                 guint32 o_code)
 {
-	GPtrArray *lines;
-	gsize max_pos, next_len;
-	gchar *cur;
-
-	get_filename ();
-
-	if (!mapped) {
-		GError *error = NULL;
-
-		mapped = g_mapped_file_new (filename, FALSE, &error);
+}
 
-		if (error) {
-			g_clear_error (&error);
-			mapped = NULL;
-			return NULL;
-		}
-	}
+void
+tracker_db_journal_append_resource (guint32      s_code,
+                                   const gchar *uri)
+{
+}
 
-	lines = g_ptr_array_sized_new (transaction_size > 0 ? transaction_size : 2000);
+void
+tracker_db_journal_rollback_transaction (void)
+{
+}
 
-	cur = g_mapped_file_get_contents (mapped);
-	max_pos = (gsize) (cur + g_mapped_file_get_length (mapped));
+void
+tracker_db_journal_commit_transaction (void)
+{
+}
 
-	while (((gsize)cur) < max_pos) {
-		next_len = strnlen (cur, max_pos - ((gsize)cur)) + 1;
-		g_ptr_array_add (lines, cur);
-		cur += next_len;
+void 
+tracker_db_journal_fsync (void)
+{
+	if (journal) {
+		fsync (fileno (journal));
 	}
-
-	return (TrackerJournalContents *) lines;
 }
 
-void 
-tracker_db_journal_free_contents (TrackerJournalContents *contents)
+
+void
+tracker_db_journal_close (void)
 {
-	if (mapped) {
-#if GLIB_CHECK_VERSION(2,22,0)
-		g_mapped_file_unref (mapped);
-#else
-		g_mapped_file_free (mapped);
-#endif
-		mapped = NULL;
+	if (journal) {
+		fclose (journal);
+		journal = NULL;
 	}
 
-	g_ptr_array_free ((GPtrArray *)contents, TRUE);
+	g_free (filename);
+	filename = NULL;
 }
diff --git a/src/libtracker-db/tracker-db-journal.h b/src/libtracker-db/tracker-db-journal.h
index 0400321..0356fb4 100644
--- a/src/libtracker-db/tracker-db-journal.h
+++ b/src/libtracker-db/tracker-db-journal.h
@@ -27,23 +27,31 @@
 
 G_BEGIN_DECLS
 
-#if !defined (__LIBTRACKER_DB_INSIDE__) && !defined (TRACKER_COMPILATION)
-#error "only <libtracker-db/tracker-db.h> must be included directly."
-#endif
-
-#define TRACKER_DB_JOURNAL_MAX_SIZE 52428800
-
-typedef GPtrArray TrackerJournalContents;
-
-const gchar*            tracker_db_journal_filename      (void);
-void                    tracker_db_journal_open          (void);
-void                    tracker_db_journal_log           (const gchar            *query);
-void                    tracker_db_journal_truncate      (void);
-void                    tracker_db_journal_close         (void);
-TrackerJournalContents* tracker_db_journal_get_contents  (guint                   transaction_size);
-void                    tracker_db_journal_free_contents (TrackerJournalContents *contents);
-void                    tracker_db_journal_fsync         (void);
-gsize                   tracker_db_journal_get_size      (void);
+const gchar* tracker_db_journal_filename                     (void);
+void         tracker_db_journal_open                         (void);
+
+void         tracker_db_journal_start_transaction            (void);
+void         tracker_db_journal_append_delete_statement      (guint32      s_code,
+                                                              guint32      p_code,
+                                                              const gchar *object);
+void         tracker_db_journal_append_delete_statement_code (guint32      s_code,
+                                                              guint32      p_code,
+                                                              guint32      o_code);
+void         tracker_db_journal_append_insert_statement      (guint32      s_code, 
+                                                              guint32      p_code, 
+                                                              const gchar *object);
+void         tracker_db_journal_append_insert_statement_code (guint32      s_code,
+                                                              guint32      p_code,
+                                                              guint32      o_code);
+void         tracker_db_journal_append_resource              (guint32      s_code,
+                                                              const gchar *uri);
+
+void         tracker_db_journal_rollback_transaction         (void);
+void         tracker_db_journal_commit_transaction           (void);
+
+void         tracker_db_journal_close                        (void);
+void         tracker_db_journal_fsync                        (void);
+gsize        tracker_db_journal_get_size                     (void);
 
 G_END_DECLS
 
diff --git a/src/tracker-store/tracker-backup.c b/src/tracker-store/tracker-backup.c
index b9d7f45..b677e3f 100644
--- a/src/tracker-store/tracker-backup.c
+++ b/src/tracker-store/tracker-backup.c
@@ -85,10 +85,6 @@ backup_callback (GError *error, gpointer user_data)
 		return;
 	}
 
-	if (info->play_journal) {
-		tracker_store_play_journal ();
-	}
-
 	dbus_g_method_return (info->context);
 
 	tracker_dbus_request_success (info->request_id);
diff --git a/src/tracker-store/tracker-main.c b/src/tracker-store/tracker-main.c
index 5271c4e..6af9255 100644
--- a/src/tracker-store/tracker-main.c
+++ b/src/tracker-store/tracker-main.c
@@ -435,7 +435,10 @@ main (gint argc, gchar *argv[])
 		return EXIT_FAILURE;
 	}
 
-	tracker_store_init (need_journal);
+	/* TODO binary-log: need_journal might contain whether the db was corrupt
+	 * or not Do something with that.*/
+
+	tracker_store_init ();
 
 	if (private->shutdown) {
 		goto shutdown;
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 4a61559..4cd564c 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -418,10 +418,6 @@ on_statements_committed (gpointer user_data)
 
 	priv = TRACKER_RESOURCES_GET_PRIVATE (resources);
 
-	/* For more information about this call, look at the function end_batch
-	 * of tracker-store.c */
-	tracker_store_flush_journal ();
-
 	/* Class signals feature */
 	events = tracker_events_get_pending ();
 
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index 6d47de0..2af72d0 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -26,9 +26,7 @@
 
 #include <libtracker-common/tracker-dbus.h>
 #include <libtracker-db/tracker-db-dbus.h>
-#include <libtracker-db/tracker-db-journal.h>
 #include <libtracker-db/tracker-db-interface-sqlite.h>
-#include <libtracker-db/tracker-db-journal.h>
 
 #include <libtracker-data/tracker-data-update.h>
 #include <libtracker-data/tracker-data-query.h>
@@ -36,7 +34,7 @@
 
 #include "tracker-store.h"
 
-#define TRACKER_STORE_TRANSACTION_MAX                   4000            /* At commit is journal fsynced too */
+#define TRACKER_STORE_TRANSACTION_MAX                   4000
 
 typedef struct {
 	gboolean  have_handler, have_sync_handler;
@@ -157,21 +155,11 @@ end_batch (TrackerStorePrivate *private)
 		/* commit pending batch items */
 		tracker_data_commit_transaction ();
 
-		/* The on_statements_committed in tracker-resources.c performs
-		 * the flush on the journal, I can only register one callback
-		 * for this atm, so that's why it's called over there as a
-		 * tracker_store_flush_journal */
-
 		private->batch_mode = FALSE;
 		private->batch_count = 0;
 	}
 }
 
-static void
-log_to_journal (TrackerStorePrivate *private, const gchar *query)
-{
-	tracker_db_journal_log (query);
-}
 
 static gboolean
 queue_idle_handler (gpointer user_data)
@@ -189,10 +177,6 @@ queue_idle_handler (gpointer user_data)
 
 		tracker_data_update_sparql (task->data.update.query, &error);
 
-		if (private->start_log) {
-			log_to_journal (private, task->data.update.query);
-		}
-
 		if (!error) {
 			private->batch_count++;
 			if (private->batch_count >= TRACKER_STORE_TRANSACTION_MAX) {
@@ -282,54 +266,9 @@ queue_idle_destroy (gpointer user_data)
 	private->have_handler = FALSE;
 }
 
-void
-tracker_store_flush_journal (void)
-{
-	TrackerStorePrivate *private;
-
-	private = g_static_private_get (&private_key);
-	g_return_if_fail (private != NULL);
-
-	tracker_db_journal_fsync ();
-}
-
-static void
-internal_play_journal (TrackerStorePrivate *private)
-{
-	TrackerJournalContents *lines;
-
-	lines = tracker_db_journal_get_contents (TRACKER_STORE_TRANSACTION_MAX);
-
-	if (lines) {
-		guint i;
-
-		tracker_data_begin_transaction ();
-		private->start_log = FALSE;
-		for (i = 0; i < lines->len; i++) {
-			const gchar *line = g_ptr_array_index (lines, i);
-			tracker_store_sparql_update (line, NULL);
-		}
-		tracker_db_journal_truncate ();
-		private->start_log = TRUE;
-		tracker_data_commit_transaction ();
-
-		tracker_db_journal_free_contents (lines);
-	}
-}
-
-void
-tracker_store_play_journal (void)
-{
-	TrackerStorePrivate *private;
-
-	private = g_static_private_get (&private_key);
-	g_return_if_fail (private != NULL);
-
-	internal_play_journal (private);
-}
 
 void
-tracker_store_init (gboolean load_journal)
+tracker_store_init (void)
 {
 	TrackerStorePrivate *private;
 
@@ -341,11 +280,6 @@ tracker_store_init (gboolean load_journal)
 	                      private,
 	                      private_free);
 
-	if (load_journal) {
-		internal_play_journal (private);
-	}
-
-	tracker_db_journal_open ();
 }
 
 void
@@ -488,10 +422,6 @@ tracker_store_sparql_update (const gchar *sparql,
 	tracker_data_update_sparql (sparql, error);
 	tracker_data_commit_transaction ();
 
-	if (private->start_log) {
-		log_to_journal (private, sparql);
-	}
-
 }
 
 GPtrArray *
@@ -517,10 +447,6 @@ tracker_store_sparql_update_blank (const gchar *sparql,
 	blank_nodes = tracker_data_update_sparql_blank (sparql, error);
 	tracker_data_commit_transaction ();
 
-	if (private->start_log) {
-		log_to_journal (private, sparql);
-	}
-
 	return blank_nodes;
 }
 
diff --git a/src/tracker-store/tracker-store.h b/src/tracker-store/tracker-store.h
index 1ad95f2..e2eb10c 100644
--- a/src/tracker-store/tracker-store.h
+++ b/src/tracker-store/tracker-store.h
@@ -35,7 +35,7 @@ typedef void (* TrackerStoreCommitCallback)       (gpointer         user_data);
 typedef void (* TrackerStoreTurtleCallback)       (GError          *error,
                                                    gpointer         user_data);
 
-void         tracker_store_init                   (gboolean load_journal);
+void         tracker_store_init                   (void);
 void         tracker_store_shutdown               (void);
 void         tracker_store_queue_commit           (TrackerStoreCommitCallback callback,
                                                    const gchar   *client_id,
@@ -60,8 +60,6 @@ tracker_store_sparql_query           (const gchar   *sparql,
 
 guint        tracker_store_get_queue_size         (void);
 
-void         tracker_store_play_journal           (void);
-void         tracker_store_flush_journal          (void);
 void         tracker_store_unreg_batches          (const gchar   *client_id);
 
 G_END_DECLS



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