changeset 1016:d1caf5d0e77c HEAD

Modify log used to test if there were other users for every changed flag or expunged message, causing two fcntl() syscalls every time -> SLOW. Now we check it only once after exclusively locking the index.
author Timo Sirainen <tss@iki.fi>
date Wed, 22 Jan 2003 21:52:17 +0200
parents 40a327d356de
children a237bde6bd1e
files src/lib-index/mail-index.c src/lib-index/mail-index.h src/lib-index/mail-modifylog.c
diffstat 3 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Wed Jan 22 21:23:28 2003 +0200
+++ b/src/lib-index/mail-index.c	Wed Jan 22 21:52:17 2003 +0200
@@ -391,6 +391,7 @@
 		/* while holding exclusive lock, keep the FSCK flag on.
 		   when the lock is released, the FSCK flag will also be
 		   removed. */
+		index->excl_lock_counter++;
 		index->header->flags |= MAIL_INDEX_FLAG_FSCK;
 		if (!mail_index_fmdatasync(index,
 					   sizeof(struct mail_index_header))) {
@@ -421,6 +422,7 @@
 	}
 
 	if (index->lock_type == MAIL_LOCK_EXCLUSIVE) {
+		index->excl_lock_counter++;
 		if (index->modifylog != NULL)
 			mail_modifylog_notify_lock_drop(index->modifylog);
 
--- a/src/lib-index/mail-index.h	Wed Jan 22 21:23:28 2003 +0200
+++ b/src/lib-index/mail-index.h	Wed Jan 22 21:52:17 2003 +0200
@@ -362,6 +362,9 @@
 	unsigned int indexid;
 	unsigned int sync_id;
 
+        /* updated whenever exclusive lock is set/unset */
+	unsigned int excl_lock_counter;
+
 	int mbox_fd;
 	struct istream *mbox_stream;
 	enum mail_lock_type mbox_lock_type;
@@ -421,7 +424,7 @@
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
-	0
+	0, 0
 #endif
 
 /* defaults - same as above but prefixed with mail_index_. */
--- a/src/lib-index/mail-modifylog.c	Wed Jan 22 21:23:28 2003 +0200
+++ b/src/lib-index/mail-modifylog.c	Wed Jan 22 21:52:17 2003 +0200
@@ -60,6 +60,9 @@
 
 	struct modify_log_file file1, file2;
 	struct modify_log_file *head, *tail;
+
+	int cache_have_others;
+	unsigned int cache_lock_counter;
 };
 
 static const struct modify_log_expunge no_expunges = { 0, 0, 0 };
@@ -707,18 +710,34 @@
 	i_assert((*rec)->seq1 != 0);
 	i_assert((*rec)->uid1 != 0);
 
-	if (!external_change) {
+	if (!external_change &&
+	    file->log->cache_lock_counter !=
+	    file->log->index->excl_lock_counter) {
 		switch (modifylog_have_other_users(file->log, FALSE)) {
 		case 0:
 			/* we're the only one having this log open,
 			   no need for modify log. */
+			file->log->cache_have_others = FALSE;
+			file->log->cache_lock_counter =
+				file->log->index->excl_lock_counter;
+
 			*rec = NULL;
 			return TRUE;
 		case -1:
 			return FALSE;
+		default:
+			file->log->cache_have_others = TRUE;
+			file->log->cache_lock_counter =
+				file->log->index->excl_lock_counter;
+			break;
 		}
 	}
 
+	if (!file->log->cache_have_others) {
+		*rec = NULL;
+		return FALSE;
+	}
+
 	if (file->mmap_used_length == file->mmap_full_length) {
 		if (!mail_modifylog_grow(file))
 			return FALSE;