[tracker] Deleting queued batchupdates and commit when client disappears
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker] Deleting queued batchupdates and commit when client disappears
- Date: Mon, 28 Sep 2009 12:31:38 +0000 (UTC)
commit 680ede23ae4db919477c27a47959224722eb8f42
Author: Philip Van Hoof <philip codeminded be>
Date: Mon Sep 28 14:29:52 2009 +0200
Deleting queued batchupdates and commit when client disappears
src/plugins/kmail/tracker-kmail-registrar.c | 16 +++---
src/tracker-store/tracker-backup.c | 2 +-
src/tracker-store/tracker-dbus.c | 29 ++++++++++++
src/tracker-store/tracker-resources.c | 20 ++++++++-
src/tracker-store/tracker-resources.h | 3 +
src/tracker-store/tracker-store.c | 63 ++++++++++++++++++++++++--
src/tracker-store/tracker-store.h | 3 +
7 files changed, 120 insertions(+), 16 deletions(-)
---
diff --git a/src/plugins/kmail/tracker-kmail-registrar.c b/src/plugins/kmail/tracker-kmail-registrar.c
index 8e656f6..cf1afba 100644
--- a/src/plugins/kmail/tracker-kmail-registrar.c
+++ b/src/plugins/kmail/tracker-kmail-registrar.c
@@ -350,7 +350,7 @@ perform_set (TrackerKMailRegistrar *object,
tracker_sparql_builder_insert_close (sparql);
tracker_store_queue_sparql_update (tracker_sparql_builder_get_result (sparql),
- NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL);
g_object_unref (sparql);
}
@@ -361,7 +361,7 @@ perform_unset (TrackerKMailRegistrar *object,
{
gchar *sparql = g_strdup_printf ("DELETE { <%s> a rdfs:Resource }", subject);
- tracker_store_queue_sparql_update (sparql, NULL, NULL, NULL);
+ tracker_store_queue_sparql_update (sparql, NULL, NULL, NULL, NULL);
g_free (sparql);
}
@@ -369,7 +369,7 @@ perform_unset (TrackerKMailRegistrar *object,
static void
perform_cleanup (TrackerKMailRegistrar *object)
{
- tracker_store_queue_sparql_update ("DELETE { ?s a rdfs:Resource } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }", NULL, NULL, NULL);
+ tracker_store_queue_sparql_update ("DELETE { ?s a rdfs:Resource } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }", NULL, NULL, NULL, NULL);
/* tracker_store_queue_sparql_update ("DELETE { ?s ?p ?o } WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }", NULL, NULL, NULL, NULL); */
}
@@ -412,7 +412,7 @@ tracker_kmail_registrar_set (TrackerKMailRegistrar *object,
perform_set (object, subject, predicates, values);
}
- tracker_store_queue_commit (on_commit,
+ tracker_store_queue_commit (on_commit, NULL,
GUINT_TO_POINTER (modseq),
NULL);
@@ -456,7 +456,7 @@ tracker_kmail_registrar_set_many (TrackerKMailRegistrar *object,
i++;
}
- tracker_store_queue_commit (on_commit,
+ tracker_store_queue_commit (on_commit, NULL,
GUINT_TO_POINTER (modseq),
NULL);
@@ -489,7 +489,7 @@ tracker_kmail_registrar_unset_many (TrackerKMailRegistrar *object,
i++;
}
- tracker_store_queue_commit (on_commit, GUINT_TO_POINTER (modseq), NULL);
+ tracker_store_queue_commit (on_commit, NULL, GUINT_TO_POINTER (modseq), NULL);
dbus_g_method_return (context);
@@ -514,7 +514,7 @@ tracker_kmail_registrar_unset (TrackerKMailRegistrar *object,
perform_unset (object, subject);
- tracker_store_queue_commit (on_commit, GUINT_TO_POINTER (modseq), NULL);
+ tracker_store_queue_commit (on_commit, NULL, GUINT_TO_POINTER (modseq), NULL);
dbus_g_method_return (context);
@@ -536,7 +536,7 @@ tracker_kmail_registrar_cleanup (TrackerKMailRegistrar *object,
perform_cleanup (object);
- tracker_store_queue_commit (on_commit,
+ tracker_store_queue_commit (on_commit, NULL,
GUINT_TO_POINTER (modseq),
NULL);
diff --git a/src/tracker-store/tracker-backup.c b/src/tracker-store/tracker-backup.c
index f63c971..3cd82a3 100644
--- a/src/tracker-store/tracker-backup.c
+++ b/src/tracker-store/tracker-backup.c
@@ -138,7 +138,7 @@ tracker_backup_save (TrackerBackup *object,
* of the open batch (if any), and then in the callback we'll idd
* continue with making the backup itself (using sqlite3_backup's API) */
- tracker_store_queue_commit (on_batch_commit, info, NULL);
+ tracker_store_queue_commit (on_batch_commit, NULL, info, NULL);
}
void
diff --git a/src/tracker-store/tracker-dbus.c b/src/tracker-store/tracker-dbus.c
index 47c88f4..21cdce7 100644
--- a/src/tracker-store/tracker-dbus.c
+++ b/src/tracker-store/tracker-dbus.c
@@ -169,6 +169,24 @@ tracker_dbus_shutdown (void)
connection = NULL;
}
+static void
+name_owner_changed_cb (DBusGProxy *proxy,
+ gchar *name,
+ gchar *old_owner,
+ gchar *new_owner,
+ gpointer user_data)
+{
+ if (tracker_is_empty_string (new_owner) && !tracker_is_empty_string (old_owner)) {
+ /* This means that old_owner got removed */
+ tracker_resources_unreg_batches (user_data, old_owner);
+ }
+}
+
+static void
+name_owner_changed_closure (gpointer data, GClosure *closure)
+{
+}
+
gboolean
tracker_dbus_register_objects (void)
{
@@ -203,6 +221,17 @@ tracker_dbus_register_objects (void)
return FALSE;
}
+ dbus_g_proxy_add_signal (gproxy, "NameOwnerChanged",
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_INVALID);
+
+ dbus_g_proxy_connect_signal (gproxy, "NameOwnerChanged",
+ G_CALLBACK (name_owner_changed_cb),
+ object,
+ name_owner_changed_closure);
+
dbus_register_object (connection,
gproxy,
G_OBJECT (object),
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 5f259b0..bf50ea6 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -277,6 +277,7 @@ tracker_resources_batch_sparql_update (TrackerResources *self,
TrackerDBusMethodInfo *info;
TrackerResourcesPrivate *priv;
guint request_id;
+ gchar *sender;
priv = TRACKER_RESOURCES_GET_PRIVATE (self);
@@ -294,9 +295,12 @@ tracker_resources_batch_sparql_update (TrackerResources *self,
info->request_id = request_id;
info->context = context;
+ sender = dbus_g_method_get_sender (context);
+
tracker_store_queue_sparql_update (update, batch_update_callback,
- info, destroy_method_info);
+ sender, info, destroy_method_info);
+ g_free (sender);
}
static void
@@ -316,6 +320,7 @@ tracker_resources_batch_commit (TrackerResources *self,
TrackerDBusMethodInfo *info;
TrackerResourcesPrivate *priv;
guint request_id;
+ gchar *sender;
priv = TRACKER_RESOURCES_GET_PRIVATE (self);
@@ -329,8 +334,12 @@ tracker_resources_batch_commit (TrackerResources *self,
info->request_id = request_id;
info->context = context;
- tracker_store_queue_commit (batch_commit_callback, info,
+ sender = dbus_g_method_get_sender (context);
+
+ tracker_store_queue_commit (batch_commit_callback, sender, info,
destroy_method_info);
+
+ g_free (sender);
}
@@ -428,3 +437,10 @@ tracker_resources_prepare (TrackerResources *object,
priv->event_sources = event_sources;
}
+
+void
+tracker_resources_unreg_batches (TrackerResources *object,
+ const gchar *old_owner)
+{
+ tracker_store_unreg_batches (old_owner);
+}
diff --git a/src/tracker-store/tracker-resources.h b/src/tracker-store/tracker-resources.h
index 22ffc8c..af71117 100644
--- a/src/tracker-store/tracker-resources.h
+++ b/src/tracker-store/tracker-resources.h
@@ -54,6 +54,9 @@ TrackerResources *tracker_resources_new (void);
void tracker_resources_prepare (TrackerResources *object,
GSList *event_sources);
+void tracker_resources_unreg_batches (TrackerResources *object,
+ const gchar *old_owner);
+
/* DBus methods */
void tracker_resources_load (TrackerResources *object,
const gchar *uri,
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index 78e638f..4504dab 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -58,7 +58,10 @@ typedef enum {
typedef struct {
TrackerStoreTaskType type;
union {
- gchar *query;
+ struct {
+ gchar *query;
+ gchar *client_id;
+ } update;
struct {
gboolean in_progress;
gchar *path;
@@ -90,7 +93,8 @@ store_task_free (TrackerStoreTask *task)
if (task->type == TRACKER_STORE_TASK_TYPE_TURTLE) {
g_free (task->data.turtle.path);
} else {
- g_free (task->data.query);
+ g_free (task->data.update.query);
+ g_free (task->data.update.client_id);
}
g_slice_free (TrackerStoreTask, task);
}
@@ -196,10 +200,10 @@ queue_idle_handler (gpointer user_data)
begin_batch (private);
- tracker_data_update_sparql (task->data.query, &error);
+ tracker_data_update_sparql (task->data.update.query, &error);
if (private->start_log) {
- log_to_journal (private, task->data.query);
+ log_to_journal (private, task->data.update.query);
}
if (!error) {
@@ -407,6 +411,7 @@ start_handler (TrackerStorePrivate *private)
void
tracker_store_queue_commit (TrackerStoreCommitCallback callback,
+ const gchar *client_id,
gpointer user_data,
GDestroyNotify destroy)
{
@@ -421,6 +426,8 @@ tracker_store_queue_commit (TrackerStoreCommitCallback callback,
task->user_data = user_data;
task->callback.commit_callback = callback;
task->destroy = destroy;
+ task->data.update.client_id = g_strdup (client_id);
+ task->data.update.query = NULL;
g_queue_push_tail (private->queue, task);
@@ -433,6 +440,7 @@ tracker_store_queue_commit (TrackerStoreCommitCallback callback,
void
tracker_store_queue_sparql_update (const gchar *sparql,
TrackerStoreSparqlUpdateCallback callback,
+ const gchar *client_id,
gpointer user_data,
GDestroyNotify destroy)
{
@@ -446,10 +454,11 @@ tracker_store_queue_sparql_update (const gchar *sparql,
task = g_slice_new0 (TrackerStoreTask);
task->type = TRACKER_STORE_TASK_TYPE_UPDATE;
- task->data.query = g_strdup (sparql);
+ task->data.update.query = g_strdup (sparql);
task->user_data = user_data;
task->callback.update_callback = callback;
task->destroy = destroy;
+ task->data.update.client_id = g_strdup (client_id);
g_queue_push_tail (private->queue, task);
@@ -577,3 +586,47 @@ tracker_store_get_queue_size (void)
return g_queue_get_length (private->queue);
}
+
+void
+tracker_store_unreg_batches (const gchar *client_id)
+{
+ TrackerStorePrivate *private;
+ static GError *error = NULL;
+ GList *list, *cur;
+
+ private = g_static_private_get (&private_key);
+ g_return_if_fail (private != NULL);
+
+ list = private->queue->head;
+
+ while (list) {
+ TrackerStoreTask *task;
+
+ cur = list;
+ list = list->next;
+ task = cur->data;
+
+ if (task && task->type != TRACKER_STORE_TASK_TYPE_TURTLE) {
+ if (g_strcmp0 (task->data.update.client_id, client_id) == 0) {
+ if (task->type == TRACKER_STORE_TASK_TYPE_UPDATE) {
+ if (!error) {
+ g_set_error (&error, TRACKER_DBUS_ERROR, 0,
+ "Client disappeared");
+ }
+ task->callback.update_callback (error, task->user_data);
+ } else {
+ task->callback.commit_callback (task->user_data);
+ }
+ task->destroy (task->user_data);
+
+ g_queue_delete_link (private->queue, cur);
+
+ store_task_free (task);
+ }
+ }
+ }
+
+ if (error) {
+ g_clear_error (&error);
+ }
+}
diff --git a/src/tracker-store/tracker-store.h b/src/tracker-store/tracker-store.h
index a87320a..877b879 100644
--- a/src/tracker-store/tracker-store.h
+++ b/src/tracker-store/tracker-store.h
@@ -39,10 +39,12 @@ typedef void (* TrackerStoreTurtleCallback) (GError *error,
void tracker_store_init (gboolean load_journal);
void tracker_store_shutdown (void);
void tracker_store_queue_commit (TrackerStoreCommitCallback callback,
+ const gchar *client_id,
gpointer user_data,
GDestroyNotify destroy);
void tracker_store_queue_sparql_update (const gchar *sparql,
TrackerStoreSparqlUpdateCallback callback,
+ const gchar *client_id,
gpointer user_data,
GDestroyNotify destroy);
void tracker_store_queue_turtle_import (GFile *file,
@@ -65,6 +67,7 @@ guint tracker_store_get_queue_size (void);
void tracker_store_play_journal (void);
void tracker_store_flush_journal (void);
+void tracker_store_unreg_batches (const gchar *client_id);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]