[tracker/journal: 18/22] libtracker-data: Fix journal replay with insert/delete mix



commit a2f46539935aa30957672e70cb0e2bf26e4009ca
Author: Jürg Billeter <j bitron ch>
Date:   Tue Mar 16 12:34:27 2010 +0100

    libtracker-data: Fix journal replay with insert/delete mix

 src/libtracker-data/tracker-data-update.c |   45 +++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 27cfae7..1ad1a12 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2404,6 +2404,7 @@ tracker_data_replay_journal (GHashTable *classes,
 {
 	GError *journal_error = NULL;
 	static TrackerProperty *rdf_type = NULL;
+	gint last_operation_type = 0;
 
 	if (!rdf_type) {
 		rdf_type = tracker_ontologies_get_property_by_uri (RDF_PREFIX "type");
@@ -2456,22 +2457,30 @@ tracker_data_replay_journal (GHashTable *classes,
 		} else if (type == TRACKER_DB_JOURNAL_END_TRANSACTION) {
 			tracker_data_commit_transaction ();
 		} else if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT) {
+			GError *new_error = NULL;
 			TrackerProperty *property;
 
+			if (last_operation_type == -1) {
+				tracker_data_update_buffer_flush (&new_error);
+				if (new_error) {
+					g_warning ("Journal replay error: '%s'", new_error->message);
+					g_clear_error (&new_error);
+				}
+			}
+			last_operation_type = 1;
+
 			tracker_db_journal_reader_get_statement (&graph_id, &subject_id, &predicate_id, &object);
 
 			property = g_hash_table_lookup (properties, GINT_TO_POINTER (predicate_id));
 
 			if (property) {
-				GError *new_error = NULL;
-
 				resource_buffer_switch (NULL, graph_id, NULL, subject_id);
 
 				cache_set_metadata_decomposed (property, object, 0, NULL, graph_id, &new_error);
 
 				if (new_error) {
 					g_warning ("Journal replay error: '%s'", new_error->message);
-					g_error_free (new_error);
+					g_clear_error (&new_error);
 				}
 
 			} else {
@@ -2479,9 +2488,19 @@ tracker_data_replay_journal (GHashTable *classes,
 			}
 
 		} else if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT_ID) {
+			GError *new_error = NULL;
 			TrackerClass *class = NULL;
 			TrackerProperty *property;
 
+			if (last_operation_type == -1) {
+				tracker_data_update_buffer_flush (&new_error);
+				if (new_error) {
+					g_warning ("Journal replay error: '%s'", new_error->message);
+					g_clear_error (&new_error);
+				}
+			}
+			last_operation_type = 1;
+
 			tracker_db_journal_reader_get_statement_id (&graph_id, &subject_id, &predicate_id, &object_id);
 
 			property = g_hash_table_lookup (properties, GINT_TO_POINTER (predicate_id));
@@ -2517,8 +2536,18 @@ tracker_data_replay_journal (GHashTable *classes,
 			}
 
 		} else if (type == TRACKER_DB_JOURNAL_DELETE_STATEMENT) {
+			GError *new_error = NULL;
 			TrackerProperty *property;
 
+			if (last_operation_type == 1) {
+				tracker_data_update_buffer_flush (&new_error);
+				if (new_error) {
+					g_warning ("Journal replay error: '%s'", new_error->message);
+					g_clear_error (&new_error);
+				}
+			}
+			last_operation_type = -1;
+
 			tracker_db_journal_reader_get_statement (&graph_id, &subject_id, &predicate_id, &object);
 
 			resource_buffer_switch (NULL, graph_id, NULL, subject_id);
@@ -2551,9 +2580,19 @@ tracker_data_replay_journal (GHashTable *classes,
 			}
 
 		} else if (type == TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID) {
+			GError *new_error = NULL;
 			TrackerClass *class = NULL;
 			TrackerProperty *property;
 
+			if (last_operation_type == 1) {
+				tracker_data_update_buffer_flush (&new_error);
+				if (new_error) {
+					g_warning ("Journal replay error: '%s'", new_error->message);
+					g_clear_error (&new_error);
+				}
+			}
+			last_operation_type = -1;
+
 			tracker_db_journal_reader_get_statement_id (&graph_id, &subject_id, &predicate_id, &object_id);
 
 			property = g_hash_table_lookup (properties, GINT_TO_POINTER (predicate_id));



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