[tracker/binary-log-2: 28/44] libtracker-data: Do not append to journal while replaying



commit d8ac4b1dbc13b086bca505456d3ba9cafed86219
Author: Jürg Billeter <j bitron ch>
Date:   Wed Jan 6 14:31:11 2010 +0100

    libtracker-data: Do not append to journal while replaying

 src/libtracker-data/tracker-data-manager.c |   17 ++++++--
 src/libtracker-data/tracker-data-update.c  |   56 +++++++++++++++++++---------
 src/libtracker-data/tracker-data-update.h  |    1 +
 3 files changed, 51 insertions(+), 23 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 7aaad34..bdc0353 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -63,6 +63,7 @@
 
 static gchar              *ontologies_dir;
 static gboolean            initialized;
+static gboolean            in_journal_replay;
 
 static void
 load_ontology_statement (const gchar *ontology_file,
@@ -385,11 +386,10 @@ query_resource_by_id (guint32 id)
 static void
 replay_journal (void)
 {
-	GError *error = NULL;
-
 	tracker_db_journal_reader_init (NULL);
 
 	while (tracker_db_journal_reader_next (NULL)) {
+		GError *error = NULL;
 		TrackerDBJournalEntryType type;
 		const gchar *subject, *predicate, *object;
 		guint32 subject_id, predicate_id, object_id;
@@ -416,7 +416,7 @@ replay_journal (void)
 			tracker_db_statement_bind_int64 (stmt, 2, (gint64) time (NULL));
 			tracker_db_statement_execute (stmt, &error);
 		} else if (type == TRACKER_DB_JOURNAL_START_TRANSACTION) {
-			tracker_data_begin_transaction ();
+			tracker_data_begin_replay_transaction ();
 		} else if (type == TRACKER_DB_JOURNAL_END_TRANSACTION) {
 			tracker_data_commit_transaction ();
 		} else if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT) {
@@ -717,7 +717,10 @@ insert_uri_in_resource_table (TrackerDBInterface *iface,
 		g_clear_error (&error);
 	}
 
-	tracker_db_journal_append_resource (id, uri);
+	if (!in_journal_replay) {
+		tracker_db_journal_append_resource (id, uri);
+	}
+
 	tracker_ontology_add_id_uri_pair (id, uri);
 
 	if (class)
@@ -985,12 +988,14 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		gint max_id = 0;
 		guint i, n_props, n_classes;
 
+		in_journal_replay = TRUE;
+
 		/* load ontology from journal into memory */
 		/*id_uri_map =*/ load_ontology_from_journal ();
 
 		classes = tracker_ontology_get_classes (&n_classes);
 
-		tracker_data_begin_transaction ();
+		tracker_data_begin_replay_transaction ();
 
 		/* create tables */
 		for (i = 0; i < n_classes; i++) {
@@ -1013,6 +1018,8 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 
 		replay_journal ();
 
+		in_journal_replay = FALSE;
+
 		/* open journal for writing */
 		tracker_db_journal_init (NULL);
 	} else if (is_first_time_index) {
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 40120c7..919a5e8 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -116,6 +116,7 @@ struct _TrackerCommitDelegate {
 };
 
 static gboolean in_transaction = FALSE;
+static gboolean in_journal_replay = FALSE;
 static TrackerDataUpdateBuffer update_buffer;
 /* current resource */
 static TrackerDataUpdateBufferResource *resource_buffer;
@@ -395,7 +396,9 @@ ensure_resource_id (const gchar *uri)
 		tracker_db_statement_execute (stmt, NULL);
 		g_object_unref (stmt);
 
-		tracker_db_journal_append_resource (id, uri);
+		if (!in_journal_replay) {
+			tracker_db_journal_append_resource (id, uri);
+		}
 
 		g_hash_table_insert (update_buffer.resource_cache, g_strdup (uri), GUINT_TO_POINTER (id));
 	}
@@ -1280,9 +1283,11 @@ tracker_data_delete_statement (const gchar  *graph,
 	if (object && g_strcmp0 (predicate, RDF_PREFIX "type") == 0) {
 		class = tracker_ontology_get_class_by_uri (object);
 		if (class != NULL) {
-			tracker_db_journal_append_delete_statement_id (resource_buffer->id,
-				tracker_data_query_resource_id (predicate),
-				query_resource_id (object));
+			if (!in_journal_replay) {
+				tracker_db_journal_append_delete_statement_id (resource_buffer->id,
+					tracker_data_query_resource_id (predicate),
+					query_resource_id (object));
+			}
 
 			cache_delete_resource_type (class, graph);
 		} else {
@@ -1293,14 +1298,16 @@ tracker_data_delete_statement (const gchar  *graph,
 		field = tracker_ontology_get_property_by_uri (predicate);
 		if (field != NULL) {
 			guint32 id = tracker_property_get_id (field);
-			if (tracker_property_get_data_type (field) == TRACKER_PROPERTY_TYPE_RESOURCE) {
-				tracker_db_journal_append_delete_statement_id (resource_buffer->id,
-					(id != 0) ? id : tracker_data_query_resource_id (predicate),
-					query_resource_id (object));
-			} else {
-				tracker_db_journal_append_delete_statement (resource_buffer->id,
-					(id != 0) ? id : tracker_data_query_resource_id (predicate),
-					object);
+			if (!in_journal_replay) {
+				if (tracker_property_get_data_type (field) == TRACKER_PROPERTY_TYPE_RESOURCE) {
+					tracker_db_journal_append_delete_statement_id (resource_buffer->id,
+						(id != 0) ? id : tracker_data_query_resource_id (predicate),
+						query_resource_id (object));
+				} else {
+					tracker_db_journal_append_delete_statement (resource_buffer->id,
+						(id != 0) ? id : tracker_data_query_resource_id (predicate),
+						object);
+				}
 			}
 
 			delete_metadata_decomposed (field, object, error);
@@ -1510,9 +1517,11 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
 		return;
 	}
 
-	tracker_db_journal_append_insert_statement_id (resource_buffer->id,
-		(prop_id != 0) ? prop_id : tracker_data_query_resource_id (predicate),
-		query_resource_id (object));
+	if (!in_journal_replay) {
+		tracker_db_journal_append_insert_statement_id (resource_buffer->id,
+			(prop_id != 0) ? prop_id : tracker_data_query_resource_id (predicate),
+			query_resource_id (object));
+	}
 
 	if (strcmp (predicate, RDF_PREFIX "type") == 0) {
 		/* handle rdf:type statements specially to
@@ -1589,9 +1598,11 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
 		return;
 	}
 
-	tracker_db_journal_append_insert_statement (resource_buffer->id,
-		(id != 0) ? id : tracker_data_query_resource_id (predicate),
-		object);
+	if (!in_journal_replay) {
+		tracker_db_journal_append_insert_statement (resource_buffer->id,
+			(id != 0) ? id : tracker_data_query_resource_id (predicate),
+			object);
+	}
 
 	/* add value to metadata database */
 	cache_set_metadata_decomposed (property, object, &actual_error);
@@ -1849,6 +1860,13 @@ tracker_data_begin_transaction (void)
 }
 
 void
+tracker_data_begin_replay_transaction (void)
+{
+	in_journal_replay = TRUE;
+	tracker_data_begin_transaction ();
+}
+
+void
 tracker_data_commit_transaction (void)
 {
 	TrackerDBInterface *iface;
@@ -1879,6 +1897,8 @@ tracker_data_commit_transaction (void)
 			delegate->callback (delegate->user_data);
 		}
 	}
+
+	in_journal_replay = FALSE;
 }
 
 static void
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index 173d2fb..2d81341 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -77,6 +77,7 @@ void     tracker_data_insert_statement_with_string  (const gchar               *
                                                      const gchar               *object,
                                                      GError                   **error);
 void     tracker_data_begin_transaction             (void);
+void     tracker_data_begin_replay_transaction      (void);
 void     tracker_data_commit_transaction            (void);
 void     tracker_data_update_sparql                 (const gchar               *update,
                                                      GError                   **error);



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