[tracker/extraction-improvements: 3/5] tracker-miner-fs: Move "retry on extraction failed" code to TrackerMinerFiles



commit 5b9dcec582bd1a9174170f035414c22fb3f3c864
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed May 4 15:18:47 2011 +0200

    tracker-miner-fs: Move "retry on extraction failed" code to TrackerMinerFiles
    
    Currently the simplest approach of retrying just once
    every failed file is taken, after that, the sparql without
    embedded metadata is added.

 src/libtracker-miner/tracker-miner-fs.c |   33 ++----------
 src/miners/fs/tracker-miner-files.c     |   90 ++++++++++++++++++++++++-------
 2 files changed, 75 insertions(+), 48 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 5d6c631..1490e68 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1652,37 +1652,14 @@ item_add_or_update_cb (TrackerMinerFS        *fs,
 	uri = g_file_get_uri (task_file);
 
 	if (error) {
-		TrackerProcessingTask *first_item_task;
+		g_message ("Could not process '%s': %s", uri, error->message);
 
-		first_item_task = tracker_processing_pool_get_last_wait (fs->private->processing_pool);
+		fs->private->total_files_notified_error++;
 
-		/* Perhaps this is too specific to TrackerMinerFiles, if the extractor
-		 * is choking on some file, the miner will get a timeout for all files
-		 * being currently processed, but the one that is actually causing it
-		 * is the first one that was added to the processing pool, so we retry
-		 * the others.
-		 */
-		if (task != first_item_task &&
-		    (error->code == G_DBUS_ERROR_NO_REPLY ||
-		     error->code == G_DBUS_ERROR_TIMEOUT ||
-		     error->code == G_DBUS_ERROR_TIMED_OUT)) {
-			g_debug ("  Got DBus timeout error on '%s', but it could not be caused by it. Retrying file.", uri);
-
-			/* Reset the TrackerSparqlBuilder */
-			g_object_unref (ctxt->builder);
-			ctxt->builder = tracker_sparql_builder_new_update ();
-
-			do_process_file (fs, task);
-		} else {
-			g_message ("Could not process '%s': %s", uri, error->message);
-
-			fs->private->total_files_notified_error++;
+		tracker_processing_pool_remove_task (fs->private->processing_pool, task);
+		tracker_processing_task_free (task);
 
-			tracker_processing_pool_remove_task (fs->private->processing_pool, task);
-			tracker_processing_task_free (task);
-
-			item_queue_handlers_set_up (fs);
-		}
+		item_queue_handlers_set_up (fs);
 	} else {
 		if (ctxt->urn) {
 			gboolean attribute_update_only;
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 7551862..cc342e6 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -64,6 +64,8 @@ struct ProcessFileData {
 	TrackerSparqlBuilder *sparql;
 	GCancellable *cancellable;
 	GFile *file;
+	gchar *mime_type;
+	guint retried : 1;
 };
 
 struct TrackerMinerFilesPrivate {
@@ -1901,33 +1903,18 @@ process_file_data_free (ProcessFileData *data)
 	g_object_unref (data->sparql);
 	g_object_unref (data->cancellable);
 	g_object_unref (data->file);
+	g_free (data->mime_type);
 	g_slice_free (ProcessFileData, data);
 }
 
 static void
-extractor_get_embedded_metadata_cb (GObject      *object,
-                                    GAsyncResult *res,
-                                    gpointer      user_data)
+sparql_builder_finish (ProcessFileData *data,
+                       const gchar     *preupdate,
+                       const gchar     *sparql,
+                       const gchar     *where)
 {
-	ProcessFileData *data = user_data;
-	const gchar *preupdate, *sparql, *where;
-	TrackerExtractInfo *info;
-	GError *error = NULL;
 	const gchar *uuid;
 
-	info = tracker_extract_client_get_metadata_finish (G_FILE (object), res, &error);
-
-	if (error) {
-		/* Something bad happened, notify about the error */
-		tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, error);
-		process_file_data_free (data);
-		return;
-	}
-
-	preupdate = tracker_extract_info_get_preupdate (info);
-	sparql = tracker_extract_info_get_update (info);
-	where = tracker_extract_info_get_where_clause (info);
-
 	if (sparql && *sparql) {
 		gboolean is_iri;
 		const gchar *urn;
@@ -1997,6 +1984,66 @@ extractor_get_embedded_metadata_cb (GObject      *object,
 		g_free (removable_device_urn);
 		g_free (uri);
 	}
+}
+
+static void
+extractor_get_embedded_metadata_cb (GObject      *object,
+                                    GAsyncResult *res,
+                                    gpointer      user_data)
+{
+	ProcessFileData *data = user_data;
+	const gchar *preupdate, *sparql, *where;
+	TrackerExtractInfo *info;
+	GError *error = NULL;
+
+	info = tracker_extract_client_get_metadata_finish (G_FILE (object), res, &error);
+
+	if (error) {
+		if (error->code == G_DBUS_ERROR_NO_REPLY ||
+		    error->code == G_DBUS_ERROR_TIMEOUT ||
+		    error->code == G_DBUS_ERROR_TIMED_OUT) {
+			gchar *uri;
+
+			uri = g_file_get_uri (data->file);
+
+			if (!data->retried) {
+				data->retried = TRUE;
+
+				g_debug ("  Got extraction DBus error on '%s'. Retrying file.", uri);
+
+				/* Try again extraction */
+				tracker_extract_client_get_metadata (data->file,
+				                                     data->mime_type,
+				                                     data->cancellable,
+				                                     extractor_get_embedded_metadata_cb,
+				                                     data);
+			} else {
+				g_warning ("  Got second extraction DBus error on '%s'. "
+				           "Adding only non-embedded metadata to the SparQL, "
+				           "the error was: %s",
+				           uri, error->message);
+
+				sparql_builder_finish (data, NULL, NULL, NULL);
+				tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, NULL);
+				process_file_data_free (data);
+			}
+
+			g_free (uri);
+		} else {
+			/* Something bad happened, notify about the error */
+			tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, error);
+			process_file_data_free (data);
+		}
+
+		g_error_free (error);
+		return;
+	}
+
+	preupdate = tracker_extract_info_get_preupdate (info);
+	sparql = tracker_extract_info_get_update (info);
+	where = tracker_extract_info_get_where_clause (info);
+
+	sparql_builder_finish (data, preupdate, sparql, where);
 
 	/* Notify about the success */
 	tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, NULL);
@@ -2037,6 +2084,8 @@ process_file_cb (GObject      *object,
 	mime_type = g_file_info_get_content_type (file_info);
 	urn = miner_files_get_file_urn (TRACKER_MINER_FILES (data->miner), file, &is_iri);
 
+	data->mime_type = g_strdup (mime_type);
+
 	tracker_sparql_builder_insert_silent_open (sparql, NULL);
 	tracker_sparql_builder_graph_open (sparql, TRACKER_MINER_FS_GRAPH_URN);
 
@@ -2105,6 +2154,7 @@ process_file_cb (GObject      *object,
 		/* Otherwise, don't request embedded metadata extraction.
 		 * We setup an idle so that we keep the previous behavior. */
 		g_debug ("Avoiding embedded metadata request for uri '%s'", uri);
+		sparql_builder_finish (data, NULL, NULL, NULL);
 		tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, NULL);
 	}
 



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