dovecot-1.2: index: If we see duplicate transaction log files, a...

dovecot at dovecot.org dovecot at dovecot.org
Tue Nov 10 03:52:59 EET 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/2cf9f73cf0aa
changeset: 9467:2cf9f73cf0aa
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 09 20:38:19 2009 -0500
description:
index: If we see duplicate transaction log files, avoid corrupting the newer one.

diffstat:

1 file changed, 33 insertions(+), 13 deletions(-)
src/lib-index/mail-transaction-log-file.c |   46 ++++++++++++++++++++---------

diffs (71 lines):

diff -r 68af994e7f3c -r 2cf9f73cf0aa src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c	Thu Nov 05 15:23:52 2009 -0500
+++ b/src/lib-index/mail-transaction-log-file.c	Mon Nov 09 20:38:19 2009 -0500
@@ -15,6 +15,23 @@
 #define LOG_PREFETCH 1024
 #define MEMORY_LOG_NAME "(in-memory transaction log file)"
 
+static void
+mail_transaction_log_mark_corrupted(struct mail_transaction_log_file *file)
+{
+	unsigned int offset =
+		offsetof(struct mail_transaction_log_header, indexid);
+
+	if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file))
+		return;
+
+	/* indexid=0 marks the log file as corrupted */
+	if (pwrite_full(file->fd, &file->hdr.indexid,
+			sizeof(file->hdr.indexid), offset) < 0) {
+		mail_index_file_set_syscall_error(file->log->index,
+						  file->filepath, "pwrite()");
+	}
+}
+
 void
 mail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
 					const char *fmt, ...)
@@ -23,16 +40,7 @@ mail_transaction_log_file_set_corrupted(
 
 	file->corrupted = TRUE;
 	file->hdr.indexid = 0;
-	if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
-		/* indexid=0 marks the log file as corrupted */
-		if (pwrite_full(file->fd, &file->hdr.indexid,
-				sizeof(file->hdr.indexid),
-				offsetof(struct mail_transaction_log_header,
-					 indexid)) < 0) {
-			mail_index_file_set_syscall_error(file->log->index,
-				file->filepath, "pwrite()");
-		}
-	}
+	mail_transaction_log_mark_corrupted(file);
 
 	va_start(va, fmt);
 	T_BEGIN {
@@ -468,10 +476,22 @@ mail_transaction_log_file_read_hdr(struc
 		if (f->hdr.file_seq == file->hdr.file_seq) {
 			/* mark the old file corrupted. we can't safely remove
 			   it from the list however, so return failure. */
-			mail_transaction_log_file_set_corrupted(f,
+			f->corrupted = TRUE;
+			f->hdr.indexid = 0;
+			if (strcmp(f->filepath, f->log->head->filepath) != 0) {
+				/* only mark .2 corrupted, just to make sure
+				   we don't lose any changes from .log in case
+				   we're somehow wrong */
+				mail_transaction_log_mark_corrupted(f);
+				ret = 0;
+			} else {
+				ret = -1;
+			}
+			mail_index_set_error(f->log->index,
+				"Transaction log %s: "
 				"duplicate transaction log sequence (%u)",
-				f->hdr.file_seq);
-			return 0;
+				f->filepath, f->hdr.file_seq);
+			return ret;
 		}
 	}
 


More information about the dovecot-cvs mailing list