[tracker/journal: 19/21] libtracker-data: Fix journal replay with insert/delete mix



commit 0ee454af6d21bfc6bf2e10c6ceffa2b81c9681d0
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 819e045..f5065b3 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2435,6 +2435,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");
@@ -2487,22 +2488,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 {
@@ -2510,9 +2519,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));
@@ -2548,8 +2567,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);
@@ -2582,9 +2611,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]