dovecot-1.2: Mail cache: If locking failed, the next time try to...

dovecot at dovecot.org dovecot at dovecot.org
Thu Sep 11 17:10:50 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/9902de77194e
changeset: 8190:9902de77194e
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Sep 11 17:10:46 2008 +0300
description:
Mail cache: If locking failed, the next time try to lock it only once.
Also increased the first timeout to 10 seconds.

diffstat:

2 files changed, 9 insertions(+), 1 deletion(-)
src/lib-index/mail-cache-private.h |    3 ++-
src/lib-index/mail-cache.c         |    7 +++++++

diffs (44 lines):

diff -r 7528e7256a1a -r 9902de77194e src/lib-index/mail-cache-private.h
--- a/src/lib-index/mail-cache-private.h	Thu Sep 11 17:06:29 2008 +0300
+++ b/src/lib-index/mail-cache-private.h	Thu Sep 11 17:10:46 2008 +0300
@@ -36,7 +36,7 @@
 /* When allocating space for transactions, don't use blocks larger than this. */
 #define MAIL_CACHE_MAX_RESERVED_BLOCK_SIZE (1024*512)
 
-#define MAIL_CACHE_LOCK_TIMEOUT 2
+#define MAIL_CACHE_LOCK_TIMEOUT 10
 #define MAIL_CACHE_LOCK_CHANGE_TIMEOUT 300
 
 #define CACHE_RECORD(cache, offset) \
@@ -171,6 +171,7 @@ struct mail_cache {
 
 	unsigned int opened:1;
 	unsigned int locked:1;
+	unsigned int last_lock_failed:1;
 	unsigned int hdr_modified:1;
 	unsigned int field_header_write_pending:1;
 	unsigned int compressing:1;
diff -r 7528e7256a1a -r 9902de77194e src/lib-index/mail-cache.c
--- a/src/lib-index/mail-cache.c	Thu Sep 11 17:06:29 2008 +0300
+++ b/src/lib-index/mail-cache.c	Thu Sep 11 17:10:46 2008 +0300
@@ -464,6 +464,12 @@ static int mail_cache_lock_file(struct m
 {
 	int ret;
 
+	if (cache->last_lock_failed) {
+		/* previous locking failed. don't waste time waiting on it
+		   again, just try once to see if it's available now. */
+		nonblock = TRUE;
+	}
+
 	if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
 		i_assert(cache->file_lock == NULL);
 		ret = mail_index_lock_fd(cache->index, cache->filepath,
@@ -483,6 +489,7 @@ static int mail_cache_lock_file(struct m
 						     "file_dotlock_create()");
 		}
 	}
+	cache->last_lock_failed = ret <= 0;
 
 	/* don't bother warning if locking failed due to a timeout. since cache
 	   updating isn't all that important we're using a very short timeout


More information about the dovecot-cvs mailing list