changeset 4977:a9babc1b3c65 HEAD

If there are transactions left while unlocking, don't unlock. Also added some next_uid debugging.
author Timo Sirainen <tss@iki.fi>
date Thu, 28 Dec 2006 22:54:59 +0200
parents 4d947423c82f
children 8d2efdb73816
files src/lib-index/mail-index-sync-update.c src/lib-index/mail-index-view.c
diffstat 2 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-sync-update.c	Thu Dec 28 22:52:32 2006 +0200
+++ b/src/lib-index/mail-index-sync-update.c	Thu Dec 28 22:54:59 2006 +0200
@@ -291,6 +291,7 @@
 	map->hdr.next_uid = rec->uid+1;
 	map->records_count++;
 	view->hdr.messages_count++;
+	view->hdr.next_uid = rec->uid+1;
 
 	write_seq_update(map, map->hdr.messages_count, map->hdr.messages_count);
 
--- a/src/lib-index/mail-index-view.c	Thu Dec 28 22:52:32 2006 +0200
+++ b/src/lib-index/mail-index-view.c	Thu Dec 28 22:54:59 2006 +0200
@@ -53,10 +53,26 @@
 	i_free(view);
 }
 
+#ifdef DEBUG
+static void mail_index_view_check_nextuid(struct mail_index_view *view)
+{
+	struct mail_index_record *rec;
+
+	if (view->hdr.messages_count == 0)
+		return;
+
+	rec = MAIL_INDEX_MAP_IDX(view->map, view->hdr.messages_count-1);
+	i_assert(rec->uid < view->hdr.next_uid);
+}
+#endif
+
 int mail_index_view_lock_head(struct mail_index_view *view, bool update_index)
 {
 	unsigned int lock_id;
 
+#ifdef DEBUG
+	mail_index_view_check_nextuid(view);
+#endif
 	if (MAIL_INDEX_MAP_IS_IN_MEMORY(view->index->map))
 		return 0;
 
@@ -95,6 +111,9 @@
 
 	if (view->map != view->index->map) {
 		/* not head mapping, no need to lock */
+#ifdef DEBUG
+		mail_index_view_check_nextuid(view);
+#endif
 		return 0;
 	}
 
@@ -103,7 +122,11 @@
 
 void mail_index_view_unlock(struct mail_index_view *view)
 {
-	if (view->lock_id != 0) {
+#ifdef DEBUG
+	mail_index_view_check_nextuid(view);
+#endif
+
+	if (view->lock_id != 0 && view->transactions == 0) {
 		mail_index_unlock(view->index, view->lock_id);
 		view->lock_id = 0;
 	}
@@ -461,6 +484,9 @@
 	if (--view->refcount > 0)
 		return;
 
+	i_assert(view->transactions == 0);
+
+	mail_index_view_unlock(view);
 	view->v.close(view);
 }