tracker r2168 - in branches/indexer-split: . src/libtracker-db src/tracker-indexer
- From: carlosg svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2168 - in branches/indexer-split: . src/libtracker-db src/tracker-indexer
- Date: Wed, 27 Aug 2008 15:35:23 +0000 (UTC)
Author: carlosg
Date: Wed Aug 27 15:35:23 2008
New Revision: 2168
URL: http://svn.gnome.org/viewvc/tracker?rev=2168&view=rev
Log:
2008-08-27 Carlos Garnacho <carlos imendio com>
* src/libtracker-db/tracker-db-index.c (tracker_db_index_flush):
Protect agains reentrancy, return the number of actually flushed
items. Also, fail when adding if the cache is being flushed.
* src/tracker-indexer/tracker-indexer.c
(tracker_indexer_set_state_flags) (tracker_indexer_unset_state_flags)
(tracker_indexer_get_state_flags): There are several reasons why the
indexer would want to stop, and not all of them are relevant outside
TrackerIndexer. This internal API will stop the indexer if any of the
relevant flags is set.
(tracker_indexer_[gs]et_running): Use internally the
TRACKER_INDEXER_STATE_PAUSED flag.
(check_disk_space_cb): Use internally the
TRACKER_INDEXER_STATE_DISK_FULL flag.
(flush_data): Set the TRACKER_INDEXER_STATE_FLUSHING flag when
flushing, so the indexing is temporarily stopped.
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/src/libtracker-db/tracker-db-index.c
branches/indexer-split/src/tracker-indexer/tracker-indexer.c
Modified: branches/indexer-split/src/libtracker-db/tracker-db-index.c
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-index.c (original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-index.c Wed Aug 27 15:35:23 2008
@@ -52,6 +52,7 @@
guint reload : 1;
guint readonly : 1;
guint in_pause : 1;
+ guint in_flush : 1;
/* From the indexer */
GHashTable *cache;
@@ -844,18 +845,24 @@
tracker_db_index_flush (TrackerDBIndex *index)
{
TrackerDBIndexPrivate *priv;
- guint size;
+ guint size, removed_items;
g_return_val_if_fail (TRACKER_IS_DB_INDEX (index), 0);
priv = TRACKER_DB_INDEX_GET_PRIVATE (index);
+ if (priv->in_flush) {
+ return;
+ }
+
if (!priv->index) {
g_debug ("Index was not open for flush, waiting...");
return 0;
}
+ priv->in_flush = TRUE;
size = g_hash_table_size (priv->cache);
+ removed_items = 0;
if (size > 0) {
GHashTableIter iter;
@@ -866,14 +873,18 @@
g_hash_table_iter_init (&iter, priv->cache);
while (g_hash_table_iter_next (&iter, &key, &value) && !priv->in_pause) {
- if (cache_flush_item (key, value, priv->index))
+ if (cache_flush_item (key, value, priv->index)) {
g_hash_table_iter_remove (&iter);
+ removed_items++;
+ }
+
g_main_context_iteration (NULL, FALSE);
}
}
+ priv->in_flush = FALSE;
- return size;
+ return removed_items;
}
guint32
@@ -1024,6 +1035,7 @@
priv = TRACKER_DB_INDEX_GET_PRIVATE (index);
+ g_return_if_fail (priv->in_flush == FALSE);
elem.id = service_id;
elem.amalgamated = tracker_db_index_item_calc_amalgamated (service_type, weight);
Modified: branches/indexer-split/src/tracker-indexer/tracker-indexer.c
==============================================================================
--- branches/indexer-split/src/tracker-indexer/tracker-indexer.c (original)
+++ branches/indexer-split/src/tracker-indexer/tracker-indexer.c Wed Aug 27 15:35:23 2008
@@ -95,6 +95,7 @@
typedef struct MetadataForeachData MetadataForeachData;
typedef struct MetadataRequest MetadataRequest;
typedef struct UpdateWordsForeachData UpdateWordsForeachData;
+typedef enum TrackerIndexerState TrackerIndexerState;
struct TrackerIndexerPrivate {
GQueue *dir_queue;
@@ -135,7 +136,7 @@
guint items_processed;
guint in_transaction : 1;
- guint is_paused : 1;
+ guint state : 3;
};
struct PathInfo {
@@ -157,6 +158,12 @@
guint32 service_type_id;
};
+enum TrackerIndexerState {
+ TRACKER_INDEXER_STATE_FLUSHING = 1 << 0,
+ TRACKER_INDEXER_STATE_PAUSED = 1 << 1,
+ TRACKER_INDEXER_STATE_DISK_FULL = 1 << 2
+};
+
enum {
PROP_0,
PROP_RUNNING,
@@ -176,6 +183,13 @@
static gboolean process_func (gpointer data);
static void check_disk_space_start (TrackerIndexer *indexer);
+static void tracker_indexer_set_state_flags (TrackerIndexer *indexer,
+ TrackerIndexerState state);
+static void tracker_indexer_unset_state_flags (TrackerIndexer *indexer,
+ TrackerIndexerState state);
+TrackerIndexerState tracker_indexer_get_state_flags (TrackerIndexer *indexer);
+
+
static guint signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (TrackerIndexer, tracker_indexer, G_TYPE_OBJECT)
@@ -285,6 +299,9 @@
{
indexer->private->flush_id = 0;
+ tracker_indexer_set_state_flags (indexer,
+ TRACKER_INDEXER_STATE_FLUSHING);
+
if (indexer->private->in_transaction) {
stop_transaction (indexer);
}
@@ -295,6 +312,9 @@
indexer->private->items_processed = 0;
+ tracker_indexer_unset_state_flags (indexer,
+ TRACKER_INDEXER_STATE_FLUSHING);
+
return FALSE;
}
@@ -311,7 +331,7 @@
schedule_flush (TrackerIndexer *indexer,
gboolean immediately)
{
- if (indexer->private->is_paused) {
+ if (tracker_indexer_get_state_flags (indexer) != 0) {
return;
}
@@ -460,7 +480,8 @@
switch (prop_id) {
case PROP_RUNNING:
- g_value_set_boolean (value, (priv->idle_id != 0));
+ g_value_set_boolean (value,
+ tracker_indexer_get_running (TRACKER_INDEXER (object)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -570,7 +591,7 @@
check_started (TrackerIndexer *indexer)
{
if (indexer->private->idle_id ||
- indexer->private->is_paused == TRUE) {
+ tracker_indexer_get_state_flags (indexer)) {
return;
}
@@ -589,9 +610,6 @@
gchar *str;
gdouble seconds_elapsed;
- /* Flush remaining items */
- schedule_flush (indexer, TRUE);
-
/* No more modules to query, we're done */
g_timer_stop (indexer->private->timer);
seconds_elapsed = g_timer_elapsed (indexer->private->timer, NULL);
@@ -602,6 +620,9 @@
indexer->private->idle_id = 0;
}
+ /* Flush remaining items */
+ schedule_flush (indexer, TRUE);
+
/* Print out how long it took us */
str = tracker_seconds_to_string (seconds_elapsed, FALSE);
@@ -652,12 +673,14 @@
disk_space_low = check_disk_space_low (indexer);
if (disk_space_low) {
- tracker_indexer_set_running (indexer, FALSE);
+ tracker_indexer_set_state_flags (indexer,
+ TRACKER_INDEXER_STATE_DISK_FULL);
/* The function above stops the low disk check, restart it */
check_disk_space_start (indexer);
} else {
- tracker_indexer_set_running (indexer, TRUE);
+ tracker_indexer_unset_state_flags (indexer,
+ TRACKER_INDEXER_STATE_DISK_FULL);
}
return TRUE;
@@ -670,10 +693,14 @@
gint low_disk_space_limit;
priv = indexer->private;
+
+ if (priv->disk_space_check_id != 0) {
+ return;
+ }
+
low_disk_space_limit = tracker_config_get_low_disk_space_limit (priv->config);
- if (low_disk_space_limit != -1 &&
- priv->disk_space_check_id == 0) {
+ if (low_disk_space_limit != -1) {
priv->disk_space_check_id = g_timeout_add_seconds (LOW_DISK_CHECK_FREQUENCY,
(GSourceFunc) check_disk_space_cb,
indexer);
@@ -1836,48 +1863,86 @@
gboolean
tracker_indexer_get_running (TrackerIndexer *indexer)
{
+ TrackerIndexerState state;
+
g_return_val_if_fail (TRACKER_IS_INDEXER (indexer), FALSE);
- return indexer->private->idle_id != 0;
+ state = tracker_indexer_get_state_flags (indexer);
+
+ return (state & TRACKER_INDEXER_STATE_PAUSED) == 0;
}
-void
-tracker_indexer_set_running (TrackerIndexer *indexer,
- gboolean running)
+static void
+tracker_indexer_check_state (TrackerIndexer *indexer)
{
- gboolean was_running;
-
- g_return_if_fail (TRACKER_IS_INDEXER (indexer));
+ TrackerIndexerState state;
- was_running = tracker_indexer_get_running (indexer);
+ state = indexer->private->state;
- if (running == was_running) {
- return;
- }
-
- if (!running) {
+ if ((state & TRACKER_INDEXER_STATE_FLUSHING) ||
+ (state & TRACKER_INDEXER_STATE_DISK_FULL) ||
+ (state & TRACKER_INDEXER_STATE_PAUSED)) {
check_disk_space_stop (indexer);
signal_status_timeout_stop (indexer);
stop_scheduled_flush (indexer);
stop_transaction (indexer);
- g_source_remove (indexer->private->idle_id);
- indexer->private->idle_id = 0;
- indexer->private->is_paused = TRUE;
-
- tracker_db_index_set_paused (indexer->private->file_index, TRUE);
- tracker_db_index_set_paused (indexer->private->email_index, TRUE);
- g_signal_emit (indexer, signals[PAUSED], 0);
+ if (indexer->private->idle_id) {
+ g_source_remove (indexer->private->idle_id);
+ indexer->private->idle_id = 0;
+ }
} else {
check_disk_space_start (indexer);
signal_status_timeout_start (indexer);
- indexer->private->is_paused = FALSE;
- indexer->private->idle_id = g_idle_add (process_func, indexer);
+ if (indexer->private->idle_id == 0) {
+ indexer->private->idle_id = g_idle_add (process_func, indexer);
+ }
+ }
+}
+
+static void
+tracker_indexer_set_state_flags (TrackerIndexer *indexer,
+ TrackerIndexerState state)
+{
+ indexer->private->state |= state;
+ tracker_indexer_check_state (indexer);
+}
+
+static void
+tracker_indexer_unset_state_flags (TrackerIndexer *indexer,
+ TrackerIndexerState state)
+{
+ indexer->private->state &= ~(state);
+ tracker_indexer_check_state (indexer);
+}
+
+TrackerIndexerState
+tracker_indexer_get_state_flags (TrackerIndexer *indexer)
+{
+ return indexer->private->state;
+}
+
+void
+tracker_indexer_set_running (TrackerIndexer *indexer,
+ gboolean running)
+{
+ TrackerIndexerState state;
+
+ state = tracker_indexer_get_state_flags (indexer);
+
+ if (running && (state & TRACKER_INDEXER_STATE_PAUSED)) {
+ tracker_indexer_unset_state_flags (indexer, TRACKER_INDEXER_STATE_PAUSED);
tracker_db_index_set_paused (indexer->private->file_index, FALSE);
tracker_db_index_set_paused (indexer->private->email_index, FALSE);
g_signal_emit (indexer, signals[CONTINUED], 0);
+ } else if (!running && !(state & TRACKER_INDEXER_STATE_PAUSED)) {
+ tracker_indexer_set_state_flags (indexer, TRACKER_INDEXER_STATE_PAUSED);
+
+ tracker_db_index_set_paused (indexer->private->file_index, TRUE);
+ tracker_db_index_set_paused (indexer->private->email_index, TRUE);
+ g_signal_emit (indexer, signals[PAUSED], 0);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]