changeset 4026:20c335412d7d HEAD

Added some locking related asserts, comments and when replacing index file, open it immediately into memory (seemed to work before too, though).
author Timo Sirainen <timo.sirainen@movial.fi>
date Sat, 18 Feb 2006 01:36:38 +0200
parents d4c02d132a32
children 0e7a9b0aa8c3
files src/lib-index/mail-index-lock.c src/lib-index/mail-index-sync-update.c src/lib-index/mail-index.c
diffstat 3 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-lock.c	Fri Feb 17 16:20:08 2006 +0200
+++ b/src/lib-index/mail-index-lock.c	Sat Feb 18 01:36:38 2006 +0200
@@ -153,10 +153,12 @@
 	}
 
 	if (update_index && index->excl_lock_count == 0) {
+		/* we wish to have the latest available index file. */
 		i_assert(index->lock_type != F_WRLCK);
 		if ((ret2 = mail_index_reopen_if_needed(index)) < 0)
 			return -1;
 		if (ret > 0 && ret2 == 0) {
+			/* no new file and the old file is already locked */
 			i_assert(lock_type == F_RDLCK);
 			i_assert(index->lock_type == F_RDLCK);
 			return 1;
@@ -164,8 +166,10 @@
 		ret = 0;
 	}
 
-	if (ret > 0)
+	if (ret > 0) {
+		/* file is already locked */
 		return 1;
+	}
 
 	if (index->lock_method == MAIL_INDEX_LOCK_DOTLOCK &&
 	    !MAIL_INDEX_IS_IN_MEMORY(index)) {
@@ -299,7 +303,6 @@
 
 	old_lock_type = index->lock_type;
 	index->lock_type = F_WRLCK;
-	index->excl_lock_count++;
 
 	if (mail_index_reopen(index, fd) < 0) {
 		i_assert(index->excl_lock_count == 1);
@@ -317,6 +320,7 @@
 		return -1;
 	}
 
+	index->excl_lock_count++;
 	return 0;
 }
 
@@ -419,10 +423,11 @@
 
 		if (!MAIL_INDEX_IS_IN_MEMORY(index)) {
 			fd = mail_index_copy(index);
-			if (fd == -1)
+			if (fd == -1 || mail_index_reopen(index, fd) < 0) {
+				if (fd != -1)
+					(void)close(fd);
 				mail_index_set_inconsistent(index);
-			else
-				(void)close(fd);
+			}
 		}
 	} else {
 		/* write the modified parts. header is small enough to be
--- a/src/lib-index/mail-index-sync-update.c	Fri Feb 17 16:20:08 2006 +0200
+++ b/src/lib-index/mail-index-sync-update.c	Sat Feb 18 01:36:38 2006 +0200
@@ -31,6 +31,8 @@
 		map->write_to_disk = TRUE;
 		map->write_atomic = TRUE;
 	}
+
+	i_assert(view->hdr.messages_count == map->hdr.messages_count);
 }
 
 static void
@@ -548,6 +550,8 @@
 
 	i_assert(ctx->view->map->records_count ==
 		 ctx->view->map->hdr.messages_count);
+	i_assert(ctx->view->hdr.messages_count ==
+		 ctx->view->map->hdr.messages_count);
 	return ret;
 }
 
@@ -629,6 +633,8 @@
 	view->map = map;
 	view->map->refcount++;
 
+	i_assert(view->hdr.messages_count == map->hdr.messages_count);
+
 	had_dirty = (map->hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0;
 	if (had_dirty)
 		map->hdr.flags &= ~MAIL_INDEX_HDR_FLAG_HAVE_DIRTY;
--- a/src/lib-index/mail-index.c	Fri Feb 17 16:20:08 2006 +0200
+++ b/src/lib-index/mail-index.c	Sat Feb 18 01:36:38 2006 +0200
@@ -1576,6 +1576,7 @@
 	int ret, old_fd, old_lock_type;
 
 	i_assert(!MAIL_INDEX_IS_IN_MEMORY(index));
+	i_assert(index->copy_lock_path == NULL || index->excl_lock_count == 0);
 
 	old_map = index->map;
 	old_fd = index->fd;
@@ -1643,6 +1644,8 @@
 {
 	struct stat st1, st2;
 
+        i_assert(index->copy_lock_path == NULL);
+
 	if (MAIL_INDEX_IS_IN_MEMORY(index))
 		return 0;