[tracker-miners/wip/carlosg/cli-improvements: 8/30] libtracker-miner: Retry files asynchronously on TrackerDecorator batch errors




commit 832c531266af62ba8b0f0eccaee7f5b877f83d1c
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Aug 16 13:46:34 2020 +0200

    libtracker-miner: Retry files asynchronously on TrackerDecorator batch errors
    
    We process a number of files together, so any SPARQL error from one file will
    result in the whole batch failing. Retry these files synchronously one by one,
    so we let the good files in, and selectively error out on just the failed files.

 src/libtracker-miner/tracker-decorator.c | 39 +++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 11 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-decorator.c b/src/libtracker-miner/tracker-decorator.c
index 383c28a01..b5ec646b8 100644
--- a/src/libtracker-miner/tracker-decorator.c
+++ b/src/libtracker-miner/tracker-decorator.c
@@ -287,6 +287,31 @@ item_warn (TrackerSparqlConnection *conn,
        g_clear_object (&cursor);
 }
 
+static void
+retry_synchronously (TrackerDecorator *decorator,
+                     GArray           *commit_buffer)
+{
+       TrackerSparqlConnection *sparql_conn;
+       guint i;
+
+       sparql_conn = tracker_miner_get_connection (TRACKER_MINER (decorator));
+
+       for (i = 0; i < commit_buffer->len; i++) {
+               SparqlUpdate *update;
+               GError *error = NULL;
+
+               update = &g_array_index (commit_buffer, SparqlUpdate, i);
+               tracker_sparql_connection_update (sparql_conn,
+                                                 update->sparql,
+                                                 NULL,
+                                                 &error);
+
+               if (error) {
+                       item_warn (sparql_conn, update->id, update->sparql, error);
+               }
+       }
+}
+
 static void
 decorator_commit_cb (GObject      *object,
                      GAsyncResult *result,
@@ -295,8 +320,6 @@ decorator_commit_cb (GObject      *object,
        TrackerSparqlConnection *conn;
        TrackerDecoratorPrivate *priv;
        TrackerDecorator *decorator;
-       GError *error = NULL;
-       guint i;
 
        decorator = user_data;
        priv = decorator->priv;
@@ -304,15 +327,9 @@ decorator_commit_cb (GObject      *object,
 
        priv->n_updates--;
 
-       if (!tracker_sparql_connection_update_array_finish (conn, result, &error)) {
-               g_warning ("There was an error pushing metadata: %s\n", error->message);
-
-               for (i = 0; i < priv->commit_buffer->len; i++) {
-                       SparqlUpdate *update;
-
-                       update = &g_array_index (priv->commit_buffer, SparqlUpdate, i);
-                       item_warn (conn, update->id, update->sparql, error);
-               }
+       if (!tracker_sparql_connection_update_array_finish (conn, result, NULL)) {
+               g_debug ("SPARQL error detected in batch, retrying one by one");
+               retry_synchronously (decorator, priv->commit_buffer);
        }
 
        g_clear_pointer (&priv->commit_buffer, g_array_unref);


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