[tracker/error-handling: 2/6] libtracker-data: Handle errors on transaction-commit



commit 688db129735849f8fb6266401fe04613d9f36e98
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Feb 9 12:05:15 2011 +0100

    libtracker-data: Handle errors on transaction-commit
    
    Out of space errors usually happen at the transaction's commit,
    so we must gracefully handle them.

 src/libtracker-data/tracker-data-update.c  |   10 ++++++++--
 src/libtracker-data/tracker-db-interface.c |   16 +++++++++-------
 src/libtracker-data/tracker-db-interface.h |    3 ++-
 3 files changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 07ae18e..9d4b2d5 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2512,6 +2512,14 @@ tracker_data_commit_transaction (GError **error)
 		return;
 	}
 
+	tracker_db_interface_end_db_transaction (iface,
+	                                         &actual_error);
+
+	if (actual_error) {
+		g_propagate_error (error, actual_error);
+		return;
+	}
+
 	get_transaction_modseq ();
 	if (has_persistent && !in_ontology_transaction) {
 		transaction_modseq++;
@@ -2545,8 +2553,6 @@ tracker_data_commit_transaction (GError **error)
 	}
 #endif
 
-	tracker_db_interface_end_db_transaction (iface);
-
 	tracker_db_interface_execute_query (iface, NULL, "PRAGMA cache_size = %d", TRACKER_DB_CACHE_SIZE_DEFAULT);
 
 	g_hash_table_remove_all (update_buffer.resources);
diff --git a/src/libtracker-data/tracker-db-interface.c b/src/libtracker-data/tracker-db-interface.c
index 249e67c..6bdf23e 100644
--- a/src/libtracker-data/tracker-db-interface.c
+++ b/src/libtracker-data/tracker-db-interface.c
@@ -64,17 +64,19 @@ tracker_db_interface_start_transaction (TrackerDBInterface *interface)
 }
 
 gboolean
-tracker_db_interface_end_db_transaction (TrackerDBInterface *interface)
+tracker_db_interface_end_db_transaction (TrackerDBInterface  *interface,
+                                         GError             **error)
 {
-	GError *error = NULL;
+	GError *internal_error = NULL;
 
-	tracker_db_interface_execute_query (interface, &error, "COMMIT");
+	tracker_db_interface_execute_query (interface, &internal_error, "COMMIT");
 
-	if (error) {
-		g_warning ("%s", error->message);
-		g_error_free (error);
+	if (internal_error) {
+		g_message ("%s", internal_error->message);
+		g_propagate_error (error, internal_error);
 
-		tracker_db_interface_execute_query (interface, NULL, "ROLLBACK");
+		/* Now that we propagate the error, ROLLBACK happens later
+		 tracker_db_interface_execute_query (interface, NULL, "ROLLBACK"); */
 
 		return FALSE;
 	}
diff --git a/src/libtracker-data/tracker-db-interface.h b/src/libtracker-data/tracker-db-interface.h
index b081902..1dcdf95 100644
--- a/src/libtracker-data/tracker-db-interface.h
+++ b/src/libtracker-data/tracker-db-interface.h
@@ -106,7 +106,8 @@ void                    tracker_db_interface_execute_query           (TrackerDBI
                                                                        ...) G_GNUC_PRINTF (3, 4);
 
 gboolean                tracker_db_interface_start_transaction       (TrackerDBInterface         *interface);
-gboolean                tracker_db_interface_end_db_transaction      (TrackerDBInterface         *interface);
+gboolean                tracker_db_interface_end_db_transaction      (TrackerDBInterface         *interface,
+                                                                      GError                    **error);
 void                    tracker_db_statement_bind_double             (TrackerDBStatement         *stmt,
                                                                       int                         index,
                                                                       double                      value);



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