[tracker] libtracker-data: Do not begin ontology transaction when not needed



commit 331363a1db08d434e6dacd84bae1f33144c518e4
Author: JÃrg Billeter <j bitron ch>
Date:   Wed Jun 15 17:28:26 2011 +0200

    libtracker-data: Do not begin ontology transaction when not needed
    
    This allows tracker-store startup with full partition. Updates will fail
    as long as partition is full.
    
    Fixes NB#263203.

 src/libtracker-data/tracker-data-manager.c |   43 +++++++++++++++++++++------
 1 files changed, 33 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index ff9da8a..3bdcd89 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3760,6 +3760,7 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 		GPtrArray *seen_classes;
 		GPtrArray *seen_properties;
 		GError *n_error = NULL;
+		gboolean transaction_started = FALSE;
 
 		seen_classes = g_ptr_array_new ();
 		seen_properties = g_ptr_array_new ();
@@ -3786,12 +3787,6 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 
 		/* check ontology against database */
 
-		tracker_data_begin_ontology_transaction (&internal_error);
-		if (internal_error) {
-			g_propagate_error (error, internal_error);
-			return FALSE;
-		}
-
 		/* Get a map of tracker:Ontology v. nao:lastModified so that we can test
 		 * for all the ontology files in ontologies_dir whether the last-modified
 		 * has changed since we dealt with the file last time. */
@@ -3868,6 +3863,16 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 				 * modified in the latest version of the file, deal with changes. */
 				if (val != last_mod) {
 					g_debug ("Ontology file '%s' needs update", ontology_path);
+
+					if (!transaction_started) {
+						tracker_data_begin_ontology_transaction (&internal_error);
+						if (internal_error) {
+							g_propagate_error (error, internal_error);
+							return FALSE;
+						}
+						transaction_started = TRUE;
+					}
+
 					if (max_id == 0) {
 						/* In case of first-time, this wont start at zero */
 						max_id = get_new_service_id (iface);
@@ -3890,6 +3895,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 						tracker_data_ontology_free_seen (seen_properties);
 						tracker_data_ontology_import_finished ();
 
+						/* as we're processing an ontology change,
+						   transaction is guaranteed to be started */
 						tracker_data_commit_transaction (&internal_error);
 						if (internal_error) {
 							g_propagate_error (error, internal_error);
@@ -3934,6 +3941,16 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 				GError *ontology_error = NULL;
 
 				g_debug ("Ontology file '%s' got added", ontology_path);
+
+				if (!transaction_started) {
+					tracker_data_begin_ontology_transaction (&internal_error);
+					if (internal_error) {
+						g_propagate_error (error, internal_error);
+						return FALSE;
+					}
+					transaction_started = TRUE;
+				}
+
 				if (max_id == 0) {
 					/* In case of first-time, this wont start at zero */
 					max_id = get_new_service_id (iface);
@@ -3956,6 +3973,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 					tracker_data_ontology_free_seen (seen_properties);
 					tracker_data_ontology_import_finished ();
 
+					/* as we're processing an ontology change,
+					   transaction is guaranteed to be started */
 					tracker_data_commit_transaction (&internal_error);
 					if (internal_error) {
 						g_propagate_error (error, internal_error);
@@ -4049,6 +4068,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 				tracker_data_ontology_free_seen (seen_properties);
 				tracker_data_ontology_import_finished ();
 
+				/* as we're processing an ontology change,
+				   transaction is guaranteed to be started */
 				tracker_data_commit_transaction (&internal_error);
 				if (internal_error) {
 					g_propagate_error (error, internal_error);
@@ -4105,10 +4126,12 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 		/* Reset the is_new flag for all classes and properties */
 		tracker_data_ontology_import_finished ();
 
-		tracker_data_commit_transaction (&internal_error);
-		if (internal_error) {
-			g_propagate_error (error, internal_error);
-			return FALSE;
+		if (transaction_started) {
+			tracker_data_commit_transaction (&internal_error);
+			if (internal_error) {
+				g_propagate_error (error, internal_error);
+				return FALSE;
+			}
 		}
 
 		g_hash_table_unref (ontos_table);



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