[tracker/no-mtime-checks-on-start: 3/4] tracker-miner-fs: Use CrawlingInterval config to force/disable/delay/check for mtime checking



commit 8bcd9632cb4ffa1105fc6ee5ef90401f8631501f
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Feb 1 14:28:13 2011 +0000

    tracker-miner-fs: Use CrawlingInterval config to force/disable/delay/check for mtime checking
    
    We do this to know if we can avoid full mtime checks on all
    directories against what we know in the database on start up or not.
    
    Fixes NB#218525, tracker-miner is too heavy to start

 src/miners/fs/tracker-config.c      |   12 ++++---
 src/miners/fs/tracker-main.c        |   63 +++++++++++++++++++++++++++++++---
 src/miners/fs/tracker-miner-files.c |   37 --------------------
 3 files changed, 64 insertions(+), 48 deletions(-)
---
diff --git a/src/miners/fs/tracker-config.c b/src/miners/fs/tracker-config.c
index 9a37304..2f86af0 100644
--- a/src/miners/fs/tracker-config.c
+++ b/src/miners/fs/tracker-config.c
@@ -49,7 +49,7 @@
 #define DEFAULT_INDEX_ON_BATTERY                 FALSE
 #define DEFAULT_INDEX_ON_BATTERY_FIRST_TIME      TRUE
 #define DEFAULT_LOW_DISK_SPACE_LIMIT             1        /* 0->100 / -1 */
