[tracker] Fixed state machine so we return to previous state after PAUSED



commit 7d248cfb70c2796c3fc1d0166867a49924457083
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Jun 12 12:08:01 2009 +0200

    Fixed state machine so we return to previous state after PAUSED
    
    This bug was simulated by setting the LowDiskSpaceLimit in the config
    to 99 and then starting the daemon. Then setting it to 1 in real time
    should start sending files to the indexer, but instead it was returned
    to PENDING state which meant the queue handler returned and didn't do
    anything since it was expecting IDLE. IDLE was attempted but denied
    given pause conditions.

 src/trackerd/tracker-status.c |   67 +++++++++++++++++++++++++++--------------
 1 files changed, 44 insertions(+), 23 deletions(-)
---
diff --git a/src/trackerd/tracker-status.c b/src/trackerd/tracker-status.c
index 704c6bd..88f5db7 100644
--- a/src/trackerd/tracker-status.c
+++ b/src/trackerd/tracker-status.c
@@ -736,13 +736,29 @@ void
 tracker_status_set (TrackerStatus new_status)
 {
 	TrackerStatusPrivate *private;
+	gboolean should_be_paused;
+	gboolean invalid_new_state;
 
 	private = g_static_private_get (&private_key);
 	g_return_if_fail (private != NULL);
 
-	g_message ("State change from '%s' --> '%s'",
+
+	should_be_paused =
+		private->is_paused_manually ||
+		private->is_paused_for_batt ||
+		private->is_paused_for_io ||
+		private->is_paused_for_space ||
+		private->is_paused_for_dbus ||
+		private->is_paused_for_unknown;
+
+	invalid_new_state =
+		should_be_paused &&
+		new_status != TRACKER_STATUS_PAUSED;
+
+	g_message ("State change from '%s' --> '%s' %s",
 		   tracker_status_to_string (private->status),
-		   tracker_status_to_string (new_status));
+		   tracker_status_to_string (new_status),
+		   invalid_new_state ? "attempted with pause conditions, doing nothing" : "");
 
 	/* Don't set previous status to the same as we are now,
 	 * otherwise we could end up setting PAUSED and our old state
@@ -761,29 +777,34 @@ tracker_status_set (TrackerStatus new_status)
 
 	/* State machine */
 	if (private->status != new_status) {
-		/* If we are paused but have been moved OUT of state
-		 * by some call, we set back to the state BEFORE we
-		 * were PAUSED. We only do this for IDLE so far.
-		 *
-		 * The reason is in part explained above with states
-		 * A, B and C. If we return to IDLE because we were
-		 * PENDING/WATCHING previously we need to move back to
-		 * PAUSED here otherwise we risk actually processing
-		 * files with no disk space.
+		/* The reason we have this check, is that it is
+		 * possible that we are trying to set our state to
+		 * IDLE after finishing crawling but actually, we
+		 * should be in a PAUSED state due to another flag,
+		 * such as low disk space. So we force PAUSED state.
+		 * However, the interesting thing here is, we must
+		 * remember to set the OLD state so we go back to the
+		 * state as set by the caller. If we don't we end up
+		 * going back to PENDING/WATCHING instead of IDLE when
+		 * we come out of being PAUSED.
 		 *
-		 * NOTE: We correct the state here if we are paused
-		 * for some reason like being out of space and we
-		 * attempt to go into an IDLE state. 
+		 * FIXME: Should we ONLY cater for IDLE here? -mr
 		 */
-		if (new_status == TRACKER_STATUS_IDLE && 
-		    (private->is_paused_manually ||
-		     private->is_paused_for_batt || 
-		     private->is_paused_for_io ||
-		     private->is_paused_for_space ||
-		     private->is_paused_for_dbus ||
-		     private->is_paused_for_unknown)) {
-			g_message ("Attempt to set state to IDLE with pause conditions, changing...");
-			tracker_status_set (TRACKER_STATUS_PAUSED);
+
+		if (invalid_new_state) {
+			g_message ("Attempt to set state to '%s' with pause conditions, doing nothing",
+				   tracker_status_to_string (new_status));
+
+			if (private->status != TRACKER_STATUS_PAUSED) {
+				tracker_status_set (TRACKER_STATUS_PAUSED);
+			}
+
+			/* Set last state so we know what to return
+			 * to when we come out of PAUSED
+			 */
+
+			private->status_before_paused = new_status;
+
 			return;
 		}
 



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