[dovecot-cvs] dovecot/src/lib-index mail-index-sync-private.h, 1.5, 1.6 mail-index-sync-update.c, 1.14, 1.15 mail-index-sync.c, 1.15, 1.16 mail-index-transaction.c, 1.5, 1.6 mail-index-view-sync.c, 1.8, 1.9 mail-index.h, 1.108, 1.109

cras at procontrol.fi cras at procontrol.fi
Sun May 23 00:30:44 EEST 2004


Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv4692/lib-index

Modified Files:
	mail-index-sync-private.h mail-index-sync-update.c 
	mail-index-sync.c mail-index-transaction.c 
	mail-index-view-sync.c mail-index.h 
Log Message:
Set dirty flags through transaction log, not directly. Some other flag
fixes etc.



Index: mail-index-sync-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-sync-private.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/mail-index-sync-private.h	22 May 2004 00:48:45 -0000	1.5
+++ b/mail-index-sync-private.h	22 May 2004 21:30:42 -0000	1.6
@@ -17,10 +17,9 @@
 	size_t expunge_idx, update_idx;
 	uint32_t next_uid;
 
-	unsigned int lock_id, dirty_lock_id;
+	unsigned int lock_id;
 
 	unsigned int sync_appends:1;
-	unsigned int have_dirty:1;
 };
 
 int mail_index_sync_update_index(struct mail_index_sync_ctx *sync_ctx,

Index: mail-index-sync-update.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- a/mail-index-sync-update.c	22 May 2004 00:48:45 -0000	1.14
+++ b/mail-index-sync-update.c	22 May 2004 21:30:42 -0000	1.15
@@ -13,6 +13,8 @@
 	struct mail_index_view *view;
 	struct mail_index_header hdr;
 	struct mail_transaction_log_view *log_view;
+
+	unsigned int have_dirty:1;
 };
 
 void mail_index_header_update_counts(struct mail_index_header *hdr,
@@ -75,6 +77,11 @@
 	if (seq1 == 0)
 		return;
 
+	if ((syncrec->add_flags & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0) {
+		ctx->hdr.flags |= MAIL_INDEX_HDR_FLAG_HAVE_DIRTY;
+		ctx->have_dirty = TRUE;
+	}
+
 	update_keywords = FALSE;
 	for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++) {
 		if (syncrec->add_keywords[i] != 0)
@@ -185,7 +192,7 @@
 	struct mail_index_sync_rec rec;
 	const struct mail_index_record *appends;
 	unsigned int append_count;
-	uint32_t count, file_seq, src_idx, dest_idx, dirty_flag;
+	uint32_t count, file_seq, src_idx, dest_idx, i;
 	uint32_t seq1, seq2;
 	uoff_t file_offset;
 	unsigned int lock_id;
@@ -204,12 +211,6 @@
 	ctx.hdr = *index->hdr;
 	ctx.log_view = sync_ctx->view->log_view;
 
-	dirty_flag = sync_ctx->have_dirty ? MAIL_INDEX_HDR_FLAG_HAVE_DIRTY : 0;
-	if ((ctx.hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != dirty_flag) {
-		ctx.hdr.flags ^= MAIL_INDEX_HDR_FLAG_HAVE_DIRTY;
-		changed = TRUE;
-	}
-
 	/* see if we need to update sync headers */
 	if (ctx.hdr.sync_stamp != sync_stamp && sync_stamp != 0) {
 		ctx.hdr.sync_stamp = sync_stamp;
@@ -301,6 +302,17 @@
 	ctx.hdr.log_file_seq = file_seq;
 	ctx.hdr.log_file_offset = file_offset;
 
+	if ((ctx.hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) &&
+	    !ctx.have_dirty) {
+		/* do we have dirty flags anymore? */
+		for (i = 0; i < map->records_count; i++) {
+			if (map->records[i].flags & MAIL_INDEX_MAIL_FLAG_DIRTY)
+				break;
+		}
+		if (i == map->records_count)
+			ctx.hdr.flags &= ~MAIL_INDEX_HDR_FLAG_HAVE_DIRTY;
+	}
+
 	if (!MAIL_INDEX_MAP_IS_IN_MEMORY(map)) {
 		map->mmap_used_size = index->hdr->header_size +
 			map->records_count * sizeof(struct mail_index_record);

Index: mail-index-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-sync.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- a/mail-index-sync.c	22 May 2004 00:48:45 -0000	1.15
+++ b/mail-index-sync.c	22 May 2004 21:30:42 -0000	1.16
@@ -25,7 +25,7 @@
 	dest = buffer_get_data(ctx->updates_buf, &dest_count);
 	dest_count /= sizeof(*dest);
 
-	for (i = 0; src != src_end; ) {
+	for (i = 0; src != src_end; src++) {
 		new_update = *src;
 
 		/* insert it into buffer, split it in multiple parts if needed
@@ -312,22 +312,6 @@
 		ctx->sync_appends;
 }
 
-int mail_index_sync_set_dirty(struct mail_index_sync_ctx *ctx, uint32_t seq)
-{
-	if (ctx->dirty_lock_id == 0) {
-		if (mail_index_lock_exclusive(ctx->index,
-					      &ctx->dirty_lock_id) < 0)
-			return -1;
-	}
-
-	/* FIXME: maybe this should go through transaction log anyway?
-	   doesn't work well with non-mmaped indexes.. */
-	i_assert(seq <= ctx->view->map->records_count);
-	ctx->view->map->records[seq-1].flags |= MAIL_INDEX_MAIL_FLAG_DIRTY;
-	ctx->have_dirty = TRUE;
-	return 0;
-}
-
 int mail_index_sync_end(struct mail_index_sync_ctx *ctx,
 			uint32_t sync_stamp, uint64_t sync_size)
 {
@@ -358,9 +342,6 @@
 			ret = -1;
 	}
 
-	if (ctx->dirty_lock_id == 0) 
-		mail_index_unlock(ctx->index, ctx->dirty_lock_id);
-
 	mail_index_unlock(ctx->index, ctx->lock_id);
 	mail_transaction_log_sync_unlock(ctx->index->log);
 	mail_index_view_close(ctx->view);

Index: mail-index-transaction.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-transaction.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/mail-index-transaction.c	22 May 2004 00:48:45 -0000	1.5
+++ b/mail-index-transaction.c	22 May 2004 21:30:42 -0000	1.6
@@ -359,7 +359,7 @@
 	if (idx < size && data[idx].uid2 < update.uid1)
 		idx++;
 
-	i_assert(idx == size || data[idx].uid1 < update.uid1);
+	i_assert(idx == size || data[idx].uid1 <= update.uid1);
 
 	/* insert it into buffer, split it in multiple parts if needed
 	   to make sure the ordering stays the same */
@@ -371,10 +371,12 @@
 		last = update.uid2;
 		update.uid2 = data[idx].uid1-1;
 
-		buffer_insert(t->updates, idx * sizeof(update),
-			      &update, sizeof(update));
-		data = buffer_get_modifyable_data(t->updates, NULL);
-		size++;
+		if (update.uid1 <= update.uid2) {
+			buffer_insert(t->updates, idx * sizeof(update),
+				      &update, sizeof(update));
+			data = buffer_get_modifyable_data(t->updates, NULL);
+			size++;
+		}
 
 		update.uid1 = update.uid2+1;
 		update.uid2 = last;

Index: mail-index-view-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-view-sync.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- a/mail-index-view-sync.c	22 May 2004 00:48:45 -0000	1.8
+++ b/mail-index-view-sync.c	22 May 2004 21:30:42 -0000	1.9
@@ -292,10 +292,16 @@
 	return 1;
 }
 
-static void
+#define FLAG_UPDATE_IS_INTERNAL(u, empty) \
+	(((u)->add_flags | (u)->remove_flags) == MAIL_INDEX_MAIL_FLAG_DIRTY && \
+	 memcmp((u)->add_keywords, empty, INDEX_KEYWORDS_BYTE_COUNT) == 0 && \
+	 memcmp((u)->add_keywords, empty, INDEX_KEYWORDS_BYTE_COUNT) == 0)
+
+static int
 mail_index_view_sync_get_rec(struct mail_index_view_sync_ctx *ctx,
 			     struct mail_index_sync_rec *rec)
 {
+	static keywords_mask_t empty_keywords = { 0, };
 	const struct mail_transaction_header *hdr = ctx->hdr;
 	const void *data = ctx->data;
 
@@ -318,13 +324,21 @@
 		const struct mail_transaction_flag_update *update =
 			CONST_PTR_OFFSET(data, ctx->data_offset);
 
-		ctx->data_offset += sizeof(*update);
+		for (;;) {
+			ctx->data_offset += sizeof(*update);
+			if (!FLAG_UPDATE_IS_INTERNAL(update, empty_keywords))
+				break;
+
+			if (ctx->data_offset == ctx->hdr->size)
+				return 0;
+		}
                 mail_index_sync_get_update(rec, update);
 		break;
 	}
 	default:
 		i_unreached();
 	}
+	return 1;
 }
 
 int mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
@@ -335,31 +349,34 @@
 	uoff_t offset;
 	int ret;
 
-	if (ctx->hdr == NULL || ctx->data_offset == ctx->hdr->size) {
-		ctx->data_offset = 0;
-		do {
-			ret = mail_index_view_sync_next_trans(ctx, &seq,
-							      &offset);
-			if (ret < 0)
-				return -1;
+	do {
+		if (ctx->hdr == NULL || ctx->data_offset == ctx->hdr->size) {
+			ctx->data_offset = 0;
+			do {
+				ret = mail_index_view_sync_next_trans(ctx, &seq,
+								      &offset);
+				if (ret < 0)
+					return -1;
 
-			if (ctx->last_read)
-				return 0;
+				if (ctx->last_read)
+					return 0;
 
-			if (!ctx->skipped) {
-				view->log_file_seq = seq;
-				view->log_file_offset = offset +
-					sizeof(*ctx->hdr) + ctx->hdr->size;
-			}
-		} while (ret == 0);
+				if (!ctx->skipped) {
+					view->log_file_seq = seq;
+					view->log_file_offset = offset +
+						sizeof(*ctx->hdr) +
+						ctx->hdr->size;
+				}
+			} while (ret == 0);
 
-		if (ctx->skipped) {
-			mail_index_view_add_synced_transaction(view, seq,
-							       offset);
+			if (ctx->skipped) {
+				mail_index_view_add_synced_transaction(view,
+								       seq,
+								       offset);
+			}
 		}
-	}
+	} while (!mail_index_view_sync_get_rec(ctx, sync_rec));
 
-	mail_index_view_sync_get_rec(ctx, sync_rec);
 	return 1;
 }
 

Index: mail-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- a/mail-index.h	22 May 2004 00:48:45 -0000	1.108
+++ b/mail-index.h	22 May 2004 21:30:42 -0000	1.109
@@ -196,10 +196,6 @@
 			 struct mail_index_sync_rec *sync_rec);
 /* Returns 1 if there's more to sync, 0 if not. */
 int mail_index_sync_have_more(struct mail_index_sync_ctx *ctx);
-/* Mark given message to be dirty, ie. we couldn't temporarily change the
-   message flags in storage. Dirty messages are tried to be synced again in
-   next sync. */
-int mail_index_sync_set_dirty(struct mail_index_sync_ctx *ctx, uint32_t seq);
 /* End synchronization by unlocking the index and closing the view.
    sync_stamp/sync_size in header is updated to given values. */
 int mail_index_sync_end(struct mail_index_sync_ctx *ctx,
@@ -207,8 +203,8 @@
 
 /* Mark index file corrupted. Invalidates all views. */
 void mail_index_mark_corrupted(struct mail_index *index);
-/* Check and fix any found problems. If index is broken beyond repair, calls
-   mail_index_reset() and returns 0. Otherwise returns -1 if there was some
+/* Check and fix any found problems. If index is broken beyond repair, it's
+   marked corrupted and 0 is returned. Otherwise returns -1 if there was some
    I/O error or 1 if everything went ok. */
 int mail_index_fsck(struct mail_index *index);
 



More information about the dovecot-cvs mailing list