dovecot: Recent flag handling rewrite. Still not perfect with ma...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 16 09:48:08 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/d911d943438e
changeset: 6037:d911d943438e
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jul 16 09:48:02 2007 +0300
description:
Recent flag handling rewrite. Still not perfect with maildir.

diffstat:

31 files changed, 343 insertions(+), 407 deletions(-)
src/lib-index/mail-index-fsck.c                    |   16 -
src/lib-index/mail-index-map.c                     |    7 
src/lib-index/mail-index-sync-update.c             |   32 ---
src/lib-index/mail-index-sync.c                    |   47 +----
src/lib-index/mail-index-transaction-private.h     |    1 
src/lib-index/mail-index-transaction-view.c        |   19 --
src/lib-index/mail-index-transaction.c             |   34 +++
src/lib-index/mail-index-view-sync.c               |    2 
src/lib-index/mail-index-view.c                    |    2 
src/lib-index/mail-index.h                         |    6 
src/lib-mail/mail-types.h                          |    3 
src/lib-storage/index/cydir/cydir-save.c           |    2 
src/lib-storage/index/cydir/cydir-sync.c           |   11 +
src/lib-storage/index/dbox/dbox-save.c             |    2 
src/lib-storage/index/dbox/dbox-sync.c             |   21 --
src/lib-storage/index/index-mail.c                 |    4 
src/lib-storage/index/index-status.c               |    2 
src/lib-storage/index/index-storage.c              |    4 
src/lib-storage/index/index-storage.h              |   18 --
src/lib-storage/index/index-sync.c                 |  174 ++++++--------------
src/lib-storage/index/maildir/maildir-save.c       |    6 
src/lib-storage/index/maildir/maildir-storage.c    |    8 
src/lib-storage/index/maildir/maildir-sync-index.c |   91 ++++++----
src/lib-storage/index/maildir/maildir-sync.c       |   32 ++-
src/lib-storage/index/maildir/maildir-uidlist.c    |   72 --------
src/lib-storage/index/maildir/maildir-uidlist.h    |    4 
src/lib-storage/index/mbox/mbox-sync-private.h     |    1 
src/lib-storage/index/mbox/mbox-sync.c             |  105 ++++++++----
src/lib/seq-range-array.c                          |   19 +-
src/lib/seq-range-array.h                          |    2 
src/util/idxview.c                                 |    3 

diffs (truncated from 1516 to 300 lines):

