Squatter streamlining patch

Mark Derbyshire mark at taom.com
Thu Nov 7 23:35:34 EST 2002


I just finished migrating our mail server to Cyrus 2.1.9 and while the 
SQUAT feature is great, it takes a few hours for squatter to grind through 
the mailboxes. I thought a simple improvement would be to add a command 
line option (-s) to skip indexing mailboxes whose cyrus.squat file has a 
later modification date than the cyrus.index file (+ a little fudge in case 
the mailbox just got updated while squatter was indexing). This takes 6X 
less clock time when squatter is run on a daily basis, for our user 
culture. In case the patch is of use to anyone else, voila:

Cheers,
Mark

--- imap/squatter.c.orig	Tue Aug 13 10:46:33 2002
+++ imap/squatter.c	Thu Nov  7 18:52:41 2002
@@ -96,6 +96,8 @@
 #include "squat.h"
 #include "imapd.h"

+#define SKIP_FUZZ 60	/* non-critical time delta to increase likelihood of 
stable mailbox */
+
 extern char *optarg;
 extern int optind;

@@ -122,6 +124,7 @@

 static int verbose = 0;
 static int mailbox_count = 0;
+static int skip_unmodified = 0;
 static SquatStats total_stats;

 static void start_stats(SquatStats* stats) {
@@ -299,6 +302,7 @@
     int fd;
     SquatOptions options;
     struct stat index_file_info;
+    struct stat tmp_file_info;
     char uid_validity_buf[30];

     data.mailbox_stats = &stats;
@@ -325,15 +329,35 @@
         return 1;
     }

+    snprintf(index_file_name, sizeof(index_file_name),
+             "%s%s", m.path, FNAME_SQUAT_INDEX);
+    snprintf(tmp_file_name, sizeof(tmp_file_name),
+             "%s%s", m.path, FNAME_INDEX);
+
+    /* process only changed mailboxes if skip option delected */
+    if (skip_unmodified &&
+        !stat(tmp_file_name, &tmp_file_info) &&
+        !stat(index_file_name, &index_file_info)) {
+        if (SKIP_FUZZ +
+              tmp_file_info.st_mtimespec.tv_sec + 
tmp_file_info.st_mtimespec.tv_nsec * 1.e-9 <
+            index_file_info.st_mtimespec.tv_sec + 
index_file_info.st_mtimespec.tv_nsec * 1.e-9) {
+            syslog(LOG_INFO, "skipping mailbox %s", name);
+            if (verbose > 0) {
+                printf("Skipping mailbox %s\n", name);
+            }
+            mailbox_close(&m);
+            return 0;
+        }
+    }
+
+    snprintf(tmp_file_name, sizeof(tmp_file_name),
+             "%s%s.tmp", m.path, FNAME_SQUAT_INDEX);
+
     syslog(LOG_INFO, "indexing mailbox %s... ", name);
     if (verbose > 0) {
       printf("Indexing mailbox %s... ", name);
     }

-    snprintf(index_file_name, sizeof(index_file_name),
-             "%s%s", m.path, FNAME_SQUAT_INDEX);
-    snprintf(tmp_file_name, sizeof(tmp_file_name),
-             "%s%s.tmp", m.path, FNAME_SQUAT_INDEX);
     if ((fd = open(tmp_file_name, O_CREAT | O_TRUNC | O_WRONLY, S_IREAD | 
S_IWRITE))
         < 0) {
       fatal_syserror("Unable to create temporary index file");
@@ -413,7 +437,7 @@

     setbuf(stdout, NULL);

-    while ((opt = getopt(argc, argv, "C:rv")) != EOF) {
+    while ((opt = getopt(argc, argv, "C:rsv")) != EOF) {
 	switch (opt) {
 	case 'C': /* alt config file */
           alt_config = optarg;
@@ -427,6 +451,10 @@
 	  rflag = 1;
 	  break;

+        case 's': /* skip unmodifed */
+          skip_unmodified = 1;
+          break;
+
 	default:
 	    usage("squatter");
 	}





More information about the Info-cyrus mailing list