tracker r1342 - in branches/indexer-split: . src/trackerd
- From: pvanhoof svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1342 - in branches/indexer-split: . src/trackerd
- Date: Mon, 5 May 2008 10:37:12 +0100 (BST)
Author: pvanhoof
Date: Mon May 5 09:37:12 2008
New Revision: 1342
URL: http://svn.gnome.org/viewvc/tracker?rev=1342&view=rev
Log:
2008-05-05 Philip Van Hoof <pvanhoof gnome org>
* src/trackerd/tracker-dbus-xesam.c
* src/trackerd/tracker-xesam.c
* src/trackerd/tracker-db-sqlite.c: Added proper locking for the db
while dealing with Events for LiveSearches
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/trackerd/tracker-db-sqlite.c
branches/indexer-split/src/trackerd/tracker-dbus-xesam.c
branches/indexer-split/src/trackerd/tracker-xesam.c
Modified: branches/indexer-split/src/trackerd/tracker-db-sqlite.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db-sqlite.c (original)
+++ branches/indexer-split/src/trackerd/tracker-db-sqlite.c Mon May 5 09:37:12 2008
@@ -3250,10 +3250,13 @@
}
+GStaticRecMutex events_table_lock = G_STATIC_REC_MUTEX_INIT;
+
TrackerDBResultSet*
tracker_db_get_live_search_hit_count (DBConnection *db_con, const gchar *search_id)
{
TrackerDBResultSet *result;
+ tracker_debug ("GetLiveSearchHitCount");
result = tracker_exec_proc (db_con->common, "GetLiveSearchHitCount", search_id, NULL);
return result;
}
@@ -3263,31 +3266,53 @@
tracker_db_get_live_search_modified_ids (DBConnection *db_con, const gchar *search_id)
{
TrackerDBResultSet *result;
+
+ /* This happens in the GMainLoop */
+ g_static_rec_mutex_lock (&events_table_lock);
+
+ /* Uses the Events table */
+ tracker_debug ("GetLiveSearchModifiedIDs");
+
result = tracker_exec_proc (db_con->common, "GetLiveSearchModifiedIDs", search_id, NULL);
+
+ g_static_rec_mutex_unlock (&events_table_lock);
+
return result;
}
+
TrackerDBResultSet*
tracker_db_get_live_search_new_ids (DBConnection *db_con, const gchar *search_id, const gchar *columns, const gchar *tables, const gchar *query)
{
TrackerDBResultSet *result;
+ /* This happens in the GMainLoop */
+ g_static_rec_mutex_lock (&events_table_lock);
+
// todo: this is a query for ottela to review
// Contract, in @result:
// ServiceID is #1
// EventType is #2
+ /* Uses the Events table */
gchar *m_query = g_strdup_printf (
- "SELECT E.ServiceID, E.EventType, %s "
- "FROM XesamLiveSearches as X, Events as E, %s "
+ "SELECT E.ServiceID, E.EventType%s %s "
+ "FROM XesamLiveSearches as X, Events as E%s %s "
"X.ServiceID = E.ServiceID "
"AND X.SearchID = ? "
"AND X.EventType IS 'Create' OR X.EventType IS 'Update' "
- "AND (%s)", columns, tables, query);
+ "%s%s%s",
+ columns?",":"", columns,
+ tables?",":"", tables,
+ query?"AND (":"", query, query?")":"");
+
+ tracker_debug ("LiveSearchUpdateQuery: %s", m_query);
result = tracker_db_interface_execute_query (db_con->db, NULL, m_query);
+ g_static_rec_mutex_unlock (&events_table_lock);
+
g_free (m_query);
return result;
@@ -3297,9 +3322,19 @@
tracker_db_get_events (DBConnection *db_con)
{
TrackerDBResultSet *result_set, *result;
+
+ /* This happens in the GMainLoop */
+ g_static_rec_mutex_lock (&events_table_lock);
+
+ /* Uses the Events table */
+ tracker_debug ("GetEvents");
result = tracker_exec_proc (db_con->common, "GetEvents", NULL);
+ tracker_debug ("SetEventsBeingHandled");
result_set = tracker_exec_proc (db_con->common, "SetEventsBeingHandled", NULL);
g_object_unref (result_set);
+
+ g_static_rec_mutex_unlock (&events_table_lock);
+
return result;
}
@@ -3307,8 +3342,18 @@
tracker_db_delete_handled_events (DBConnection *db_con, TrackerDBResultSet *events)
{
TrackerDBResultSet *result_set;
+
+ /* This happens in the GMainLoop */
+ g_static_rec_mutex_lock (&events_table_lock);
+
+ /* Uses the Events table */
+ tracker_debug ("DeleteHandledEvents");
+
result_set = tracker_exec_proc (db_con->common, "DeleteHandledEvents", NULL);
g_object_unref (result_set);
+
+ g_static_rec_mutex_unlock (&events_table_lock);
+
}
static guint32
@@ -3319,10 +3364,14 @@
int i;
guint32 id = 0;
+ /* This happens in the indexer's thread */
+ g_static_rec_mutex_lock (&events_table_lock);
+
result_set = tracker_exec_proc (db_con->common, "GetNewEventID", NULL);
if (!result_set) {
tracker_error ("ERROR: could not create event - GetNewEventID failed");
+ g_static_rec_mutex_unlock (&events_table_lock);
return 0;
}
@@ -3336,6 +3385,9 @@
if (result_set)
g_object_unref (result_set);
+ /* Uses the Events table */
+ tracker_debug ("CreateEvent %s", eid);
+
result_set = tracker_exec_proc (db_con, "CreateEvent", eid, service_id_str, type, NULL);
id = tracker_db_interface_sqlite_get_last_insert_id (TRACKER_DB_INTERFACE_SQLITE (db_con->db));
if (result_set)
@@ -3345,6 +3397,8 @@
g_free (eid);
+ g_static_rec_mutex_unlock (&events_table_lock);
+
return id;
}
@@ -3361,8 +3415,11 @@
int service_type_id;
char *str_service_type_id, *path, *name;
+ g_static_rec_mutex_lock (&events_table_lock);
+
if (!info || !info->uri || !info->uri[0] || !service || !db_con) {
tracker_error ("ERROR: cannot create service");
+ g_static_rec_mutex_unlock (&events_table_lock);
return 0;
}
@@ -3382,6 +3439,7 @@
if (!result_set) {
tracker_error ("ERROR: could not create service - GetNewID failed");
+ g_static_rec_mutex_unlock (&events_table_lock);
return 0;
}
@@ -3445,6 +3503,7 @@
g_free (str_filesize);
g_free (str_mtime);
g_free (str_offset);
+ g_static_rec_mutex_unlock (&events_table_lock);
return 0;
}
id = tracker_db_interface_sqlite_get_last_insert_id (TRACKER_DB_INTERFACE_SQLITE (db_con->db));
@@ -3464,7 +3523,8 @@
g_free (parent);
}
- tracker_db_create_event (db_con, sid, "Create");
+ if (tracker_config_get_enable_xesam (tracker->config))
+ tracker_db_create_event (db_con, sid, "Create");
}
g_free (name);
@@ -3476,6 +3536,8 @@
g_free (str_mtime);
g_free (str_offset);
+ g_static_rec_mutex_unlock (&events_table_lock);
+
return id;
}
Modified: branches/indexer-split/src/trackerd/tracker-dbus-xesam.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-xesam.c (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-xesam.c Mon May 5 09:37:12 2008
@@ -79,6 +79,23 @@
}
static void
+xesam_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
+{
+ TrackerDBusXesamPriv *priv;
+
+ priv = GET_PRIV (object);;
+
+ switch (prop_id) {
+ case PROP_DB_CONNECTION:
+ g_value_set_pointer (value, priv->db_con);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+static void
xesam_set_property (GObject *object,
guint param_id,
const GValue *value,
@@ -107,13 +124,14 @@
object_class->finalize = xesam_search_finalize;
object_class->set_property = xesam_set_property;
+ object_class->get_property = xesam_get_property;
g_object_class_install_property (object_class,
PROP_DB_CONNECTION,
g_param_spec_pointer ("db-connection",
"DB connection",
"Database connection to use in transactions",
- G_PARAM_WRITABLE));
+ G_PARAM_WRITABLE|G_PARAM_READABLE));
signals[XESAM_HITS_ADDED] =
g_signal_new ("hits-added",
Modified: branches/indexer-split/src/trackerd/tracker-xesam.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-xesam.c (original)
+++ branches/indexer-split/src/trackerd/tracker-xesam.c Mon May 5 09:37:12 2008
@@ -20,6 +20,7 @@
*/
#include "tracker-xesam.h"
+#include <libtracker-common/tracker-config.h>
extern Tracker *tracker;
@@ -147,11 +148,15 @@
TrackerDBusXesam *proxy = TRACKER_DBUS_XESAM (tracker_dbus_get_object (TRACKER_TYPE_DBUS_XESAM));
DBConnection *db_con = NULL;
+ if (!proxy)
+ return FALSE;
+
g_object_get (proxy, "db-connection", &db_con, NULL);
- // lock (indexer)
+ if (!db_con)
+ return FALSE;
+
result_set = tracker_db_get_events (db_con);
- // lock (indexer)
if (tracker_db_result_set_get_n_rows (result_set) > 0) {
@@ -189,9 +194,7 @@
}
g_list_free (sessions);
- // lock (indexer)
tracker_db_delete_handled_events (db_con, result_set);
- // unlock (indexer)
}
g_object_unref (result_set);
@@ -199,10 +202,7 @@
return reason_to_live;
}
-/* Should be set initially to FALSE instead (but then we activate this
- * unfinished code)*/
-
-static gboolean live_search_handler_running = TRUE;
+static gboolean live_search_handler_running = FALSE;
static void
live_search_handler_destroy (gpointer data)
@@ -213,7 +213,7 @@
void
tracker_xesam_wakeup (guint32 last_id)
{
- // This happens each time a new event is created
+ /* This happens each time a new event is created */
if (!live_search_handler_running) {
live_search_handler_running = TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]