diff -r 5d3a941444f1 -r d911d943438e src/lib-index/mail-index-fsck.c
--- a/src/lib-index/mail-index-fsck.c	Mon Jul 16 07:52:50 2007 +0300
+++ b/src/lib-index/mail-index-fsck.c	Mon Jul 16 09:48:02 2007 +0300
@@ -72,11 +72,9 @@ mail_index_fsck_map(struct mail_index *i
 	hdr.log_file_seq = file_seq;
 
 	hdr.messages_count = 0;
-	hdr.recent_messages_count = 0;
 	hdr.seen_messages_count = 0;
 	hdr.deleted_messages_count = 0;
 
-	hdr.first_recent_uid_lowwater = 0;
 	hdr.first_unseen_uid_lowwater = 0;
 	hdr.first_deleted_uid_lowwater = 0;
 
@@ -88,16 +86,11 @@ mail_index_fsck_map(struct mail_index *i
 		}
 
 		hdr.messages_count++;
-		if ((rec->flags & MAIL_RECENT) != 0)
-			hdr.recent_messages_count++;
 		if ((rec->flags & MAIL_SEEN) != 0)
 			hdr.seen_messages_count++;
 		if ((rec->flags & MAIL_DELETED) != 0)
 			hdr.deleted_messages_count++;
 
-		if ((rec->flags & MAIL_RECENT) != 0 &&
-		    hdr.first_recent_uid_lowwater == 0)
-			hdr.first_recent_uid_lowwater = rec->uid;
 		if ((rec->flags & MAIL_SEEN) == 0 &&
 		    hdr.first_unseen_uid_lowwater == 0)
 			hdr.first_unseen_uid_lowwater = rec->uid;
@@ -115,12 +108,14 @@ mail_index_fsck_map(struct mail_index *i
 		hdr.next_uid = last_uid+1;
 	}
 
-	if (hdr.first_recent_uid_lowwater == 0)
-                hdr.first_recent_uid_lowwater = hdr.next_uid;
 	if (hdr.first_unseen_uid_lowwater == 0)
                 hdr.first_unseen_uid_lowwater = hdr.next_uid;
 	if (hdr.first_deleted_uid_lowwater == 0)
                 hdr.first_deleted_uid_lowwater = hdr.next_uid;
+	if (hdr.first_recent_uid > hdr.next_uid)
+		hdr.first_recent_uid = hdr.next_uid;
+	if (hdr.first_recent_uid == 0)
+		hdr.first_recent_uid = 1;
 
         CHECK(log_file_seq, !=);
         CHECK(log_file_head_offset, !=);
@@ -128,13 +123,12 @@ mail_index_fsck_map(struct mail_index *i
 
 	CHECK(uid_validity, !=);
         CHECK(messages_count, !=);
-        CHECK(recent_messages_count, !=);
         CHECK(seen_messages_count, !=);
         CHECK(deleted_messages_count, !=);
 
-        CHECK(first_recent_uid_lowwater, <);
         CHECK(first_unseen_uid_lowwater, <);
 	CHECK(first_deleted_uid_lowwater, <);
+	CHECK(first_recent_uid, !=);
 
 	map->hdr = hdr;
 	return 1;
diff -r 5d3a941444f1 -r d911d943438e src/lib-index/mail-index-map.c
--- a/src/lib-index/mail-index-map.c	Mon Jul 16 07:52:50 2007 +0300
+++ b/src/lib-index/mail-index-map.c	Mon Jul 16 09:48:02 2007 +0300
@@ -301,11 +301,11 @@ static int mail_index_check_header(struc
 	if (hdr->next_uid == 0)
 		return 0;
 
-	if (hdr->recent_messages_count > hdr->messages_count ||
-	    hdr->seen_messages_count > hdr->messages_count ||
+	if (hdr->seen_messages_count > hdr->messages_count ||
 	    hdr->deleted_messages_count > hdr->messages_count)
 		return 0;
-	if (hdr->first_recent_uid_lowwater > hdr->next_uid ||
+	if (hdr->first_recent_uid == 0 ||
+	    hdr->first_recent_uid > hdr->next_uid ||
 	    hdr->first_unseen_uid_lowwater > hdr->next_uid ||
 	    hdr->first_deleted_uid_lowwater > hdr->next_uid)
 		return 0;
@@ -638,6 +638,7 @@ static void mail_index_header_init(struc
 	hdr->indexid = index->indexid;
 	hdr->log_file_seq = 1;
 	hdr->next_uid = 1;
+	hdr->first_recent_uid = 1;
 }
 
 struct mail_index_map *mail_index_map_alloc(struct mail_index *index)
diff -r 5d3a941444f1 -r d911d943438e src/lib-index/mail-index-sync-update.c
--- a/src/lib-index/mail-index-sync-update.c	Mon Jul 16 07:52:50 2007 +0300
+++ b/src/lib-index/mail-index-sync-update.c	Mon Jul 16 09:48:02 2007 +0300
@@ -93,26 +93,6 @@ mail_index_header_update_counts(struct m
 				uint8_t old_flags, uint8_t new_flags,
 				const char **error_r)
 {
-	if (((old_flags ^ new_flags) & MAIL_RECENT) != 0) {
-		/* different recent-flag */
-		if ((old_flags & MAIL_RECENT) == 0) {
-			hdr->recent_messages_count++;
-			if (hdr->recent_messages_count > hdr->messages_count) {
-				*error_r = "Recent counter wrong";
-				return -1;
-			}
-		} else {
-			if (hdr->recent_messages_count == 0 ||
-			    hdr->recent_messages_count > hdr->messages_count) {
-				*error_r = "Recent counter wrong";
-				return -1;
-			}
-
-			if (--hdr->recent_messages_count == 0)
-				hdr->first_recent_uid_lowwater = hdr->next_uid;
-		}
-	}
-
 	if (((old_flags ^ new_flags) & MAIL_SEEN) != 0) {
 		/* different seen-flag */
 		if ((old_flags & MAIL_SEEN) != 0) {
@@ -169,9 +149,6 @@ mail_index_header_update_lowwaters(struc
 mail_index_header_update_lowwaters(struct mail_index_header *hdr,
 				   const struct mail_index_record *rec)
 {
-	if ((rec->flags & MAIL_RECENT) != 0 &&
-	    rec->uid < hdr->first_recent_uid_lowwater)
-		hdr->first_recent_uid_lowwater = rec->uid;
 	if ((rec->flags & MAIL_SEEN) == 0 &&
 	    rec->uid < hdr->first_unseen_uid_lowwater)
 		hdr->first_unseen_uid_lowwater = rec->uid;
@@ -335,7 +312,7 @@ static int sync_flag_update(const struct
         flag_mask = ~u->remove_flags;
 
 	if (((u->add_flags | u->remove_flags) &
-	     (MAIL_SEEN | MAIL_DELETED | MAIL_RECENT)) == 0) {
+	     (MAIL_SEEN | MAIL_DELETED)) == 0) {
 		/* we're not modifying any counted/lowwatered flags */
 		for (idx = seq1-1; idx < seq2; idx++) {
 			rec = MAIL_INDEX_MAP_IDX(view->map, idx);
@@ -626,7 +603,7 @@ void mail_index_map_check(struct mail_in
 void mail_index_map_check(struct mail_index_map *map)
 {
 	const struct mail_index_header *hdr = &map->hdr;
-	unsigned int i, del = 0, recent = 0, seen = 0;
+	unsigned int i, del = 0, seen = 0;
 
 	i_assert(hdr->messages_count == map->records_count);
 	for (i = 0; i < map->records_count; i++) {
@@ -637,10 +614,6 @@ void mail_index_map_check(struct mail_in
 		if (rec->flags & MAIL_DELETED) {
 			i_assert(rec->uid >= hdr->first_deleted_uid_lowwater);
 			del++;
-		}
-		if (rec->flags & MAIL_RECENT) {
-			i_assert(rec->uid >= hdr->first_recent_uid_lowwater);
-			recent++;
 		}
 		if (rec->flags & MAIL_SEEN)
 			seen++;
@@ -648,7 +621,6 @@ void mail_index_map_check(struct mail_in
 			i_assert(rec->uid >= hdr->first_unseen_uid_lowwater);
 	}
 	i_assert(del == hdr->deleted_messages_count);
-	i_assert(recent == hdr->recent_messages_count);
 	i_assert(seen == hdr->seen_messages_count);
 }
 #endif
diff -r 5d3a941444f1 -r d911d943438e src/lib-index/mail-index-sync.c
--- a/src/lib-index/mail-index-sync.c	Mon Jul 16 07:52:50 2007 +0300
+++ b/src/lib-index/mail-index-sync.c	Mon Jul 16 09:48:02 2007 +0300
@@ -15,6 +15,7 @@ struct mail_index_sync_ctx {
 	struct mail_index *index;
 	struct mail_index_view *view;
 	struct mail_index_transaction *sync_trans, *ext_trans;
+	enum mail_index_sync_flags flags;
 
 	const struct mail_transaction_header *hdr;
 	const void *data;
@@ -170,27 +171,6 @@ static int mail_index_sync_add_dirty_upd
 	return 0;
 }
 
-static int mail_index_sync_add_recent_updates(struct mail_index_sync_ctx *ctx)
-{
-	const struct mail_index_record *rec;
-	uint32_t seq, messages_count;
-	bool seen_recent = FALSE;
-
-	messages_count = mail_index_view_get_messages_count(ctx->view);
-	for (seq = 1; seq <= messages_count; seq++) {
-		if (mail_index_lookup(ctx->view, seq, &rec) < 0)
-			return -1;
-
-		if ((rec->flags & MAIL_RECENT) != 0) {
-			seen_recent = TRUE;
-			mail_index_update_flags(ctx->sync_trans, rec->uid,
-						MODIFY_REMOVE, MAIL_RECENT);
-		}
-	}
-
-	return 0;
-}
-
 static void
 mail_index_sync_update_mailbox_pos(struct mail_index_sync_ctx *ctx)
 {
@@ -205,8 +185,7 @@ mail_index_sync_update_mailbox_pos(struc
 }
 
 static int
-mail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx,
-			      enum mail_index_sync_flags flags)
+mail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx)
 {
 	struct mail_index_transaction *sync_trans = ctx->sync_trans;
 	struct mail_index_sync_list *synclist;
@@ -215,14 +194,9 @@ mail_index_sync_read_and_sort(struct mai
 	int ret;
 
 	if ((ctx->view->map->hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) &&
-	    (flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0) {
+	    (ctx->flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0) {
 		/* show dirty flags as flag updates */
 		if (mail_index_sync_add_dirty_updates(ctx) < 0)
-			return -1;
-	}
-
-	if ((flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0) {
-		if (mail_index_sync_add_recent_updates(ctx) < 0)
 			return -1;
 	}
 
@@ -287,7 +261,7 @@ mail_index_need_sync(struct mail_index *
 		     enum mail_index_sync_flags flags,
 		     uint32_t log_file_seq, uoff_t log_file_offset)
 {
-	if (hdr->recent_messages_count > 0 &&
+	if (hdr->first_recent_uid < hdr->next_uid &&
 	    (flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0)
 		return TRUE;
 
@@ -385,6 +359,7 @@ int mail_index_sync_begin(struct mail_in
 	ctx->index = index;
 	ctx->last_tail_seq = hdr->log_file_seq;
 	ctx->last_tail_offset = hdr->log_file_tail_offset;
+	ctx->flags = flags;
 
 	ctx->view = mail_index_view_open(index);
 
@@ -410,7 +385,7 @@ int mail_index_sync_begin(struct mail_in
 
 	/* we need to have all the transactions sorted to optimize
 	   caller's mailbox access patterns */
-	if (mail_index_sync_read_and_sort(ctx, flags) < 0) {
+	if (mail_index_sync_read_and_sort(ctx) < 0) {
                 mail_index_sync_rollback(&ctx);
 		return -1;
 	}
@@ -599,7 +574,7 @@ int mail_index_sync_commit(struct mail_i
 {
         struct mail_index_sync_ctx *ctx = *_ctx;
 	struct mail_index *index = ctx->index;
-	uint32_t seq, diff;
+	uint32_t seq, diff, next_uid;
 	uoff_t offset;
 	bool want_rotate;
 	int ret = 0;
@@ -610,6 +585,14 @@ int mail_index_sync_commit(struct mail_i
 		   the cache offsets are updated only if the compression was
 		   successful. */
 		(void)mail_cache_compress(index->cache, ctx->ext_trans);
+	}
+
+	next_uid = mail_index_transaction_get_next_uid(ctx->ext_trans);
+	if ((ctx->flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0 &&
+	    index->map->hdr.first_recent_uid < next_uid) {
+		mail_index_update_header(ctx->ext_trans,
+			offsetof(struct mail_index_header, first_recent_uid),
+			&next_uid, sizeof(next_uid), FALSE);
 	}
 
 	if (mail_index_transaction_commit(&ctx->ext_trans, &seq, &offset) < 0) {
diff -r 5d3a941444f1 -r d911d943438e src/lib-index/mail-index-transaction-private.h
--- a/src/lib-index/mail-index-transaction-private.h	Mon Jul 16 07:52:50 2007 +0300
+++ b/src/lib-index/mail-index-transaction-private.h	Mon Jul 16 09:48:02 2007 +0300
@@ -89,6 +89,7 @@ void mail_index_transaction_unref(struct
 void mail_index_transaction_unref(struct mail_index_transaction **t);
 
 void mail_index_transaction_sort_appends(struct mail_index_transaction *t);
+uint32_t mail_index_transaction_get_next_uid(struct mail_index_transaction *t);
 
 bool mail_index_seq_array_lookup(const ARRAY_TYPE(seq_array) *array,
 				 uint32_t seq, unsigned int *idx_r);
diff -r 5d3a941444f1 -r d911d943438e src/lib-index/mail-index-transaction-view.c
--- a/src/lib-index/mail-index-transaction-view.c	Mon Jul 16 07:52:50 2007 +0300
+++ b/src/lib-index/mail-index-transaction-view.c	Mon Jul 16 09:48:02 2007 +0300
@@ -42,23 +42,16 @@ _tview_get_header(struct mail_index_view
 	struct mail_index_view_transaction *tview =
                 (struct mail_index_view_transaction *)view;
 	const struct mail_index_header *hdr;


More information about the dovecot-cvs mailing list