[tracker/writeback-refactor-rebase: 23/65] libtracker-miner, miners-fs: Error handling unmount of FS during writeback, add timeout



commit 8f125edacc8cd2a5d0335184189ff47129cf58b5
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Jul 18 13:17:43 2011 +0200

    libtracker-miner, miners-fs: Error handling unmount of FS during writeback, add timeout

 src/libtracker-miner/tracker-miner-fs.c      |   29 ----------
 src/libtracker-miner/tracker-miner-fs.h      |    2 -
 src/miners/fs/tracker-writeback-dispatcher.c |   76 ++++++++++++++++++++++----
 3 files changed, 65 insertions(+), 42 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 5db3089..23731ee 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -4738,8 +4738,6 @@ tracker_miner_fs_writeback_file (TrackerMinerFS *fs,
  * tracker_miner_fs_writeback_notify:
  * @fs: a #TrackerMinerFS
  * @file: a #GFile
- * @rdf_types: a #GStrv
- * @resutls: a #GPtrArray
  * @error: a #GError with the error that happened during processing, or %NULL.
  *
  * Notifies @fs that all writing back on @file has been finished, if any error
@@ -4751,35 +4749,8 @@ tracker_miner_fs_writeback_file (TrackerMinerFS *fs,
 void
 tracker_miner_fs_writeback_notify (TrackerMinerFS *fs,
                                    GFile          *file,
-                                   GStrv           rdf_types,
-                                   GPtrArray      *results,
                                    const GError   *error)
 {
-	if (error && error->code == G_DBUS_ERROR_NO_REPLY) {
-		ItemWritebackData *data;
-		gchar *path;
-
-		/* This happens in case of exit() of the tracker-writeback binary, which
-		 * happens on unmount of the FS event, for example */
-
-		/* TODO: ideally the queue adds a wait time before it retries of a few
-		 * seconds. And also, ideally it doesn't retry for ever: if the
-		 * tracker-writeback binary crashes then the signature or the error-code
-		 * is the same. This would right now result in endless retrying */
-
-		path = g_file_get_path (file);
-
-		g_debug ("%s (WRITEBACK) (retry after unmount event)", path);
-		trace_eq_push_tail ("WRITEBACK", file, "Retry after unmount event");
-
-		data = item_writeback_data_new (file, rdf_types, results);
-
-		g_queue_push_tail (fs->priv->items_writeback, data);
-
-		item_queue_handlers_set_up (fs);
-
-		g_free (path);
-	}
 }
 
 /**
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 98c9421..0b7efd2 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -136,8 +136,6 @@ void                  tracker_miner_fs_writeback_file       (TrackerMinerFS *fs,
                                                              GPtrArray      *results);
 void                  tracker_miner_fs_writeback_notify     (TrackerMinerFS *fs,
                                                              GFile          *file,
-                                                             GStrv           rdf_types,
-                                                             GPtrArray      *results,
                                                              const GError   *error);
 void                  tracker_miner_fs_check_directory      (TrackerMinerFS *fs,
                                                              GFile          *file,
diff --git a/src/miners/fs/tracker-writeback-dispatcher.c b/src/miners/fs/tracker-writeback-dispatcher.c
index 4e2dafe..cd41828 100644
--- a/src/miners/fs/tracker-writeback-dispatcher.c
+++ b/src/miners/fs/tracker-writeback-dispatcher.c
@@ -34,6 +34,8 @@ typedef struct {
 	TrackerMinerFS *fs;
 	GPtrArray *results;
 	GStrv rdf_types;
+	TrackerWritebackDispatcher *self; /* weak */
+	guint retry_timeout;
 } WritebackFileData;
 
 typedef struct {
@@ -62,12 +64,13 @@ static void     writeback_dispatcher_finalize        (GObject              *obje
 static gboolean writeback_dispatcher_initable_init   (GInitable            *initable,
                                                       GCancellable         *cancellable,
                                                       GError              **error);
-static void writeback_dispatcher_writeback_file      (TrackerMinerFS       *fs,
+static void     writeback_dispatcher_writeback_file  (TrackerMinerFS       *fs,
                                                       GFile                *file,
                                                       GStrv                 rdf_types,
                                                       GPtrArray            *results,
                                                       gpointer              user_data);
-
+static void     self_weak_notify                     (gpointer              data,
+                                                      GObject              *where_the_object_was);
 
 static void
 writeback_dispatcher_initable_iface_init (GInitableIface *iface)
@@ -225,6 +228,47 @@ tracker_writeback_dispatcher_new (TrackerMinerFiles  *miner_files,
 }
 
 static void
+writeback_file_data_free (WritebackFileData *data)
+{
+	if (data->self) {
+		g_object_weak_unref (G_OBJECT (data->self), self_weak_notify, data);
+	}
+	g_object_unref (data->fs);
+	g_object_unref (data->file);
+	g_strfreev (data->rdf_types);
+	g_ptr_array_unref (data->results);
+	g_free (data);
+}
+
+static void
+self_weak_notify (gpointer data, GObject *where_the_object_was)
+{
+	WritebackFileData *udata = data;
+	/* Shut down while retrying writeback */
+	g_debug ("Shutdown while retrying WRITEBACK after unmount, not retrying anymore");
+	if (udata->retry_timeout != 0) {
+		g_source_remove (udata->retry_timeout);
+	}
+	udata->self = NULL;
+	writeback_file_data_free (udata);
+}
+
+static gboolean
+retry_idle (gpointer user_data)
+{
+	WritebackFileData *data = user_data;
+
+	tracker_miner_fs_writeback_file (data->fs,
+	                                 data->file,
+	                                 data->rdf_types,
+	                                 data->results);
+
+	writeback_file_data_free (data);
+
+	return FALSE;
+}
+
+static void
 writeback_file_finished  (GObject      *source_object,
                           GAsyncResult *res,
                           gpointer      user_data)
@@ -235,16 +279,23 @@ writeback_file_finished  (GObject      *source_object,
 	g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object),
 	                               res, &error);
 
-	tracker_miner_fs_writeback_notify (data->fs, data->file,
-	                                   data->rdf_types,
-	                                   data->results,
-	                                   error);
+	if (error && error->code == G_DBUS_ERROR_NO_REPLY) {
+		/* This happens in case of exit() of the tracker-writeback binary, which
+		 * happens on unmount of the FS event, for example */
 
-	g_object_unref (data->fs);
-	g_object_unref (data->file);
-	g_strfreev (data->rdf_types);
-	g_ptr_array_unref (data->results);
-	g_free (data);
+		/* TODO: Ideally it doesn't retry for ever: if the tracker-writeback
+		 * binary crashes then the signature or the error-code is the same. This
+		 * would right now result in endless retrying */
+
+		g_debug ("Retry WRITEBACK after unmount");
+		tracker_miner_fs_writeback_notify (data->fs, data->file, NULL);
+
+		data->retry_timeout = g_timeout_add_seconds (5, retry_idle, data);
+
+	} else {
+		tracker_miner_fs_writeback_notify (data->fs, data->file, error);
+		writeback_file_data_free (data);
+	}
 }
 
 static void
@@ -292,6 +343,9 @@ writeback_dispatcher_writeback_file (TrackerMinerFS *fs,
 
 	g_variant_builder_close (&builder);
 
+	data->retry_timeout = 0;
+	data->self = self;
+	g_object_weak_ref (G_OBJECT (data->self), self_weak_notify, data);
 	data->fs = g_object_ref (fs);
 	data->file = g_object_ref (file);
 	data->results = g_ptr_array_ref (results);



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