[tracker/duplicates-after-interrupts] libtracker-miner: loop until a successful query in item_query_exists()
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/duplicates-after-interrupts] libtracker-miner: loop until a successful query in item_query_exists()
- Date: Tue, 13 Jul 2010 11:11:44 +0000 (UTC)
commit 5f8b55ae9854e677b5169e806dcb8e1eb7dd890c
Author: Aleksander Morgado <aleksander lanedo com>
Date: Tue Jul 13 13:10:15 2010 +0200
libtracker-miner: loop until a successful query in item_query_exists()
src/libtracker-miner/tracker-miner-fs.c | 48 ++++++++++++++++++++++--------
1 files changed, 35 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 1903257..fddb6a5 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -72,6 +72,7 @@ typedef struct {
gchar *iri;
gchar *mime;
gboolean get_mime;
+ GError *error;
} ItemQueryExistsData;
typedef struct {
@@ -1073,17 +1074,15 @@ item_query_exists_cb (GObject *object,
ItemQueryExistsData *data = user_data;
TrackerResultIterator *iterator;
TrackerMiner *miner;
- GError *error = NULL;
guint n_results;
miner = TRACKER_MINER (object);
- iterator = tracker_miner_execute_sparql_finish (miner, result, &error);
+ iterator = tracker_miner_execute_sparql_finish (miner, result, &data->error);
g_main_loop_quit (data->main_loop);
- if (error) {
- g_critical ("Could not execute sparql query: %s", error->message);
- g_error_free (error);
+ /* If any error found during query, like an Interrupt, return */
+ if (data->error) {
return;
}
@@ -1120,9 +1119,11 @@ item_query_exists (TrackerMinerFS *miner,
gchar **iri,
gchar **mime)
{
- gboolean result;
- gchar *sparql, *uri;
+ gboolean result;
+ gchar *sparql;
+ gchar *uri;
ItemQueryExistsData data = { 0 };
+ guint n_retries = 0;
data.get_mime = (mime != NULL);
@@ -1137,13 +1138,34 @@ item_query_exists (TrackerMinerFS *miner,
data.main_loop = g_main_loop_new (NULL, FALSE);
data.uri = uri;
- tracker_miner_execute_sparql (TRACKER_MINER (miner),
- sparql,
- NULL,
- item_query_exists_cb,
- &data);
+ /* Loop to make sure that we ALWAYS get a successful reply
+ * here. If we get interrupted, for example, we need to retry.
+ * This loop will run forever until we get a proper result,
+ * otherwise we'll end up with duplicates in the store */
+ while (1) {
+ tracker_miner_execute_sparql (TRACKER_MINER (miner),
+ sparql,
+ NULL,
+ item_query_exists_cb,
+ &data);
+
+ g_main_loop_run (data.main_loop);
+
+ if (data.error) {
+ /* Note that data.iri and data.mime cannot be
+ * initialized in this case */
+ g_message ("RETRYING (%u) after failed query for existence of item '%s': '%s'",
+ ++n_retries,
+ uri,
+ data.error->message);
+ g_error_free (data.error);
+ data.error = NULL;
+ } else {
+ /* Successful reply from store, we can safely go on */
+ break;
+ }
+ }
- g_main_loop_run (data.main_loop);
result = (data.iri != NULL);
g_main_loop_unref (data.main_loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]