Index: src/lib-index/mail-index-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-private.h,v
retrieving revision 1.29.2.1
diff -u -r1.29.2.1 mail-index-sync-private.h
--- src/lib-index/mail-index-sync-private.h	18 May 2006 10:08:55 -0000	1.29.2.1
+++ src/lib-index/mail-index-sync-private.h	28 May 2006 21:18:55 -0000
@@ -38,6 +38,7 @@
 
 struct mail_index_sync_map_ctx {
 	struct mail_index_view *view;
+	struct mail_transaction_log_view *log_view;
 	uint32_t cur_ext_id;
 
 	array_t ARRAY_DEFINE(expunge_handlers,
Index: src/lib-index/mail-index-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.96.2.2
diff -u -r1.96.2.2 mail-index-sync-update.c
--- src/lib-index/mail-index-sync-update.c	28 May 2006 21:18:27 -0000	1.96.2.2
+++ src/lib-index/mail-index-sync-update.c	28 May 2006 21:18:55 -0000
@@ -455,6 +455,16 @@
 {
 	int ret = 0;
 
+	{
+	uint32_t file_seq;
+	uoff_t file_offset;
+	mail_transaction_log_view_get_prev_pos(ctx->log_view,
+					       &file_seq, &file_offset);
+	i_debug("mail_index_sync_record: map=%p, file_seq=%u, "
+		"file_offset=%"PRIuUOFF_T,
+		ctx->view->map, file_seq, file_offset);
+	}
+
 	t_push();
 	switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
 	case MAIL_TRANSACTION_APPEND: {
@@ -611,6 +621,7 @@
 {
 	memset(sync_map_ctx, 0, sizeof(*sync_map_ctx));
 	sync_map_ctx->view = view;
+	sync_map_ctx->log_view = view->log_view;
 	sync_map_ctx->cur_ext_id = (uint32_t)-1;
 	sync_map_ctx->type = type;
 
@@ -658,6 +669,8 @@
 	int ret;
 	bool had_dirty, skipped, check_ext_offsets;
 
+	i_debug("mail_index_sync_update_index: map=%p begins", view->map);
+
 	mail_index_sync_map_init(&sync_map_ctx, view,
 				 MAIL_INDEX_SYNC_HANDLER_FILE);
 
@@ -770,6 +783,11 @@
 	map->hdr.log_file_seq = seq;
 	map->hdr.log_file_ext_offset = offset;
 
+	i_debug("mail_index_sync_update_index: map=%p, file_seq=%u, "
+		"int_offset=%u, ext_offset=%u",
+		map, seq, map->hdr.log_file_int_offset,
+		map->hdr.log_file_ext_offset);
+
 	if (first_append_uid != 0)
 		mail_index_update_day_headers(&map->hdr, first_append_uid);
 
Index: src/lib-index/mail-index-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync.c,v
retrieving revision 1.72.2.2
diff -u -r1.72.2.2 mail-index-sync.c
--- src/lib-index/mail-index-sync.c	28 May 2006 21:18:27 -0000	1.72.2.2
+++ src/lib-index/mail-index-sync.c	28 May 2006 21:18:55 -0000
@@ -752,6 +752,7 @@
 		mail_index_set_error(ctx->view->index,
 			"View synchronization from transaction log failed: %s",
 			error);
+		abort();
 	}
 	t_pop();
 	va_end(va);
Index: src/lib-index/mail-index-view-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view-sync.c,v
retrieving revision 1.52
diff -u -r1.52 mail-index-view-sync.c
--- src/lib-index/mail-index-view-sync.c	2 May 2006 22:06:32 -0000	1.52
+++ src/lib-index/mail-index-view-sync.c	28 May 2006 21:18:55 -0000
@@ -254,6 +254,9 @@
 		view->sync_new_map = view->index->map;
 		view->sync_new_map->refcount++;
 
+		i_debug("mail_index_view_sync_begin: map=%p, sync_new_map=%p",
+			view->map, view->sync_new_map);
+
 		/* since we're syncing everything, the counters get fixed */
 		view->broken_counters = FALSE;
 
@@ -269,6 +272,9 @@
 		   hadn't been any expunges. */
 		uint32_t old_records_count = view->map->records_count;
 
+		i_debug("mail_index_view_sync_begin: map=%p, cloning, head=%d",
+			view->map, view->sync_new_map,
+			view->map == view->index->map);
 		if (view->map != view->index->map) {
 			/* Using non-head mapping. We have to apply
 			   transactions to it to get latest changes into it. */
@@ -313,6 +319,11 @@
 	mail_index_view_unref_maps(view);
 	view->syncing = TRUE;
 
+	i_debug(" - view: file_seq=%u, file_offset=%"PRIuUOFF_T,
+		view->log_file_seq, view->log_file_offset);
+	i_debug(" - map: file_seq=%u, file_int_offset=%u, file_ext_offset=%u",
+		view->map->hdr.log_file_seq, view->map->hdr.log_file_int_offset,
+		view->map->hdr.log_file_ext_offset);
 	*ctx_r = ctx;
 	return 0;
 }
@@ -578,6 +589,11 @@
 	}
 	view->hdr = view->map->hdr;
 
+	i_debug("mail_index_view_sync_end: map=%p (idx_map=%p), file_seq=%u, "
+		"int_offset=%u, ext_offset=%u", view->map, view->index->map,
+		view->map->hdr.log_file_seq, view->map->hdr.log_file_int_offset,
+		view->map->hdr.log_file_ext_offset);
+
 	/* set log view to empty range so unneeded memory gets freed */
 	(void)mail_transaction_log_view_set(view->log_view,
 					    view->log_file_seq,
Index: src/lib-index/mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.230.2.3
diff -u -r1.230.2.3 mail-index.c
--- src/lib-index/mail-index.c	28 May 2006 21:18:27 -0000	1.230.2.3
+++ src/lib-index/mail-index.c	28 May 2006 21:18:55 -0000
@@ -582,6 +582,8 @@
 	if (--map->refcount > 0)
 		return;
 
+	i_debug("map_index_map: map=%p freed", map);
+
 	i_assert(map->refcount == 0);
 	mail_index_map_clear(index, map);
 	if (map->extension_pool != NULL)
@@ -603,6 +605,11 @@
 	} else {
 		map->hdr = *hdr;
 	}
+
+	i_debug("mail_index_map_copy_hdr: map=%p, file_seq=%u, "
+		"int_offset=%u, ext_offset=%u",
+		map, map->hdr.log_file_seq, map->hdr.log_file_int_offset,
+		map->hdr.log_file_ext_offset);
 }
 
 static int mail_index_mmap(struct mail_index *index, struct mail_index_map *map)
@@ -848,6 +855,10 @@
 		max_offset = (uoff_t)-1;
 	}
 
+	i_debug("mail_index_sync_from_transactions: map=%p, sync_to_index=%d, "
+		"file_seq=%u, file_offset=%u", *map, sync_to_index,
+		map_hdr->log_file_seq, map_hdr->log_file_int_offset);
+
 	log_view = mail_transaction_log_view_open(index->log);
 	if (mail_transaction_log_view_set(log_view,
 					  map_hdr->log_file_seq,
@@ -864,6 +875,7 @@
 	view = mail_index_view_open(index);
 	mail_index_sync_map_init(&sync_map_ctx, view,
 				 MAIL_INDEX_SYNC_HANDLER_HEAD);
+	sync_map_ctx.log_view = log_view;
 
 	check_ext_offsets = TRUE; broken = FALSE;
 	while ((ret = mail_transaction_log_view_next(log_view, &thdr, &tdata,
@@ -893,6 +905,9 @@
 	index->map->hdr.log_file_int_offset =
 		index->map->hdr.log_file_ext_offset = prev_offset;
 
+	i_debug("mail_index_sync_from_transactions: map=%p, file_seq=%u, "
+		"file_offset=%u", index->map, prev_seq, prev_offset);
+
 	mail_index_sync_map_deinit(&sync_map_ctx);
 	mail_index_view_close(&view);
 	mail_transaction_log_view_close(&log_view);
@@ -989,6 +1004,7 @@
 	used_size = hdr->header_size + hdr->messages_count * hdr->record_size;
 	if (map->mmap_size >= used_size && map->hdr_base == hdr) {
 		map->records_count = hdr->messages_count;
+		i_debug("mail_index_map_try_existing: map=%p succeeded", map);
 		mail_index_map_copy_hdr(map, hdr);
 		return 1;
 	}
@@ -1046,6 +1062,7 @@
 
 	if (map == NULL) {
 		map = i_new(struct mail_index_map, 1);
+		i_debug("map_index_map: map=%p created", map);
 		map->refcount = 1;
 		map->hdr_copy_buf =
 			buffer_create_dynamic(default_pool, sizeof(map->hdr));
@@ -1087,6 +1104,12 @@
 	index->hdr = &map->hdr;
 	index->map = map;
 	i_assert(map->hdr.messages_count == map->records_count);
+
+	i_debug("mail_index_map: map=%p, file_seq=%u, "
+		"int_offset=%u, ext_offset=%u",
+		map, map->hdr.log_file_seq, map->hdr.log_file_int_offset,
+		map->hdr.log_file_ext_offset);
+
 	index->mapping = FALSE;
 	return 1;
 }
@@ -1209,6 +1232,11 @@
 		}
 	}
 
+	i_debug("mail_index_map_clone: map=%p -> %p, file_seq=%u, "
+		"int_offset=%u, ext_offset=%u",
+		map, mem_map, map->hdr.log_file_seq,
+		map->hdr.log_file_int_offset, map->hdr.log_file_ext_offset);
+
 	return mem_map;
 }
 
@@ -1297,6 +1325,11 @@
 {
 	size_t hdr_size;
 
+	i_debug("mail_index_write_base_header: map=%p, file_seq=%u, "
+		"int_offset=%u, ext_offset=%u",
+		index->map, hdr->log_file_seq, hdr->log_file_int_offset,
+		hdr->log_file_ext_offset);
+
 	hdr_size = I_MIN(sizeof(*hdr), hdr->base_header_size);
 
 	if (!MAIL_INDEX_MAP_IS_IN_MEMORY(index->map)) {
