tracker r1394 - branches/indexer-split/src/trackerd
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1394 - branches/indexer-split/src/trackerd
- Date: Mon, 12 May 2008 14:55:11 +0100 (BST)
Author: mr
Date: Mon May 12 13:55:10 2008
New Revision: 1394
URL: http://svn.gnome.org/viewvc/tracker?rev=1394&view=rev
Log:
* src/trackerd/tracker-db.c: Fix some build warnings.
* src/trackerd/tracker-email-utils.c: Renamed Tracker member.
* src/trackerd/tracker-process-files.c: Log when the thread exits.
Modified:
branches/indexer-split/src/trackerd/tracker-cache.c
branches/indexer-split/src/trackerd/tracker-cache.h
branches/indexer-split/src/trackerd/tracker-db-sqlite.c
branches/indexer-split/src/trackerd/tracker-db.c
branches/indexer-split/src/trackerd/tracker-email-utils.c
branches/indexer-split/src/trackerd/tracker-main.c
branches/indexer-split/src/trackerd/tracker-main.h
branches/indexer-split/src/trackerd/tracker-process-files.c
Modified: branches/indexer-split/src/trackerd/tracker-cache.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-cache.c (original)
+++ branches/indexer-split/src/trackerd/tracker-cache.c Mon May 12 13:55:10 2008
@@ -1,5 +1,6 @@
-/* Tracker - indexer and metadata database engine
- * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2007, Jamie McCracken
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -37,24 +38,26 @@
extern Tracker *tracker;
-typedef struct
-{
- Indexer *file_index;
- Indexer *file_update_index;
- Indexer *email_index;
-
-
+typedef struct {
+ Indexer *file_index;
+ Indexer *file_update_index;
+ Indexer *email_index;
} IndexConnection;
+static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
+
+static GHashTable *file_word_table;
+static GHashTable *file_update_word_table;
+static GHashTable *email_word_table;
static Indexer *
-create_merge_index (const char *name)
+create_merge_index (const gchar *name)
{
Indexer *indexer;
- char *temp_file_name;
- int i;
+ gchar *temp_file_name;
+ gint i;
- for (i=1; i < 1000; i++) {
+ for (i = 1; i < 1000; i++) {
temp_file_name = g_strdup_printf ("%s%d", name, i);
char *tmp = g_build_filename (tracker->data_dir, temp_file_name, NULL);
@@ -64,7 +67,9 @@
g_free (tmp);
continue;
}
+
g_free (tmp);
+
break;
}
@@ -75,94 +80,198 @@
return indexer;
}
-
-
-static gint
-flush_all_file_words ( gpointer key,
- gpointer value,
- gpointer data)
+static gboolean
+file_word_table_foreach (gpointer key,
+ gpointer value,
+ gpointer data)
{
IndexConnection *index_con = data;
+ GByteArray *array = value;
+
+ if (!array) {
+ return TRUE;
+ }
+
+ if (data) {
+ tracker_indexer_append_word_chunk (index_con->file_index,
+ key,
+ (WordDetails*) array->data,
+ array->len / sizeof (WordDetails));
+ }
- GByteArray *array = value;
+ g_byte_array_free (array, TRUE);
+ g_free (key);
+
+ return TRUE;
+}
- if (array) {
+static gboolean
+file_update_word_table_foreach (gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ IndexConnection *index_con = data;
+ GByteArray *array = value;
- tracker_indexer_append_word_chunk (index_con->file_index, key, (WordDetails *) array->data, (array->len / sizeof (WordDetails)));
+ if (!array) {
+ return TRUE;
+ }
- g_byte_array_free (array, TRUE);
+ if (data) {
+ tracker_indexer_update_word_chunk (index_con->file_update_index,
+ key,
+ (WordDetails*) array->data,
+ array->len / sizeof (WordDetails));
}
+ g_byte_array_free (array, TRUE);
g_free (key);
- return 1;
+ return TRUE;
}
-
-static gint
-flush_all_file_update_words ( gpointer key,
- gpointer value,
- gpointer data)
+static gboolean
+email_word_table_foreach (gpointer key,
+ gpointer value,
+ gpointer data)
{
IndexConnection *index_con = data;
+ GByteArray *array = value;
- GByteArray *array = value;
-
- if (array) {
-
- tracker_indexer_update_word_chunk (index_con->file_update_index, key, (WordDetails *) array->data, (array->len / sizeof (WordDetails)));
-
- g_byte_array_free (array, TRUE);
+ if (!array) {
+ return TRUE;
+ }
+
+ if (data) {
+ tracker_indexer_append_word_chunk (index_con->email_index,
+ key,
+ (WordDetails*) array->data,
+ array->len / sizeof (WordDetails));
}
+ g_byte_array_free (array, TRUE);
g_free (key);
- return 1;
+ return TRUE;
}
+static gboolean
+cache_needs_flush (void)
+{
+ gint estimate_cache;
+
+ estimate_cache = tracker->word_detail_count * 8;
+ estimate_cache += tracker->word_count * 75;
+ estimate_cache += tracker->word_update_count * 75;
+
+ if (estimate_cache > tracker->memory_limit) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
-static gint
-flush_all_email_words ( gpointer key,
- gpointer value,
- gpointer data)
+static inline gboolean
+is_email (gint service_type)
{
- IndexConnection *index_con = data;
+ return service_type >= tracker->email_service_min &&
+ service_type <= tracker->email_service_max;
+}
+
+static gboolean
+update_word_table (GHashTable *table,
+ const gchar *word,
+ WordDetails *word_details)
+{
+ GByteArray *array;
+ gboolean new_word;
+ gint sz;
+
+ new_word = FALSE;
+ sz = sizeof (WordDetails);
+
+ tracker->word_detail_count++;
- GByteArray *array = value;
+ array = g_hash_table_lookup (table, word);
- if (array) {
+ if (!array) {
+ if (!tracker_config_get_low_memory_mode (tracker->config)) {
+ array = g_byte_array_sized_new (sz * 2);
+ } else {
+ array = g_byte_array_sized_new (sz);
+ }
+
+ new_word = TRUE;
+ }
- tracker_indexer_append_word_chunk (index_con->email_index, key, (WordDetails *) array->data, (array->len / sizeof (WordDetails)));
+ array = g_byte_array_append (array, (guint8*) word_details, sz);
- g_byte_array_free (array, TRUE);
+ if (new_word) {
+ g_hash_table_insert (table, g_strdup (word), array);
+ } else {
+ g_hash_table_insert (table, (gchar*) word, array);
}
- g_free (key);
-
- return 1;
+ return new_word;
+}
+
+void
+tracker_cache_init (void)
+{
+ if (file_word_table ||
+ file_update_word_table ||
+ email_word_table) {
+ /* Already initialised */
+ return;
+ }
+
+ file_word_table = g_hash_table_new (g_str_hash, g_str_equal);
+ file_update_word_table = g_hash_table_new (g_str_hash, g_str_equal);
+ email_word_table = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+void
+tracker_cache_shutdown (void)
+{
+ g_hash_table_foreach_remove (email_word_table, email_word_table_foreach, NULL);
+ g_hash_table_destroy (email_word_table);
+ email_word_table = NULL;
+
+ g_hash_table_foreach_remove (file_update_word_table, file_update_word_table_foreach, NULL);
+ g_hash_table_destroy (file_update_word_table);
+ file_update_word_table = NULL;
+
+ g_hash_table_foreach_remove (file_word_table, file_word_table_foreach, NULL);
+ g_hash_table_destroy (file_word_table);
+ email_word_table = NULL;
}
void
-tracker_cache_flush_all ()
+tracker_cache_flush_all (void)
{
IndexConnection index_con;
- gboolean using_file_tmp = FALSE, using_email_tmp = FALSE;
+ gboolean using_file_tmp = FALSE;
+ gboolean using_email_tmp = FALSE;
- if (tracker->word_count == 0 && tracker->word_update_count == 0) {
+ if (tracker->word_count == 0 &&
+ tracker->word_update_count == 0) {
return;
}
- tracker_log ("Flushing all words - total hits in cache is %d, total words %d", tracker->word_detail_count, tracker->word_count);
-
- /* if word count is small then flush to main index rather than a new temp index */
+ tracker_log ("Flushing all words - total hits in cache is %d, total words %d",
+ tracker->word_detail_count,
+ tracker->word_count);
+
+ /* If word count is small then flush to main index rather than
+ * a new temp index.
+ */
if (tracker->word_count < 1500) {
-
- index_con.file_index = tracker->file_index;
+ index_con.file_index = tracker->file_index;
index_con.email_index = tracker->email_index;
-
} else {
-
- /* determine is index has been written to significantly before and create new ones if so */
+ /* Determine is index has been written to
+ * significantly before and create new ones if so.
+ */
if (tracker_indexer_size (tracker->file_index) > 4000000) {
index_con.file_index = create_merge_index ("file-index.tmp.");
tracker_log ("flushing to %s", tracker_indexer_get_name (index_con.file_index));
@@ -180,20 +289,16 @@
}
}
- if (!tracker_indexer_has_merge_files (INDEX_TYPE_FILES) && tracker->word_update_count < 5000) {
+ if (!tracker_indexer_has_merge_files (INDEX_TYPE_FILES) &&
+ tracker->word_update_count < 5000) {
index_con.file_update_index = tracker->file_index;
} else {
index_con.file_update_index = tracker->file_update_index;
}
- g_hash_table_foreach (tracker->file_word_table, (GHFunc) flush_all_file_words, &index_con);
- g_hash_table_destroy (tracker->file_word_table);
-
- g_hash_table_foreach (tracker->email_word_table, (GHFunc) flush_all_email_words, &index_con);
- g_hash_table_destroy (tracker->email_word_table);
-
- g_hash_table_foreach (tracker->file_update_word_table, (GHFunc) flush_all_file_update_words, &index_con);
- g_hash_table_destroy (tracker->file_update_word_table);
+ g_hash_table_foreach_remove (file_word_table, file_word_table_foreach, &index_con);
+ g_hash_table_foreach_remove (email_word_table, email_word_table_foreach, &index_con);
+ g_hash_table_foreach_remove (file_update_word_table, file_update_word_table_foreach, &index_con);
if (using_file_tmp) {
tracker_indexer_close (index_con.file_index);
@@ -203,109 +308,55 @@
tracker_indexer_close (index_con.email_index);
}
- tracker->file_word_table = g_hash_table_new (g_str_hash, g_str_equal);
- tracker->file_update_word_table = g_hash_table_new (g_str_hash, g_str_equal);
- tracker->email_word_table = g_hash_table_new (g_str_hash, g_str_equal);
-
tracker->word_detail_count = 0;
tracker->word_count = 0;
tracker->word_update_count = 0;
}
-
-static gboolean
-cache_needs_flush ()
-{
-
- int estimate_cache;
-
- estimate_cache = tracker->word_detail_count * 8;
-
- estimate_cache += (tracker->word_count * 75) + (tracker->word_update_count * 75);
-
- if (estimate_cache > tracker->memory_limit) {
- return TRUE;
- }
-
- return FALSE;
-
-
-}
-
-
-static inline gboolean
-is_email (gint service_type)
-{
- return (service_type >= tracker->email_service_min && service_type <= tracker->email_service_max);
-}
-
-
-static gboolean
-update_word_table (GHashTable *table, const char *word, WordDetails *word_details)
-{
- gboolean new_word = FALSE;
-
- int sz = sizeof (WordDetails);
-
- tracker->word_detail_count++;
-
- GByteArray *array = g_hash_table_lookup (table, word);
-
- if (!array) {
-
- if (!tracker_config_get_low_memory_mode (tracker->config)) {
- array = g_byte_array_sized_new (sz * 2);
- } else {
- array = g_byte_array_sized_new (sz);
- }
-
- new_word = TRUE;
- }
-
- array = g_byte_array_append (array, (guint8 *) word_details, sz);
-
- if (new_word) {
- g_hash_table_insert (table, g_strdup (word), array);
- } else {
- g_hash_table_insert (table, (gchar *) word, array);
- }
-
- return new_word;
-
-}
-
-
void
-tracker_cache_add (const gchar *word, guint32 service_id, gint service_type, gint score, gboolean is_new)
+tracker_cache_add (const gchar *word,
+ guint32 service_id,
+ gint service_type,
+ gint score,
+ gboolean is_new)
{
- static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
WordDetails word_details;
word_details.id = service_id;
word_details.amalgamated = tracker_indexer_calc_amalgamated (service_type, score);
if (is_new) {
-
- /* no need to mutex new stuff as only one thread is processing them */
+ /* No need to mutex new stuff as only one thread is
+ * processing them.
+ */
if (!is_email (service_type)) {
- if (update_word_table (tracker->file_word_table, word, &word_details)) tracker->word_count++;
+ if (update_word_table (file_word_table, word, &word_details)) {
+ tracker->word_count++;
+ }
} else {
- if (update_word_table (tracker->email_word_table, word, &word_details)) tracker->word_count++;
- }
-
+ if (update_word_table (email_word_table, word, &word_details)) {
+ tracker->word_count++;
+ }
+ }
} else {
- /* we need to mutex this to prevent corruption on multi cpu machines as both index process thread and user request thread (when setting tags/metadata) can call this */
+ /* We need to mutex this to prevent corruption on
+ * multi cpu machines as both index process thread and
+ * user request thread (when setting tags/metadata)
+ * can call this.
+ */
g_static_mutex_lock (&mutex);
- if (update_word_table (tracker->file_update_word_table, word, &word_details)) tracker->word_update_count++;
+ if (update_word_table (file_update_word_table, word, &word_details)) {
+ tracker->word_update_count++;
+ }
g_static_mutex_unlock (&mutex);
}
-
}
gboolean
-tracker_cache_process_events (DBConnection *db_con, gboolean check_flush)
+tracker_cache_process_events (DBConnection *db_con,
+ gboolean check_flush)
{
GObject *object;
gboolean stopped_trans = FALSE;
@@ -313,17 +364,18 @@
object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
while (TRUE) {
-
gboolean sleep = FALSE;
-
if (tracker->shutdown) {
return FALSE;
}
if (!tracker->is_running ||
!tracker_config_get_enable_indexing (tracker->config)) {
- if (check_flush) tracker_cache_flush_all ();
+ if (check_flush) {
+ tracker_cache_flush_all ();
+ }
+
sleep = TRUE;
}
@@ -337,8 +389,9 @@
}
if (sleep) {
-
- if (db_con) tracker_db_end_index_transaction (db_con);
+ if (db_con) {
+ tracker_db_end_index_transaction (db_con);
+ }
/* Signal state change */
g_signal_emit_by_name (object,
@@ -355,8 +408,11 @@
g_cond_wait (tracker->files_signal_cond,
tracker->files_signal_mutex);
} else {
-
- /* set mutex to indicate we are in "check" state to prevent race conditions from other threads resetting gloabl vars */
+ /* Set mutex to indicate we are in
+ * "check" state to prevent race
+ * conditions from other threads
+ * resetting gloabl vars.
+ */
g_mutex_lock (tracker->files_check_mutex);
if ((!tracker->is_running ||
@@ -369,9 +425,12 @@
g_mutex_unlock (tracker->files_check_mutex);
}
- /* determine if wake up call is a shutdown signal */
+ /* Determine if wake up call is a shutdown signal */
if (tracker->shutdown) {
- if (check_flush) tracker_cache_flush_all ();
+ if (check_flush) {
+ tracker_cache_flush_all ();
+ }
+
return FALSE;
} else {
/* Signal state change */
@@ -386,12 +445,10 @@
tracker_config_get_enable_indexing (tracker->config));
continue;
}
-
- }
+ }
if (tracker->grace_period > 1) {
-
- tracker_log ("pausing indexing while client requests or external disk I/O are taking place");
+ tracker_log ("Pausing indexer while client requests/disk I/O take place");
tracker->request_waiting = FALSE;
@@ -417,10 +474,11 @@
tracker->grace_period--;
- if (tracker->grace_period > 2) tracker->grace_period = 2;
+ if (tracker->grace_period > 2) {
+ tracker->grace_period = 2;
+ }
continue;
-
} else {
if (tracker->pause_io) {
tracker->pause_io = FALSE;
@@ -438,9 +496,7 @@
}
}
-
if (check_flush && cache_needs_flush ()) {
-
if (db_con) {
tracker_db_end_index_transaction (db_con);
tracker_db_refresh_all (db_con->data);
@@ -448,22 +504,14 @@
}
tracker_cache_flush_all ();
-
}
-
- if (stopped_trans
- && db_con
- && !tracker_db_is_in_transaction (db_con)) {
+ if (stopped_trans && db_con && !tracker_db_is_in_transaction (db_con)) {
tracker_db_start_index_transaction (db_con);
}
tracker_throttle (5000);
return TRUE;
-
}
-
-
}
-
Modified: branches/indexer-split/src/trackerd/tracker-cache.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-cache.h (original)
+++ branches/indexer-split/src/trackerd/tracker-cache.h Mon May 12 13:55:10 2008
@@ -26,12 +26,14 @@
G_BEGIN_DECLS
+void tracker_cache_init (void);
+void tracker_cache_shutdown (void);
void tracker_cache_add (const gchar *word,
guint32 service_id,
gint service_type,
gint score,
gboolean is_new);
-void tracker_cache_flush_all ();
+void tracker_cache_flush_all (void);
gboolean tracker_cache_process_events (DBConnection *db_con,
gboolean check_flush);
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 12 13:55:10 2008
@@ -1490,11 +1490,11 @@
gboolean
-tracker_db_needs_setup ()
+tracker_db_needs_setup (void)
{
- return (!tracker_db_manager_file_exists (TRACKER_DB_FILE_META)
- || !file_exists (tracker->data_dir, TRACKER_INDEXER_FILE_INDEX_DB_FILENAME)
- || !tracker_db_manager_file_exists (TRACKER_DB_FILE_CONTENTS));
+ return (!tracker_db_manager_file_exists (TRACKER_DB_FILE_META) ||
+ !file_exists (tracker->data_dir, TRACKER_INDEXER_FILE_INDEX_DB_FILENAME) ||
+ !tracker_db_manager_file_exists (TRACKER_DB_FILE_CONTENTS));
}
Modified: branches/indexer-split/src/trackerd/tracker-db.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db.c (original)
+++ branches/indexer-split/src/trackerd/tracker-db.c Mon May 12 13:55:10 2008
@@ -276,35 +276,48 @@
void
-tracker_db_save_thumbs (DBConnection *db_con, const char *small_thumb, const char *large_thumb, guint32 file_id)
+tracker_db_save_thumbs (DBConnection *db_con,
+ const gchar *small_thumb,
+ const gchar *large_thumb,
+ guint32 file_id)
{
- char *str_file_id;
+#if 0
+ gchar *str_file_id;
str_file_id = tracker_uint_to_string (file_id);
g_return_if_fail (str_file_id);
if (small_thumb) {
- char *small_thumb_file;
+ gchar *small_thumb_file;
- /* small_thumb_file = tracker_escape_string (small_thumb); */
-/* tracker_db_set_metadata (db_con, "Files", str_file_id, "File.SmallThumbnailPath", small_thumb_file, TRUE, FALSE, TRUE); */
-/* tracker_exec_proc (db_con, "SetMetadata", "Files", str_file_id, "File.SmallThumbnailPath", small_thumb_file, "1", NULL); */
- /* g_free (small_thumb_file); */
+ small_thumb_file = tracker_escape_string (small_thumb);
+ tracker_db_set_metadata (db_con,
+ "Files", str_file_id,
+ "File.SmallThumbnailPath", small_thumb_file,
+ TRUE, FALSE, TRUE);
+ tracker_exec_proc (db_con, "SetMetadata",
+ "Files", str_file_id,
+ "File.SmallThumbnailPath", small_thumb_file,
+ "1", NULL);
+ g_free (small_thumb_file);
}
if (large_thumb) {
- char *large_thumb_file;
+ gchar *large_thumb_file;
- /* large_thumb_file = tracker_escape_string (large_thumb); */
-/* tracker_db_set_metadata (db_con, "Files", str_file_id, "File.LargeThumbnailPath", large_thumb_file, TRUE, FALSE, TRUE); */
- /* g_free (large_thumb_file); */
+ large_thumb_file = tracker_escape_string (large_thumb);
+ tracker_db_set_metadata (db_con,
+ "Files", str_file_id,
+ "File.LargeThumbnailPath", large_thumb_file,
+ TRUE, FALSE, TRUE);
+ g_free (large_thumb_file);
}
g_free (str_file_id);
+#endif
}
-
char **
tracker_db_get_files_in_folder (DBConnection *db_con, const char *folder_uri)
{
Modified: branches/indexer-split/src/trackerd/tracker-email-utils.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-email-utils.c (original)
+++ branches/indexer-split/src/trackerd/tracker-email-utils.c Mon May 12 13:55:10 2008
@@ -792,12 +792,12 @@
gchar *str_uint, *tmp_filename, *tmp_name;
g_return_val_if_fail (filename, NULL);
- g_return_val_if_fail (tracker->email_attachements_dir, NULL);
+ g_return_val_if_fail (tracker->email_attachments_dir, NULL);
str_uint = tracker_uint_to_string (g_random_int ());
tmp_filename = g_strconcat (str_uint, "-", filename, NULL);
g_free (str_uint);
- tmp_name = g_build_filename (tracker->email_attachements_dir, tmp_filename, NULL);
+ tmp_name = g_build_filename (tracker->email_attachments_dir, tmp_filename, NULL);
g_free (tmp_filename);
return tmp_name;
Modified: branches/indexer-split/src/trackerd/tracker-main.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-main.c (original)
+++ branches/indexer-split/src/trackerd/tracker-main.c Mon May 12 13:55:10 2008
@@ -46,16 +46,17 @@
#include <libtracker-common/tracker-file-utils.h>
#include <libtracker-common/tracker-nfs-lock.h>
-#include "tracker-dbus.h"
#include "tracker-email.h"
+#include "tracker-cache.h"
+#include "tracker-dbus.h"
+#include "tracker-db-manager.h"
+#include "tracker-hal.h"
#include "tracker-indexer.h"
#include "tracker-process-files.h"
-#include "tracker-watch.h"
-#include "tracker-hal.h"
#include "tracker-service-manager.h"
#include "tracker-status.h"
+#include "tracker-watch.h"
#include "tracker-xesam.h"
-#include "tracker-db-manager.h"
#ifdef OS_WIN32
#include <windows.h>
@@ -140,34 +141,6 @@
static gint verbosity;
static gint initial_sleep = -1;
-static gchar *
-get_lock_file ()
-{
- gchar *lock_file, *str;
-
- str = g_strconcat (g_get_user_name (), "_tracker_lock", NULL);
-
- /* check if setup for NFS usage (and enable atomic NFS safe locking) */
- if (tracker_config_get_nfs_locking (tracker->config)) {
-
- /* place lock file in tmp dir to allow multiple
- * sessions on NFS
- */
- lock_file = g_build_filename (tracker->sys_tmp_root_dir, str, NULL);
-
- } else {
- /* place lock file in home dir to prevent multiple
- * sessions on NFS (as standard locking might be
- * broken on NFS)
- */
- lock_file = g_build_filename (tracker->root_dir, str, NULL);
- }
-
- g_free (str);
- return lock_file;
-}
-
-
static GOptionEntry entries[] = {
{ "exclude-dir", 'e', 0,
G_OPTION_ARG_STRING_ARRAY, &no_watch_dirs,
@@ -220,11 +193,31 @@
{ NULL }
};
-gboolean
-tracker_die (void)
+static gchar *
+get_lock_file (void)
{
- tracker_error ("trackerd has failed to exit on time - terminating...");
- exit (EXIT_FAILURE);
+ gchar *lock_file, *str;
+
+ str = g_strconcat (g_get_user_name (), "_tracker_lock", NULL);
+
+ /* check if setup for NFS usage (and enable atomic NFS safe locking) */
+ if (tracker_config_get_nfs_locking (tracker->config)) {
+ /* Place lock file in tmp dir to allow multiple
+ * sessions on NFS
+ */
+ lock_file = g_build_filename (tracker->sys_tmp_root_dir, str, NULL);
+
+ } else {
+ /* Place lock file in home dir to prevent multiple
+ * sessions on NFS (as standard locking might be
+ * broken on NFS)
+ */
+ lock_file = g_build_filename (tracker->root_dir, str, NULL);
+ }
+
+ g_free (str);
+
+ return lock_file;
}
static void
@@ -333,10 +326,6 @@
tracker->word_detail_count = 0;
tracker->word_update_count = 0;
- tracker->file_word_table = g_hash_table_new (g_str_hash, g_str_equal);
- tracker->file_update_word_table = g_hash_table_new (g_str_hash, g_str_equal);
- tracker->email_word_table = g_hash_table_new (g_str_hash, g_str_equal);
-
if (!tracker_config_get_low_memory_mode (tracker->config)) {
tracker->memory_limit = 16000 *1024;
@@ -463,11 +452,10 @@
}
static void
-initialise_directories (void)
+initialise_locations (void)
{
gchar *str;
- gchar *filename;
-
+
str = g_strdup_printf ("Tracker-%s.%d", g_get_user_name (), getpid ());
tracker->sys_tmp_root_dir = g_build_filename (g_get_tmp_dir (), str, NULL);
g_free (str);
@@ -478,6 +466,17 @@
tracker->user_data_dir = g_build_filename (tracker->root_dir, "data", NULL);
tracker->xesam_dir = g_build_filename (g_get_home_dir (), ".xesam", NULL);
+ tracker->email_attachments_dir = g_build_filename (tracker->sys_tmp_root_dir, "Attachments", NULL);
+ tracker->log_filename = g_build_filename (tracker->root_dir, "tracker.log", NULL);
+}
+
+static void
+initialise_directories (gboolean *need_index)
+{
+ gchar *filename;
+
+ *need_index = FALSE;
+
/* Remove an existing one */
if (g_file_test (tracker->sys_tmp_root_dir, G_FILE_TEST_EXISTS)) {
tracker_dir_remove (tracker->sys_tmp_root_dir);
@@ -492,6 +491,12 @@
g_free (filename);
+ /* Remove database if we are reindexing */
+ if (reindex || tracker_db_needs_setup ()) {
+ tracker_dir_remove (tracker->data_dir);
+ *need_index = TRUE;
+ }
+
/* Create other directories we need */
if (!g_file_test (tracker->user_data_dir, G_FILE_TEST_EXISTS)) {
g_mkdir_with_parents (tracker->user_data_dir, 00755);
@@ -501,11 +506,9 @@
g_mkdir_with_parents (tracker->data_dir, 00755);
}
- tracker->email_attachements_dir = g_build_filename (tracker->sys_tmp_root_dir, "Attachments", NULL);
- g_mkdir_with_parents (tracker->email_attachements_dir, 00700);
+ g_mkdir_with_parents (tracker->email_attachments_dir, 00700);
/* Remove existing log files */
- tracker->log_filename = g_build_filename (tracker->root_dir, "tracker.log", NULL);
tracker_file_unlink (tracker->log_filename);
}
@@ -676,7 +679,7 @@
}
static void
-shutdown_threads (void)
+shutdown_threads (GThread *thread_to_join)
{
tracker_log ("Shutting down threads");
@@ -711,15 +714,33 @@
*/
g_mutex_unlock (tracker->metadata_check_mutex);
g_mutex_unlock (tracker->files_check_mutex);
-}
+ /* We wait now for the thread to exit and join, then clean up
+ * the mutexts and conds.
+ */
+ tracker_log ("Waiting for thread:%p to finish", thread_to_join);
+ g_thread_join (thread_to_join);
+
+ /* Clean up */
+#if 0
+ tracker_log ("Waiting for file check/signal mutexes to unlock before cleaning up...");
+ g_mutex_free (tracker->files_check_mutex);
+ g_mutex_free (tracker->files_signal_mutex);
+ g_cond_free (tracker->files_signal_cond);
+
+ tracker_log ("Waiting for metadata check/signal mutexes to unlock before cleaning up...");
+ g_mutex_free (tracker->metadata_check_mutex);
+ g_mutex_free (tracker->metadata_signal_mutex);
+ g_cond_free (tracker->metadata_signal_cond);
+#endif
+}
static gboolean
-check_multiple_instances ()
+check_multiple_instances (void)
{
- gint lfp;
- gboolean multiple = FALSE;
- gchar *lock_file;
+ gchar *lock_file;
+ gint lfp;
+ gboolean multiple = FALSE;
tracker_log ("Checking instances running");
@@ -729,13 +750,14 @@
if (lfp < 0) {
g_free (lock_file);
- g_error ("Cannot open or create lockfile %s - exiting", lock_file);
+ g_error ("Cannot open or create lockfile:'%s'", lock_file);
}
if (lockf (lfp, F_TLOCK, 0) < 0) {
g_warning ("Tracker daemon is already running - attempting to run in readonly mode");
multiple = TRUE;
}
+
g_free (lock_file);
return multiple;
@@ -777,6 +799,15 @@
if (tracker->sys_tmp_root_dir) {
tracker_dir_remove (tracker->sys_tmp_root_dir);
}
+
+ g_free (tracker->data_dir);
+ g_free (tracker->config_dir);
+ g_free (tracker->root_dir);
+ g_free (tracker->user_data_dir);
+ g_free (tracker->sys_tmp_root_dir);
+ g_free (tracker->email_attachments_dir);
+ g_free (tracker->xesam_dir);
+ g_free (tracker->log_filename);
}
gint
@@ -784,9 +815,10 @@
{
GOptionContext *context = NULL;
GError *error = NULL;
+ GThread *thread;
GSList *l;
gchar *example;
- gboolean need_index = FALSE;
+ gboolean need_index;
g_type_init ();
@@ -850,40 +882,34 @@
tracker->pid = getpid ();
tracker->dir_queue = g_async_queue_new ();
- /* Set up directories */
- initialise_directories ();
- umask (077);
+ /* This makes sure we have all the locations like the data
+ * dir, user data dir, etc all configured.
+ *
+ * The initialise_directories() function makes sure everything
+ * exists physically and/or is reset depending on various
+ * options (like if we reindex, we remove the data dir).
+ */
+ initialise_locations ();
- /* Set up the config */
+ /* Initialise major subsystems */
tracker->config = tracker_config_new ();
tracker->language = tracker_language_new (tracker->config);
- /* Set up the log */
tracker_log_init (tracker->log_filename,
tracker_config_get_verbosity (tracker->config),
fatal_errors);
- tracker_log ("Starting log");
-
- /* Set up locking */
tracker_nfs_lock_init (tracker->root_dir,
tracker_config_get_nfs_locking (tracker->config));
-
- /* Prepare db information */
tracker_db_manager_init (tracker->data_dir,
tracker->user_data_dir,
tracker->sys_tmp_root_dir);
-
- /* Set up xesam */
tracker_xesam_init ();
+ tracker_cache_init ();
+ tracker_service_manager_init ();
+ initialise_directories (&need_index);
initialise_threading ();
- if (reindex || tracker_db_needs_setup ()) {
- tracker_dir_remove (tracker->data_dir);
- g_mkdir_with_parents (tracker->data_dir, 00755);
- need_index = TRUE;
- }
-
umask (077);
tracker->readonly = check_multiple_instances ();
@@ -947,9 +973,6 @@
sanity_check_option_values ();
- /* Initialise the service manager */
- tracker_service_manager_init ();
-
/* Set thread safe DB connection */
tracker_db_thread_init ();
@@ -987,13 +1010,13 @@
tracker->is_running = FALSE;
tracker_error ("File monitoring failed to start");
} else {
- g_thread_create_full ((GThreadFunc) tracker_process_files,
- tracker,
- (gulong) tracker_config_get_thread_stack_size (tracker->config),
- FALSE,
- FALSE,
- G_THREAD_PRIORITY_NORMAL,
- NULL);
+ thread = g_thread_create_full ((GThreadFunc) tracker_process_files,
+ tracker,
+ (gulong) tracker_config_get_thread_stack_size (tracker->config),
+ TRUE,
+ FALSE,
+ G_THREAD_PRIORITY_NORMAL,
+ NULL);
}
}
@@ -1024,20 +1047,33 @@
/* Set kill timeout */
g_timeout_add_full (G_PRIORITY_LOW, 20000, shutdown_timeout_cb, NULL, NULL);
- shutdown_threads ();
+ tracker_cache_shutdown ();
+
+ shutdown_threads (thread);
shutdown_indexer ();
shutdown_databases ();
shutdown_directories ();
+ /* Clean up other struct members */
+ if (tracker->file_process_queue) {
+ g_async_queue_unref (tracker->file_process_queue);
+ }
+
+ if (tracker->file_metadata_queue) {
+ g_async_queue_unref (tracker->file_metadata_queue);
+ }
+
+ if (tracker->dir_queue) {
+ g_async_queue_unref (tracker->dir_queue);
+ }
+
/* Shutdown major subsystems */
if (tracker->hal) {
g_object_unref (tracker->hal);
tracker->hal = NULL;
}
- if (tracker->language) {
- tracker_language_free (tracker->language);
- }
+ tracker_language_free (tracker->language);
if (tracker->config) {
g_object_unref (tracker->config);
@@ -1048,8 +1084,6 @@
tracker_nfs_lock_term ();
tracker_log_term ();
- /* FIXME: we need to clean up Tracker struct members */
-
return EXIT_SUCCESS;
}
Modified: branches/indexer-split/src/trackerd/tracker-main.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-main.h (original)
+++ branches/indexer-split/src/trackerd/tracker-main.h Mon May 12 13:55:10 2008
@@ -73,7 +73,7 @@
gchar *root_dir;
gchar *user_data_dir;
gchar *sys_tmp_root_dir;
- gchar *email_attachements_dir;
+ gchar *email_attachments_dir;
gchar *xesam_dir;
gchar *log_filename;
@@ -130,11 +130,6 @@
/* Application run time values */
gint index_count;
- /* Cache words before saving to word index */
- GHashTable *file_word_table;
- GHashTable *file_update_word_table;
- GHashTable *email_word_table;
-
gint word_detail_count;
gint word_count;
gint word_update_count;
Modified: branches/indexer-split/src/trackerd/tracker-process-files.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-process-files.c (original)
+++ branches/indexer-split/src/trackerd/tracker-process-files.c Mon May 12 13:55:10 2008
@@ -1723,6 +1723,8 @@
g_mutex_unlock (tracker->files_signal_mutex);
+ tracker_log ("Process thread:%p now finishing", g_thread_self ());
+
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]