[dovecot-cvs] dovecot/src/lib-index mail-transaction-log.c, 1.65, 1.66 mail-index-sync-update.c, 1.49, 1.50 mail-index-sync.c, 1.35, 1.36

cras at dovecot.org cras at dovecot.org
Sun Oct 17 19:40:00 EEST 2004


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

Modified Files:
	mail-transaction-log.c mail-index-sync-update.c 
	mail-index-sync.c 
Log Message:
Write transactions into index at the beginning of syncing if there's appends
or external changes.



Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- mail-transaction-log.c	14 Oct 2004 22:16:43 -0000	1.65
+++ mail-transaction-log.c	17 Oct 2004 16:39:58 -0000	1.66
@@ -922,55 +922,6 @@
 }
 
 static void
-mail_transaction_log_append_fix(struct mail_index_transaction *t,
-				const struct mail_transaction_header *hdr,
-				const void *data)
-{
-	const struct mail_index_record *old, *old_end;
-	struct mail_index_record *appends, *end, *rec, *dest;
-	size_t size;
-	int deleted = FALSE;
-
-	if (t->appends == NULL)
-		return;
-
-	appends = buffer_get_modifyable_data(t->appends, &size);
-	end = PTR_OFFSET(appends, size);
-
-	if (appends == end)
-		return;
-
-	/* we'll just check that none of the appends are already in
-	   transaction log. this could happen if we crashed before we had
-	   a chance to update index file */
-	old_end = CONST_PTR_OFFSET(data, hdr->size);
-	for (old = data; old != old_end; old++) {
-		/* appends are sorted */
-		for (rec = appends; rec != end; rec++) {
-			if (rec->uid >= old->uid) {
-				if (rec->uid == old->uid) {
-					rec->uid = 0;
-					deleted = TRUE;
-				}
-				break;
-			}
-		}
-	}
-
-	if (deleted) {
-		/* compress deleted appends away */
-		for (rec = dest = appends; rec != end; rec++) {
-			if (rec->uid != 0)
-				dest++;
-			else if (rec != dest)
-				*rec = *dest;
-		}
-		buffer_set_used_size(t->appends,
-				     (char *)dest - (char *)appends);
-	}
-}
-
-static void
 transaction_save_ext_intro(struct mail_index_transaction *t,
 			   const struct mail_transaction_ext_intro *intro)
 {
@@ -1019,9 +970,6 @@
 	while ((ret = mail_transaction_log_view_next(sync_view,
 						     &hdr, &data, NULL)) == 1) {
 		switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
-		case MAIL_TRANSACTION_APPEND:
-			mail_transaction_log_append_fix(t, hdr, data);
-			break;
 		case MAIL_TRANSACTION_CACHE_RESET: {
 			const struct mail_transaction_cache_reset *reset = data;
 

Index: mail-index-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- mail-index-sync-update.c	3 Oct 2004 16:32:59 -0000	1.49
+++ mail-index-sync-update.c	17 Oct 2004 16:39:58 -0000	1.50
@@ -786,6 +786,7 @@
 		buffer_append(map->hdr_copy_buf, map->hdr,
 			      map->hdr->header_size);
 		map->hdr = map->hdr_copy_buf->data;
+		index->hdr = map->hdr;
 	}
 
 	mail_index_unmap(index, view->map);
@@ -876,7 +877,9 @@
 			ret = -1;
 		}
 		map->hdr = map->mmap_base;
+		index->hdr = map->hdr;
 	}
+	i_assert(view->map == index->map);
 
         mail_index_view_unlock(view);
 	return ret;

Index: mail-index-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- mail-index-sync.c	11 Oct 2004 13:14:59 -0000	1.35
+++ mail-index-sync.c	17 Oct 2004 16:39:58 -0000	1.36
@@ -210,11 +210,14 @@
 }
 
 static int
-mail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx, int sync_recent)
+mail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx, int sync_recent,
+			      int *update_index_now_r)
 {
 	size_t size;
 	int ret;
 
+	*update_index_now_r = FALSE;
+
 	if ((ctx->view->map->hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) &&
 	    ctx->sync_dirty) {
 		/* show dirty flags as flag updates */
@@ -230,8 +233,21 @@
 	while ((ret = mail_transaction_log_view_next(ctx->view->log_view,
 						     &ctx->hdr,
 						     &ctx->data, NULL)) > 0) {
-		if ((ctx->hdr->type & MAIL_TRANSACTION_EXTERNAL) == 0)
+		if ((ctx->hdr->type & MAIL_TRANSACTION_EXTERNAL) != 0) {
+			/* last sync was written to transaction log,
+			   but it wasn't committed to index. do it now so
+			   the next sync won't do things wrong (especially
+			   duplicate appends). */
+			*update_index_now_r = TRUE;
+		} else if ((ctx->hdr->type & MAIL_TRANSACTION_TYPE_MASK) ==
+			   MAIL_TRANSACTION_APPEND) {
+			/* we appended new message, and now we're committing
+			   it into indexes. do it immediately so that we don't
+			   break if we have to sync the mailbox too */
+			*update_index_now_r = TRUE;
+		} else {
 			mail_index_sync_sort_transaction(ctx);
+		}
 	}
 
 	ctx->expunges = buffer_get_data(ctx->expunges_buf, &size);
@@ -268,6 +284,7 @@
 	uint32_t seq;
 	uoff_t offset;
 	unsigned int lock_id;
+	int update_now;
 
 	if (mail_transaction_log_sync_lock(index->log, &seq, &offset) < 0)
 		return -1;
@@ -311,11 +328,25 @@
 	   caller's mailbox access patterns */
 	ctx->expunges_buf = buffer_create_dynamic(default_pool, 1024);
 	ctx->updates_buf = buffer_create_dynamic(default_pool, 1024);
-	if (mail_index_sync_read_and_sort(ctx, sync_recent) < 0) {
+	if (mail_index_sync_read_and_sort(ctx, sync_recent, &update_now) < 0) {
                 mail_index_sync_rollback(ctx);
 		return -1;
 	}
 
+	if (update_now) {
+		if (mail_transaction_log_view_set(ctx->view->log_view,
+				index->hdr->log_file_seq,
+				index->hdr->log_file_offset,
+				seq, offset, MAIL_TRANSACTION_TYPE_MASK) < 0) {
+			mail_index_sync_rollback(ctx);
+			return -1;
+		}
+		if (mail_index_sync_update_index(ctx) < 0) {
+			mail_index_sync_rollback(ctx);
+			return -1;
+		}
+	}
+
 	*ctx_r = ctx;
 	*view_r = ctx->view;
 	return 1;



More information about the dovecot-cvs mailing list