dovecot-2.2: lib-storage: If dovecot.index.thread corruption is ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 12 17:24:24 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/e6c2a1344f86
changeset: 16689:e6c2a1344f86
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 12 17:24:05 2013 +0300
description:
lib-storage: If dovecot.index.thread corruption is noticed, delete the file.

diffstat:

 src/lib-index/mail-index-strmap.c    |   3 +--
 src/lib-index/mail-index-strmap.h    |   1 +
 src/lib-storage/index/index-thread.c |  26 +++++++++++++++++---------
 3 files changed, 19 insertions(+), 11 deletions(-)

diffs (106 lines):

diff -r 07b41fd29a6e -r e6c2a1344f86 src/lib-index/mail-index-strmap.c
--- a/src/lib-index/mail-index-strmap.c	Mon Aug 12 15:44:51 2013 +0300
+++ b/src/lib-index/mail-index-strmap.c	Mon Aug 12 17:24:05 2013 +0300
@@ -238,8 +238,7 @@
 	view->desynced = FALSE;
 }
 
-static void
-mail_index_strmap_view_set_corrupted(struct mail_index_strmap_view *view)
+void mail_index_strmap_view_set_corrupted(struct mail_index_strmap_view *view)
 {
 	mail_index_set_error(view->strmap->index,
 			     "Corrupted strmap index file: %s",
diff -r 07b41fd29a6e -r e6c2a1344f86 src/lib-index/mail-index-strmap.h
--- a/src/lib-index/mail-index-strmap.h	Mon Aug 12 15:44:51 2013 +0300
+++ b/src/lib-index/mail-index-strmap.h	Mon Aug 12 17:24:05 2013 +0300
@@ -56,6 +56,7 @@
 			    const ARRAY_TYPE(mail_index_strmap_rec) **recs_r,
 			    const struct hash2_table **hash_r);
 void mail_index_strmap_view_close(struct mail_index_strmap_view **view);
+void mail_index_strmap_view_set_corrupted(struct mail_index_strmap_view *view);
 
 /* Return the highest used string index. */
 uint32_t mail_index_strmap_view_get_highest_idx(struct mail_index_strmap_view *view);
diff -r 07b41fd29a6e -r e6c2a1344f86 src/lib-storage/index/index-thread.c
--- a/src/lib-storage/index/index-thread.c	Mon Aug 12 15:44:51 2013 +0300
+++ b/src/lib-storage/index/index-thread.c	Mon Aug 12 17:24:05 2013 +0300
@@ -28,6 +28,7 @@
 	ARRAY_TYPE(seq_range) added_uids;
 
 	unsigned int failed:1;
+	unsigned int corrupted:1;
 };
 
 struct mail_thread_mailbox {
@@ -52,10 +53,11 @@
 static void mail_thread_clear(struct mail_thread_context *ctx);
 
 static int
-mail_strmap_rec_get_msgid(struct mail *mail,
+mail_strmap_rec_get_msgid(struct mail_thread_context *ctx,
 			  const struct mail_index_strmap_rec *rec,
 			  const char **msgid_r)
 {
+	struct mail *mail = ctx->tmp_mail;
 	const char *msgids = NULL, *msgid;
 	unsigned int n = 0;
 	int ret;
@@ -91,15 +93,18 @@
 	/* get the nth message-id */
 	msgid = message_id_get_next(&msgids);
 	if (msgid != NULL) {
-		for (; n > 0 && *msgids != '\0'; n--)
+		for (; n > 0; n--)
 			msgid = message_id_get_next(&msgids);
 	}
 
 	if (msgid == NULL) {
-		/* shouldn't have happened */
+		/* shouldn't have happened, probably corrupted */
 		mail_storage_set_critical(mail->box->storage,
-			"Threading in %s UID %u lost Message ID %u",
+			"Corrupted thread index for mailbox %s: "
+			"UID %u lost Message ID %u",
 			mail->box->vname, mail->uid, rec->ref_index);
+		ctx->failed = TRUE;
+		ctx->corrupted = TRUE;
 		return -1;
 	}
 	*msgid_r = msgid;
@@ -119,7 +124,7 @@
 
 	/* either a match or a collision, need to look closer */
 	T_BEGIN {
-		ret = mail_strmap_rec_get_msgid(ctx->tmp_mail, rec, &msgid);
+		ret = mail_strmap_rec_get_msgid(ctx, rec, &msgid);
 		if (ret <= 0) {
 			if (ret < 0)
 				ctx->failed = TRUE;
@@ -142,11 +147,10 @@
 	int ret;
 
 	T_BEGIN {
-		ret = mail_strmap_rec_get_msgid(ctx->tmp_mail, rec1, &msgid1);
+		ret = mail_strmap_rec_get_msgid(ctx, rec1, &msgid1);
 		if (ret > 0) {
 			msgid1 = t_strdup(msgid1);
-			ret = mail_strmap_rec_get_msgid(ctx->tmp_mail, rec2,
-							&msgid2);
+			ret = mail_strmap_rec_get_msgid(ctx, rec2, &msgid2);
 		}
 		ret = ret <= 0 ? -1 :
 			strcmp(msgid1, msgid2) == 0;
@@ -567,7 +571,11 @@
 		mail_thread_cache_sync_add(tbox, ctx, search_ctx);
 	if (mailbox_search_deinit(&search_ctx) < 0)
 		ret = -1;
-
+	if (ctx->failed) {
+		ret = -1;
+		if (ctx->corrupted)
+			mail_index_strmap_view_set_corrupted(tbox->strmap_view);
+	}
 	if (ret < 0) {
 		mail_thread_deinit(&ctx);
 		return -1;


More information about the dovecot-cvs mailing list