[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-save.c, 1.81, 1.82 mbox-sync-private.h, 1.50, 1.51 mbox-sync.c, 1.152, 1.153

cras at dovecot.org cras at dovecot.org
Sat Apr 23 18:18:24 EEST 2005


Update of /var/lib/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv28538/lib-storage/index/mbox

Modified Files:
	mbox-save.c mbox-sync-private.h mbox-sync.c 
Log Message:
If UIDVALIDITY changes, don't invalidate the whole index. Just expunge all
existing messages and update uidvalidity/nextuid fields. Now we don't have
to re-login when this happens.



Index: mbox-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-save.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- mbox-save.c	8 Apr 2005 14:32:52 -0000	1.81
+++ mbox-save.c	23 Apr 2005 15:18:22 -0000	1.82
@@ -558,7 +558,7 @@
 	if (ctx->synced) {
 		mail_index_update_header(ctx->trans,
 			offsetof(struct mail_index_header, next_uid),
-			&ctx->next_uid, sizeof(ctx->next_uid));
+			&ctx->next_uid, sizeof(ctx->next_uid), FALSE);
 	}
 
 	if (!ctx->synced && ctx->mbox->mbox_fd != -1 &&

Index: mbox-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- mbox-sync-private.h	8 Apr 2005 15:08:53 -0000	1.50
+++ mbox-sync-private.h	23 Apr 2005 15:18:22 -0000	1.51
@@ -113,7 +113,7 @@
 
 	pool_t mail_keyword_pool;
 
-	uint32_t prev_msg_uid, next_uid;
+	uint32_t prev_msg_uid, next_uid, idx_next_uid;
 	uint32_t seq, idx_seq, need_space_seq;
 	off_t expunged_space, space_diff;
 

Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -d -r1.152 -r1.153
--- mbox-sync.c	22 Apr 2005 20:58:18 -0000	1.152
+++ mbox-sync.c	23 Apr 2005 15:18:22 -0000	1.153
@@ -266,12 +266,12 @@
 		rec = NULL;
 	}
 
