[dovecot-cvs] dovecot/src/lib-index mail-index-sync.c, 1.41, 1.42 mail-index.c, 1.167, 1.168

cras at dovecot.org cras at dovecot.org
Wed Nov 24 22:42:04 EET 2004


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv9490

Modified Files:
	mail-index-sync.c mail-index.c 
Log Message:
Avoid re-reading index file with mmap_disable=yes.



Index: mail-index-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- mail-index-sync.c	24 Nov 2004 17:31:53 -0000	1.41
+++ mail-index-sync.c	24 Nov 2004 20:42:02 -0000	1.42
@@ -290,6 +290,10 @@
 	return 0;
 }
 
+#define MAIL_INDEX_IS_SYNCS_SAME(index) \
+	((index)->sync_log_file_seq == (index)->hdr->log_file_seq && \
+	 (index)->sync_log_file_offset == (index)->hdr->log_file_ext_offset)
+
 int mail_index_sync_begin(struct mail_index *index,
                           struct mail_index_sync_ctx **ctx_r,
 			  struct mail_index_view **view_r,
@@ -299,36 +303,25 @@
 	struct mail_index_sync_ctx *ctx;
 	uint32_t seq;
 	uoff_t offset;
-	unsigned int lock_id;
+	unsigned int lock_id = 0;
 	int seen_external;
 
 	if (mail_transaction_log_sync_lock(index->log, &seq, &offset) < 0)
 		return -1;
 
-	if (mail_index_lock_shared(index, TRUE, &lock_id) < 0) {
-		mail_transaction_log_sync_unlock(index->log);
-		return -1;
-	}
-
-	if (index->mmap_disable) {
-		if (index->sync_log_file_seq != seq ||
-		    index->sync_log_file_offset != offset) {
-			/* we may have synced our internal view more than what
-			   is synced in index. re-read the whole index if our
-			   sync seq/offset doesn't match what is in index's
-			   header. */
-			if (mail_index_map(index, TRUE) <= 0) {
-				mail_transaction_log_sync_unlock(index->log);
-				mail_index_unlock(index, lock_id);
-				return -1;
-			}
-		} else {
-			/* the whole log file is synced already. */
-			i_assert(index->map->hdr.log_file_seq == seq);
-			i_assert(index->map->hdr.log_file_ext_offset == offset);
+	if (!index->mmap_disable || !MAIL_INDEX_IS_SYNCS_SAME(index) ||
+	    index->sync_log_file_seq != seq ||
+	    index->sync_log_file_offset != offset) {
+		/* make sure we have the latest file mapped */
+		if (mail_index_lock_shared(index, TRUE, &lock_id) < 0) {
+			mail_transaction_log_sync_unlock(index->log);
+			return -1;
 		}
-	} else {
-		if (mail_index_map(index, FALSE) <= 0) {
+
+		/* with mmap_disable the force parameter has somewhat special
+		   meaning, it syncs exactly to the log seq/offset in index
+		   file's header. */
+		if (mail_index_map(index, index->mmap_disable) <= 0) {
 			mail_transaction_log_sync_unlock(index->log);
 			mail_index_unlock(index, lock_id);
 			return -1;

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.167
retrieving revision 1.168
diff -u -d -r1.167 -r1.168
--- mail-index.c	14 Nov 2004 01:23:21 -0000	1.167
+++ mail-index.c	24 Nov 2004 20:42:02 -0000	1.168
@@ -696,6 +696,8 @@
 	struct mail_index_map *map;
 	int ret;
 
+	i_assert(index->lock_type != F_UNLCK);
+
 	if (!force && index->map != NULL) {
 		ret = mail_index_map_try_existing(index->map);
 		if (ret != 0)
@@ -972,6 +974,8 @@
 	uoff_t offset;
 	int ret;
 
+	i_assert(index->lock_type == F_UNLCK);
+
 	/* log file lock protects index creation */
 	if (mail_transaction_log_sync_lock(index->log, &seq, &offset) < 0)
 		return -1;
@@ -990,7 +994,9 @@
 		mail_index_file_set_syscall_error(index, path, "write_full()");
 		ret = -1;
 	} else {
+		index->lock_type = F_WRLCK;
 		ret = mail_index_map(index, FALSE);
+		index->lock_type = F_UNLCK;
 	}
 
 	if (ret == 0) {
@@ -1118,6 +1124,11 @@
 			(flags & MAIL_INDEX_OPEN_FLAG_MMAP_NO_WRITE) != 0;
 		index->lock_method = lock_method;
 
+		/* don't even bother to handle dotlocking without mmap being
+		   disabled. that combination simply doesn't make any sense */
+		i_assert(lock_method != MAIL_INDEX_LOCK_DOTLOCK ||
+			 index->mmap_disable);
+
 		ret = mail_index_open_files(index, flags);
 		if (ret <= 0)
 			break;
@@ -1183,9 +1194,7 @@
 
 	old_map = index->map;
 	old_fd = index->fd;
-
-	index->map = NULL;
-	index->hdr = NULL;
+	old_map->refcount++;
 
 	/* new file, new locks. the old fd can keep it's locks, they don't
 	   matter anymore as no-one's going to modify the file. */
@@ -1213,7 +1222,10 @@
 	}
 
 	if (ret == 0) {
-		if (mail_index_map(index, FALSE) <= 0)
+		/* read the new mapping. note that with mmap_disable we want
+		   to keep the old mapping in index->map so we can update it
+		   by reading transaction log. */
+		if (mail_index_map(index, TRUE) <= 0)
 			ret = -1;
 	}
 



More information about the dovecot-cvs mailing list