dovecot-2.1: lib-index: Handle transaction log read errors separ...

dovecot at dovecot.org dovecot at dovecot.org
Wed Nov 23 19:01:59 EET 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/fb0ffce5a0ba
changeset: 13750:fb0ffce5a0ba
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Nov 23 19:01:28 2011 +0200
description:
lib-index: Handle transaction log read errors separately from log corruption.

diffstat:

 src/lib-index/mail-index-modseq.c    |   4 ++--
 src/lib-index/mail-index-sync.c      |  17 ++++++++++++-----
 src/lib-index/mail-index-view-sync.c |   2 +-
 src/lib-index/mail-transaction-log.h |   4 ++--
 4 files changed, 17 insertions(+), 10 deletions(-)

diffs (80 lines):

diff -r 90ecb83a9ca7 -r fb0ffce5a0ba src/lib-index/mail-index-modseq.c
--- a/src/lib-index/mail-index-modseq.c	Wed Nov 23 17:01:51 2011 +0200
+++ b/src/lib-index/mail-index-modseq.c	Wed Nov 23 19:01:28 2011 +0200
@@ -426,8 +426,8 @@
 					    I_MAX(1, hdr->log_seq),
 					    hdr->log_offset,
 					    end_seq, end_offset, &reset);
-	if (ret == 0) {
-		/* missing files - try with only the last file */
+	if (ret <= 0) {
+		/* missing files / error - try with only the last file */
 		ret = mail_transaction_log_view_set(ctx->log_view, end_seq, 0,
 						    end_seq, end_offset,
 						    &reset);
diff -r 90ecb83a9ca7 -r fb0ffce5a0ba src/lib-index/mail-index-sync.c
--- a/src/lib-index/mail-index-sync.c	Wed Nov 23 17:01:51 2011 +0200
+++ b/src/lib-index/mail-index-sync.c	Wed Nov 23 19:01:28 2011 +0200
@@ -315,15 +315,17 @@
 	ret = mail_transaction_log_view_set(view->log_view,
                                             start_file_seq, start_file_offset,
 					    log_seq, log_offset, &reset);
-	if (ret <= 0) {
+	if (ret < 0)
+		return -1;
+	if (ret == 0) {
 		/* either corrupted or the file was deleted for
 		   some reason. either way, we can't go forward */
 		mail_index_set_error(view->index,
 			"Unexpected transaction log desync with index %s",
 			view->index->filepath);
-		return -1;
+		return 0;
 	}
-	return 0;
+	return 1;
 }
 
 int mail_index_sync_begin(struct mail_index *index,
@@ -468,8 +470,13 @@
 
 	/* we wish to see all the changes from last mailbox sync position to
 	   the end of the transaction log */
-	if (mail_index_sync_set_log_view(ctx->view, hdr->log_file_seq,
-					 hdr->log_file_tail_offset) < 0) {
+	ret = mail_index_sync_set_log_view(ctx->view, hdr->log_file_seq,
+					   hdr->log_file_tail_offset);
+	if (ret < 0) {
+                mail_index_sync_rollback(&ctx);
+		return -1;
+	}
+	if (ret == 0) {
 		/* if a log file is missing, there's nothing we can do except
 		   to skip over it. fix the problem with fsck and try again. */
 		mail_index_fsck_locked(index);
diff -r 90ecb83a9ca7 -r fb0ffce5a0ba src/lib-index/mail-index-view-sync.c
--- a/src/lib-index/mail-index-view-sync.c	Wed Nov 23 17:01:51 2011 +0200
+++ b/src/lib-index/mail-index-view-sync.c	Wed Nov 23 19:01:28 2011 +0200
@@ -500,7 +500,7 @@
 		view->map->hdr.log_file_head_offset;
 
 	if (mail_transaction_log_view_set(view->log_view, seq, offset,
-					  seq, offset, &reset) < 0)
+					  seq, offset, &reset) <= 0)
 		return -1;
 	view->inconsistent = FALSE;
 	return 0;
diff -r 90ecb83a9ca7 -r fb0ffce5a0ba src/lib-index/mail-transaction-log.h
--- a/src/lib-index/mail-transaction-log.h	Wed Nov 23 17:01:51 2011 +0200
+++ b/src/lib-index/mail-transaction-log.h	Wed Nov 23 19:01:28 2011 +0200
@@ -210,8 +210,8 @@
 mail_transaction_log_view_open(struct mail_transaction_log *log);
 void mail_transaction_log_view_close(struct mail_transaction_log_view **view);
 
-/* Set view boundaries. Returns -1 if error, 0 if files are lost, 1 if ok.
-   reset_r=TRUE if the whole index should be reset before applying any
+/* Set view boundaries. Returns -1 if error, 0 if files are lost or corrupted,
+   1 if ok. reset_r=TRUE if the whole index should be reset before applying any
    changes. */
 int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
 				  uint32_t min_file_seq, uoff_t min_file_offset,


More information about the dovecot-cvs mailing list