-	if (ret == 0 && uid < sync_ctx->hdr->next_uid) {
+	if (ret == 0 && uid < sync_ctx->idx_next_uid) {
 		/* this UID was already in index and it was expunged */
 		mail_storage_set_critical(STORAGE(sync_ctx->mbox->storage),
 			"mbox sync: Expunged message reappeared in mailbox %s "
 			"(UID %u < %u)", sync_ctx->mbox->path, uid,
-			sync_ctx->hdr->next_uid);
+			sync_ctx->idx_next_uid);
 		ret = 0; rec = NULL;
 	} else if (rec != NULL && rec->uid != uid) {
 		/* new UID in the middle of the mailbox - shouldn't happen */
@@ -923,7 +923,7 @@
 	const struct mail_index_record *rec;
 	uint32_t uid, messages_count;
 	uoff_t offset;
-	int ret, expunged, skipped_mails;
+	int ret, expunged, skipped_mails, uidvalidity_changed;
 
 	messages_count =
 		mail_index_view_get_messages_count(sync_ctx->sync_view);
@@ -938,10 +938,13 @@
 	while ((ret = mbox_sync_read_next_mail(sync_ctx, mail_ctx)) > 0) {
 		uid = mail_ctx->mail.uid;
 
-		if (mail_ctx->seq == 1 && sync_ctx->base_uid_validity != 0 &&
-                    sync_ctx->hdr->uid_validity != 0 &&
-		    sync_ctx->base_uid_validity !=
-		    sync_ctx->hdr->uid_validity) {
+		uidvalidity_changed = mail_ctx->seq == 1 &&
+			sync_ctx->base_uid_validity != 0 &&
+			sync_ctx->hdr->uid_validity != 0 &&
+			sync_ctx->base_uid_validity !=
+			sync_ctx->hdr->uid_validity;
+
+		if (uidvalidity_changed) {
 			mail_storage_set_critical(
 				STORAGE(sync_ctx->mbox->storage),
 				"UIDVALIDITY changed (%u -> %u) "
@@ -949,8 +952,21 @@
 				sync_ctx->hdr->uid_validity,
 				sync_ctx->base_uid_validity,
 				sync_ctx->mbox->path);
-                        mail_index_mark_corrupted(sync_ctx->mbox->ibox.index);
-			return -1;
+
+			/* we need to recreate all messages in index */
+			while (sync_ctx->idx_seq <= messages_count) {
+				mail_index_expunge(sync_ctx->t,
+						   sync_ctx->idx_seq++);
+			}
+
+			/* next_uid must be reset before message syncing
+			   begins, or we get errors about UIDs larger than
+			   next_uid. */
+			sync_ctx->idx_next_uid = 0;
+			mail_index_update_header(sync_ctx->t,
+				offsetof(struct mail_index_header, next_uid),
+				&sync_ctx->idx_next_uid,
+				sizeof(sync_ctx->idx_next_uid), TRUE);
 		}
 
 		if (mail_ctx->uid_broken && partial) {
@@ -963,7 +979,7 @@
 			uid = 0;
 
 		rec = NULL; ret = 1;
-		if (uid != 0) {
+		if (uid != 0 && !uidvalidity_changed) {
 			ret = mbox_sync_read_index_rec(sync_ctx, uid, &rec);
 			if (ret < 0)
 				return -1;
@@ -977,7 +993,8 @@
 		if (ret == 0) {
 			/* UID found but it's broken */
 			uid = 0;
-		} else if (uid == 0 && !mail_ctx->pseudo &&
+		} else if (uid == 0 && !uidvalidity_changed &&
+			   !mail_ctx->pseudo &&
 			   (sync_ctx->delay_writes ||
 			    sync_ctx->idx_seq <= messages_count)) {
 			/* If we can't use/store X-UID header, use MD5 sum.
@@ -994,7 +1011,7 @@
 				uid = mail_ctx->mail.uid = rec->uid;
 		}
 
-		if (!mail_ctx->pseudo) {
+		if (!mail_ctx->pseudo && !uidvalidity_changed) {
 			/* get all sync records related to this message */
 			if (mbox_sync_read_index_syncs(sync_ctx, uid,
 						       &expunged) < 0)
@@ -1075,7 +1092,6 @@
 
 	if (!skipped_mails)
 		sync_ctx->mbox->mbox_sync_dirty = FALSE;
-
 	return 1;
 }
 
@@ -1251,7 +1267,7 @@
 		mail_index_update_header(sync_ctx->t,
 			offsetof(struct mail_index_header, uid_validity),
 			&sync_ctx->base_uid_validity,
-			sizeof(sync_ctx->base_uid_validity));
+			sizeof(sync_ctx->base_uid_validity), TRUE);
 	}
 
 	if (istream_raw_mbox_is_eof(sync_ctx->input) &&
@@ -1259,7 +1275,7 @@
 		i_assert(sync_ctx->next_uid != 0);
 		mail_index_update_header(sync_ctx->t,
 			offsetof(struct mail_index_header, next_uid),
-			&sync_ctx->next_uid, sizeof(sync_ctx->next_uid));
+			&sync_ctx->next_uid, sizeof(sync_ctx->next_uid), FALSE);
 	}
 
 	if ((uint32_t)st->st_mtime != sync_ctx->hdr->sync_stamp &&
@@ -1268,7 +1284,7 @@
 
 		mail_index_update_header(sync_ctx->t,
 			offsetof(struct mail_index_header, sync_stamp),
-			&sync_stamp, sizeof(sync_stamp));
+			&sync_stamp, sizeof(sync_stamp), TRUE);
 	}
 
 	if ((uint64_t)st->st_size != sync_ctx->hdr->sync_size &&
@@ -1277,7 +1293,7 @@
 
 		mail_index_update_header(sync_ctx->t,
 			offsetof(struct mail_index_header, sync_size),
-			&sync_size, sizeof(sync_size));
+			&sync_size, sizeof(sync_size), TRUE);
 	}
 
 	sync_ctx->mbox->mbox_dirty_stamp = st->st_mtime;
@@ -1300,6 +1316,7 @@
 
 	sync_ctx->prev_msg_uid = 0;
 	sync_ctx->next_uid = sync_ctx->hdr->next_uid;
+	sync_ctx->idx_next_uid = sync_ctx->hdr->next_uid;
 	sync_ctx->seq = 0;
 	sync_ctx->idx_seq = 1;
 	sync_ctx->need_space_seq = 0;



More information about the dovecot-cvs mailing list