-#define DEFAULT_CRAWLING_INTERVAL                0        /* 0->365 / -1 */
+#define DEFAULT_CRAWLING_INTERVAL                -1       /* 0->365 / -1 / -2 */
 #define DEFAULT_REMOVABLE_DAYS_THRESHOLD         3        /* 1->365 / 0  */
 
 typedef struct {
@@ -296,10 +296,12 @@ tracker_config_class_init (TrackerConfigClass *klass)
 	                                 PROP_CRAWLING_INTERVAL,
 	                                 g_param_spec_int ("crawling-interval",
 	                                                   "Crawling interval",
-	                                                   " Interval in days to check the filesystem is up to date in the database."
-	                                                   " If set to 0, crawling always occurs on startup, if -1 crawling is"
-	                                                   " disabled entirely. Maximum is 365.",
-	                                                   -1,
+	                                                   " Interval in days to check the filesystem is up to date in the database,"
+	                                                   " maximum is 365, default is -1.\n"
+	                                                   "   -2 = crawling is disabled entirely\n"
+	                                                   "   -1 = crawling *may* occur on startup (if not cleanly shutdown)\n"
+	                                                   "    0 = crawling is forced",
+	                                                   -2,
 	                                                   365,
 	                                                   DEFAULT_CRAWLING_INTERVAL,
 	                                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index 262489d..07ded14 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -188,19 +188,28 @@ initialize_priority (void)
 }
 
 static gboolean
-should_crawl (TrackerConfig *config)
+should_crawl (TrackerConfig *config,
+              gboolean      *forced)
 {
 	gint crawling_interval;
 
 	crawling_interval = tracker_config_get_crawling_interval (config);
 
-	g_message ("Checking whether to perform mtime checks during crawling:");
+	g_message ("Checking whether to crawl file system based on configured crawling interval:");
 
-	if (crawling_interval == -1) {
+	if (crawling_interval == -2) {
 		g_message ("  Disabled");
 		return FALSE;
+	} else if (crawling_interval == -1) {
+		g_message ("  Maybe (depends on a clean last shutdown)");
+		return TRUE;
 	} else if (crawling_interval == 0) {
-		g_message ("  Enabled");
+		g_message ("  Forced");
+
+		if (forced) {
+			*forced = TRUE;
+		}
+
 		return TRUE;
 	} else {
 		guint64 then, now;
@@ -533,6 +542,9 @@ main (gint argc, gchar *argv[])
 	GOptionContext *context;
 	GError *error = NULL;
 	gchar *log_filename = NULL;
+	gboolean do_mtime_checking;
+	gboolean do_crawling;
+	gboolean force_mtime_checking;
 
 	g_type_init ();
 
@@ -600,9 +612,39 @@ main (gint argc, gchar *argv[])
 
 	main_loop = g_main_loop_new (NULL, FALSE);
 
+	/* Check if we should crawl and if we should force mtime
+	 * checking based on the config.
+	 */
+	do_crawling = should_crawl (config, &force_mtime_checking);
+
+	/* Get the last shutdown state to see if we need to perform a
+	 * full mtime check against the db or not.
+	 *
+	 * Set to TRUE here in case we crash and miss file system
+	 * events.
+	 */
+	g_message ("Checking whether to force mtime checking during crawling (based on last clean shutdown):");
+
+	/* Override the shutdown state decision based on the config */
+	if (force_mtime_checking) {
+		do_mtime_checking = TRUE;
+	} else {
+		do_mtime_checking = tracker_db_manager_get_need_mtime_check ();
+	}
+
+	g_message ("  %s %s",
+	           do_mtime_checking ? "Yes" : "No",
+	           force_mtime_checking ? "(forced from config)" : "");
+
+	/* Set the need for an mtime check to TRUE so we check in the
+	 * event of a crash, this is changed back on shutdown if
+	 * everything appears to be fine.
+	 */
+	tracker_db_manager_set_need_mtime_check (TRUE);
+
 	miner_files = tracker_miner_files_new (config);
-	tracker_miner_fs_set_initial_crawling (TRACKER_MINER_FS (miner_files),
-	                                       should_crawl (config));
+	tracker_miner_fs_set_initial_crawling (TRACKER_MINER_FS (miner_files), do_crawling);
+	tracker_miner_fs_set_mtime_checking (TRACKER_MINER_FS (miner_files), do_mtime_checking);
 
 	g_signal_connect (miner_files, "finished",
 			  G_CALLBACK (miner_finished_cb),
@@ -637,6 +679,15 @@ main (gint argc, gchar *argv[])
 
 	g_message ("Shutdown started");
 
+	/* Reasons to not mark ourselves as cleanly shutdown include:
+	 *
+	 * 1. Still have files to process in our queues.
+	 * 2. We crash (out of our control usually anyway).
+	 */
+	if (!tracker_miner_fs_has_items_to_process (TRACKER_MINER_FS (miner_files))) {
+		tracker_db_manager_set_need_mtime_check (FALSE);
+	}
+
 	g_main_loop_unref (main_loop);
 	g_object_unref (config);
 
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 53ef349..9a260be 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -2627,42 +2627,6 @@ miner_files_ignore_next_update_file (TrackerMinerFS       *fs,
 	return TRUE;
 }
 
-static gboolean
-should_check_mtime (TrackerConfig *config)
-{
-	gint crawling_interval;
-
-	crawling_interval = tracker_config_get_crawling_interval (config);
-
-	g_message ("Checking whether to perform mtime checks during crawling:");
-
-	if (crawling_interval == -1) {
-		g_message ("  Disabled");
-		return FALSE;
-	} else if (crawling_interval == 0) {
-		g_message ("  Enabled");
-		return TRUE;
-	} else {
-		guint64 then, now;
-
-		then = tracker_db_manager_get_last_crawl_done ();
-		if (then < 1) {
-			g_message ("  No previous timestamp, crawling forced");
-			return TRUE;
-		}
-
-		now = (guint64) time (NULL);
-
-		if (now < then + (crawling_interval * SECONDS_PER_DAY)) {
-			g_message ("  Postponed");
-			return FALSE;
-		} else {
-			g_message ("Not occurred for %d days, crawling forced", crawling_interval);
-			return FALSE;
-		}
-	}
-}
-
 static void
 miner_files_finished (TrackerMinerFS *fs)
 {
@@ -2677,7 +2641,6 @@ tracker_miner_files_new (TrackerConfig *config)
 	                     "config", config,
 	                     "processing-pool-wait-limit", 10,
 	                     "processing-pool-ready-limit", 100,
-	                     "mtime-checking", should_check_mtime (config),
 	                     NULL);
 }
 



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