[tracker/journal-err-reporting-merge: 3/5] libtracker-data, tests, tracker-control: Handle journal errors



commit e34fb33d0c124f12597000b6c74dfa5e55c5cf5e
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Apr 21 16:16:00 2011 +0200

    libtracker-data, tests, tracker-control: Handle journal errors

 src/libtracker-data/tracker-data-backup.c     |   22 +++++++-
 src/libtracker-data/tracker-data-manager.c    |   50 +++++++++++++++---
 src/libtracker-data/tracker-data-update.c     |   70 ++++++++++++++++++++----
 src/libtracker-data/tracker-db-manager.c      |    8 +++-
 src/tracker-control/tracker-control-general.c |    4 +-
 tests/libtracker-data/tracker-db-journal.c    |   35 +++++++++----
 6 files changed, 154 insertions(+), 35 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-backup.c b/src/libtracker-data/tracker-data-backup.c
index c46c350..8bf0844 100644
--- a/src/libtracker-data/tracker-data-backup.c
+++ b/src/libtracker-data/tracker-data-backup.c
@@ -337,6 +337,7 @@ tracker_data_backup_restore (GFile                *journal,
 		gchar **argv;
 		gint exit_status;
 		guint select_cache_size, update_cache_size;
+		GError *n_error = NULL;
 
 		flags = tracker_db_manager_get_flags (&select_cache_size, &update_cache_size);
 
@@ -378,7 +379,18 @@ tracker_data_backup_restore (GFile                *journal,
 		g_strfreev (argv);
 
 		tracker_db_manager_init_locations ();
-		tracker_db_journal_init (NULL, FALSE);
+		tracker_db_journal_init (NULL, FALSE, &n_error);
+
+		if (n_error) {
+			if (!info->error) {
+				g_propagate_error (&info->error, n_error);
+			} else {
+				g_warning ("Ignored error while initializing journal during backup (another higher priority error already took place): %s",
+				           n_error->message ? n_error->message : "No error given");
+				g_error_free (n_error);
+			}
+			n_error = NULL;
+		}
 
 		if (info->error) {
 			tracker_db_manager_restore_from_temp ();
@@ -386,7 +398,13 @@ tracker_data_backup_restore (GFile                *journal,
 			tracker_db_manager_remove_temp ();
 		}
 
-		tracker_db_journal_shutdown ();
+		tracker_db_journal_shutdown (&n_error);
+
+		if (n_error) {
+			g_warning ("Ignored error while shuting down journal during backup: %s",
+			           n_error->message ? n_error->message : "No error given");
+			g_error_free (n_error);
+		}
 
 		tracker_data_manager_init (flags, test_schemas, &is_first, TRUE,
 		                           select_cache_size, update_cache_size,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 108d841..2f83173 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3556,7 +3556,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 	iface = tracker_db_manager_get_db_interface ();
 
 	if (journal_check && is_first_time_index) {
-		if (tracker_db_journal_reader_init (NULL)) {
+		/* Call may fail without notice */
+		if (tracker_db_journal_reader_init (NULL, NULL)) {
 			if (tracker_db_journal_reader_next (NULL)) {
 				/* journal with at least one valid transaction
 				   is required to trigger journal replay */
@@ -3580,7 +3581,13 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 	if (read_journal) {
 		in_journal_replay = TRUE;
 
-		tracker_db_journal_reader_ontology_init (NULL);
+		tracker_db_journal_reader_ontology_init (NULL, &internal_error);
+
+		if (internal_error) {
+			g_propagate_error (error, internal_error);
+
+			return FALSE;
+		}
 
 		/* Load ontology IDs from journal into memory */
 		load_ontology_ids_from_journal (&uri_id_map, &max_id);
@@ -3594,7 +3601,13 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 		if (!read_journal) {
 			/* Truncate journal as it does not even contain a single valid transaction
 			 * or is explicitly ignored (journal_check == FALSE, only for test cases) */
-			tracker_db_journal_init (NULL, TRUE);
+			tracker_db_journal_init (NULL, TRUE, &internal_error);
+
+			if (internal_error) {
+				g_propagate_error (error, internal_error);
+
+				return FALSE;
+			}
 		}
 
 		/* load ontology from files into memory (max_id starts at zero: first-time) */
@@ -3710,7 +3723,13 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 		check_ontology = FALSE;
 	} else {
 		if (!read_only) {
-			tracker_db_journal_init (NULL, FALSE);
+			tracker_db_journal_init (NULL, FALSE, &internal_error);
+
+			if (internal_error) {
+				g_propagate_error (error, internal_error);
+
+				return FALSE;
+			}
 
 			/* Load ontology from database into memory */
 			db_get_static_data (iface);
@@ -4112,7 +4131,8 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 			if (g_error_matches (internal_error, TRACKER_DB_INTERFACE_ERROR, TRACKER_DB_NO_SPACE)) {
 				tracker_db_manager_remove_all (FALSE);
 				tracker_db_manager_shutdown ();
-				tracker_db_journal_shutdown ();
+				/* Call may fail without notice, we're in error handling already */
+				tracker_db_journal_shutdown (NULL);
 			}
 
 			g_hash_table_unref (uri_id_map);
@@ -4123,7 +4143,14 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 		in_journal_replay = FALSE;
 
 		/* open journal for writing */
-		tracker_db_journal_init (NULL, FALSE);
+		tracker_db_journal_init (NULL, FALSE, &internal_error);
+
+		if (internal_error) {
+			g_hash_table_unref (uri_id_map);
+			g_propagate_error (error, internal_error);
+
+			return FALSE;
+		}
 
 		g_hash_table_unref (uri_id_map);
 	}
@@ -4170,10 +4197,19 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
 void
 tracker_data_manager_shutdown (void)
 {
+	GError *error = NULL;
+
 	g_return_if_fail (initialized == TRUE);
 
 	/* Make sure we shutdown all other modules we depend on */
-	tracker_db_journal_shutdown ();
+	tracker_db_journal_shutdown (&error);
+
+	if (error) {
+		/* TODO: propagate error */
+		g_warning ("%s", error->message);
+		g_error_free (error);
+	}
+
 	tracker_db_manager_shutdown ();
 	tracker_ontologies_shutdown ();
 	if (!reloading) {
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index dfbec66..7560e06 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2960,7 +2960,15 @@ tracker_data_begin_transaction (GError **error)
 
 	if (!in_journal_replay) {
 		if (in_ontology_transaction) {
-			tracker_db_journal_start_ontology_transaction (resource_time);
+			GError *n_error = NULL;
+			tracker_db_journal_start_ontology_transaction (resource_time, &n_error);
+
+			if (n_error) {
+				tracker_db_interface_end_db_transaction (iface, NULL);
+				g_propagate_error (error, n_error);
+				return;
+			}
+
 		} else {
 			tracker_db_journal_start_transaction (resource_time);
 		}
@@ -3012,22 +3020,34 @@ tracker_data_commit_transaction (GError **error)
 		return;
 	}
 
-	get_transaction_modseq ();
-	if (has_persistent && !in_ontology_transaction) {
-		transaction_modseq++;
-	}
-
 	if (!in_journal_replay) {
 		if (has_persistent || in_ontology_transaction) {
-			tracker_db_journal_commit_db_transaction ();
+			tracker_db_journal_commit_db_transaction (&actual_error);
 		} else {
 			/* If we only had transient properties, then we must not write
 			 * anything to the journal. So we roll it back, but only the
 			 * journal's part. */
-			tracker_db_journal_rollback_transaction ();
+			tracker_db_journal_rollback_transaction (&actual_error);
+		}
+
+		if (actual_error) {
+
+			/* Can't write in journal anymore; quite a serious problem, not sure
+			 * if rollback of transaction in the sqlite database is what must be
+			 * done here (behaviour change while adding error reporting to the
+			 * journal) */
+
+			tracker_data_rollback_transaction ();
+			g_propagate_error (error, actual_error);
+			return;
 		}
 	}
 
+	get_transaction_modseq ();
+	if (has_persistent && !in_ontology_transaction) {
+		transaction_modseq++;
+	}
+
 	resource_time = 0;
 	in_transaction = FALSE;
 	in_ontology_transaction = FALSE;
@@ -3091,7 +3111,13 @@ tracker_data_rollback_transaction (void)
 	tracker_db_interface_execute_query (iface, NULL, "PRAGMA cache_size = %d", TRACKER_DB_CACHE_SIZE_DEFAULT);
 
 	if (!in_journal_replay) {
-		tracker_db_journal_rollback_transaction ();
+		tracker_db_journal_rollback_transaction (&ignorable);
+
+		if (ignorable) {
+			/* Not sure if this is also ignorable: it's the close() of the
+			 * journal file failing. */
+			g_error_free (ignorable);
+		}
 
 		if (rollback_callbacks) {
 			guint n;
@@ -3183,10 +3209,17 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
 	TrackerProperty *rdf_type = NULL;
 	gint last_operation_type = 0;
 	const gchar *uri;
+	GError *n_error = NULL;
+
 
 	rdf_type = tracker_ontologies_get_rdf_type ();
 
-	tracker_db_journal_reader_init (NULL);
+	tracker_db_journal_reader_init (NULL, &n_error);
+	if (n_error) {
+		/* This is fatal */
+		g_propagate_error (error, n_error);
+		return;
+	}
 
 	while (tracker_db_journal_reader_next (&journal_error)) {
 		TrackerDBJournalEntryType type;
@@ -3439,15 +3472,28 @@ tracker_data_replay_journal (TrackerBusyCallback   busy_callback,
 		}
 	}
 
+
 	if (journal_error) {
+		GError *n_error = NULL;
 		gsize size;
 
 		size = tracker_db_journal_reader_get_size_of_correct ();
 		tracker_db_journal_reader_shutdown ();
 
-		tracker_db_journal_init (NULL, FALSE);
+		tracker_db_journal_init (NULL, FALSE, &n_error);
+		if (n_error) {
+			/* This is fatal */
+			g_propagate_error (error, n_error);
+			return;
+		}
 		tracker_db_journal_truncate (size);
-		tracker_db_journal_shutdown ();
+		tracker_db_journal_shutdown (&n_error);
+
+		if (n_error) {
+			/* This is fatal */
+			g_propagate_error (error, n_error);
+			return;
+		}
 
 		g_clear_error (&journal_error);
 	} else {
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index c931cd4..3427eb6 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -392,6 +392,7 @@ db_manager_remove_journal (void)
 	gboolean do_rotate = FALSE;
 	const gchar *dirs[3] = { NULL, NULL, NULL };
 	guint i;
+	GError *error = NULL;
 
 	/* We duplicate the path here because later we shutdown the
 	 * journal which frees this data. We want to survive that.
@@ -406,7 +407,12 @@ db_manager_remove_journal (void)
 	directory = g_path_get_dirname (path);
 
 	tracker_db_journal_get_rotating (&do_rotate, &chunk_size, &rotate_to);
-	tracker_db_journal_shutdown ();
+	tracker_db_journal_shutdown (&error);
+
+	if (error) {
+		g_message ("%s", error->message);
+		g_error_free (error);
+	}
 
 	dirs[0] = directory;
 	dirs[1] = do_rotate ? rotate_to : NULL;
diff --git a/src/tracker-control/tracker-control-general.c b/src/tracker-control/tracker-control-general.c
index 247e291..f15ed2e 100644
--- a/src/tracker-control/tracker-control-general.c
+++ b/src/tracker-control/tracker-control-general.c
@@ -438,11 +438,11 @@ tracker_control_general_run (void)
 			return EXIT_FAILURE;
 		}
 
-		tracker_db_journal_init (NULL, FALSE);
+		tracker_db_journal_init (NULL, FALSE, NULL);
 
 		tracker_db_manager_remove_all (hard_reset);
 		tracker_db_manager_shutdown ();
-		tracker_db_journal_shutdown ();
+		tracker_db_journal_shutdown (NULL);
 
 		/* Unset log handler */
 		g_log_remove_handler (NULL, log_handler_id);
diff --git a/tests/libtracker-data/tracker-db-journal.c b/tests/libtracker-data/tracker-db-journal.c
index b7565cc..37df7fb 100644
--- a/tests/libtracker-data/tracker-db-journal.c
+++ b/tests/libtracker-data/tracker-db-journal.c
@@ -26,21 +26,26 @@
 static void
 test_init_and_shutdown (void)
 {
+	GError *error = NULL;
 	gboolean result;
 
 	/* check double init/shutdown */
 	tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
-	result = tracker_db_journal_init (NULL, FALSE);
+	result = tracker_db_journal_init (NULL, FALSE, &error);
+	g_assert_no_error (error);
 	g_assert (result == TRUE);
 
-	result = tracker_db_journal_shutdown ();
+	result = tracker_db_journal_shutdown (&error);
+	g_assert_no_error (error);
 	g_assert (result == TRUE);
 
 	tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
-	result = tracker_db_journal_init (NULL, FALSE);
+	result = tracker_db_journal_init (NULL, FALSE, &error);
+	g_assert_no_error (error);
 	g_assert (result == TRUE);
 
-	result = tracker_db_journal_shutdown ();
+	result = tracker_db_journal_shutdown (&error);
+	g_assert_no_error (error);
 	g_assert (result == TRUE);
 }
 
@@ -51,12 +56,14 @@ test_write_functions (void)
 	const gchar *filename;
 	gsize initial_size, actual_size;
 	gboolean result;
+	GError *error = NULL;
 
 	path = g_build_filename (TOP_BUILDDIR, "tests", "libtracker-db", "tracker-store.journal", NULL);
 	g_unlink (path);
 
 	tracker_db_journal_set_rotating (FALSE, G_MAXSIZE, NULL);
-	tracker_db_journal_init (path, FALSE);
+	tracker_db_journal_init (path, FALSE, &error);
+	g_assert_no_error (error);
 
 	filename = tracker_db_journal_get_filename ();
 	g_assert (filename != NULL);
@@ -76,7 +83,8 @@ test_write_functions (void)
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_delete_statement (0, 10, 11, "test");
 	g_assert_cmpint (result, ==, TRUE);
-	result = tracker_db_journal_rollback_transaction ();
+	result = tracker_db_journal_rollback_transaction (&error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 	actual_size = tracker_db_journal_get_size ();
 	g_assert_cmpint (initial_size, ==, actual_size);
@@ -92,7 +100,8 @@ test_write_functions (void)
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_delete_statement_id (0, 12, 13, 14);
 	g_assert_cmpint (result, ==, TRUE);
-	result = tracker_db_journal_commit_db_transaction ();
+	result = tracker_db_journal_commit_db_transaction (&error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 	actual_size = tracker_db_journal_get_size ();
 	g_assert_cmpint (initial_size, !=, actual_size);
@@ -106,7 +115,8 @@ test_write_functions (void)
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_insert_statement (0, 15, 16, "test");
 	g_assert_cmpint (result, ==, TRUE);
-	result = tracker_db_journal_commit_db_transaction ();
+	result = tracker_db_journal_commit_db_transaction (&error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 
 	/* Test insert id */
@@ -120,14 +130,16 @@ test_write_functions (void)
 	g_assert_cmpint (result, ==, TRUE);
 	result = tracker_db_journal_append_insert_statement_id (0, 17, 18, 19);
 	g_assert_cmpint (result, ==, TRUE);
-	result = tracker_db_journal_commit_db_transaction ();
+	result = tracker_db_journal_commit_db_transaction (&error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 
 	/* Test fsync */
 	result = tracker_db_journal_fsync ();
 	g_assert_cmpint (result, ==, TRUE);
 
-	tracker_db_journal_shutdown ();
+	tracker_db_journal_shutdown (&error);
+	g_assert_no_error (error);
 
 	g_free (path);
 }
@@ -147,7 +159,8 @@ test_read_functions (void)
 	/* NOTE: we don't unlink here so we can use the data from the write tests */
 
 	/* Create an iterator */
-	result = tracker_db_journal_reader_init (path);
+	result = tracker_db_journal_reader_init (path, &error);
+	g_assert_no_error (error);
 	g_assert_cmpint (result, ==, TRUE);
 
 	type = tracker_db_journal_reader_get_type ();



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