dovecot-1.2: indexes: Error handling fixes.

dovecot at dovecot.org dovecot at dovecot.org
Tue Apr 14 01:24:14 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/eb9e5ab575a9
changeset: 8941:eb9e5ab575a9
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Apr 13 17:21:32 2009 -0400
description:
indexes: Error handling fixes.

diffstat:

4 files changed, 23 insertions(+), 9 deletions(-)
src/lib-index/mail-index-map.c              |   20 +++++++++++---------
src/lib-index/mail-transaction-log-append.c |    4 ++++
src/lib-index/mail-transaction-log-file.c   |    1 +
src/lib-index/mail-transaction-log.c        |    7 +++++++

diffs (79 lines):

diff -r aba994bec90b -r eb9e5ab575a9 src/lib-index/mail-index-map.c
--- a/src/lib-index/mail-index-map.c	Mon Apr 13 16:11:15 2009 -0400
+++ b/src/lib-index/mail-index-map.c	Mon Apr 13 17:21:32 2009 -0400
@@ -942,11 +942,8 @@ int mail_index_map(struct mail_index *in
 		   logs (which we'll also do even if the reopening succeeds).
 		   if index files are unusable (e.g. major version change)
 		   don't even try to use the transaction log. */
-		if (mail_index_map_latest_file(index) == 0) {
-			/* make sure we don't try to open the file again */
-			if (unlink(index->filepath) < 0 && errno != ENOENT)
-				mail_index_set_syscall_error(index, "unlink()");
-		} else {
+		ret = mail_index_map_latest_file(index);
+		if (ret > 0) {
 			/* if we're creating the index file, we don't have any
 			   logs yet */
 			if (index->log->head != NULL && index->indexid != 0) {
@@ -955,10 +952,15 @@ int mail_index_map(struct mail_index *in
 				ret = mail_index_sync_map(&index->map, type,
 							  TRUE);
 			}
-		}
-	}
-
-	index->initial_mapped = TRUE;
+		} else if (ret == 0) {
+			/* make sure we don't try to open the file again */
+			if (unlink(index->filepath) < 0 && errno != ENOENT)
+				mail_index_set_syscall_error(index, "unlink()");
+		}
+	}
+
+	if (ret >= 0)
+		index->initial_mapped = TRUE;
 	index->mapping = FALSE;
 	return ret;
 }
diff -r aba994bec90b -r eb9e5ab575a9 src/lib-index/mail-transaction-log-append.c
--- a/src/lib-index/mail-transaction-log-append.c	Mon Apr 13 16:11:15 2009 -0400
+++ b/src/lib-index/mail-transaction-log-append.c	Mon Apr 13 17:21:32 2009 -0400
@@ -98,6 +98,10 @@ static int log_buffer_write(struct log_a
 	struct mail_transaction_log_file *file = ctx->file;
 
 	if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
+		if (file->buffer == NULL) {
+			file->buffer = buffer_create_dynamic(default_pool, 4096);
+			file->buffer_offset = sizeof(file->hdr);
+		}
 		buffer_append_buf(file->buffer, ctx->output, 0, (size_t)-1);
 		file->sync_offset = file->buffer_offset + file->buffer->used;
 		return 0;
diff -r aba994bec90b -r eb9e5ab575a9 src/lib-index/mail-transaction-log-file.c
--- a/src/lib-index/mail-transaction-log-file.c	Mon Apr 13 16:11:15 2009 -0400
+++ b/src/lib-index/mail-transaction-log-file.c	Mon Apr 13 17:21:32 2009 -0400
@@ -1564,6 +1564,7 @@ void mail_transaction_log_file_move_to_m
 		/* we don't have the full log in the memory. read it. */
 		(void)mail_transaction_log_file_read(file, 0, FALSE);
 	}
+	file->last_size = 0;
 
 	if (close(file->fd) < 0) {
 		mail_index_file_set_syscall_error(file->log->index,
diff -r aba994bec90b -r eb9e5ab575a9 src/lib-index/mail-transaction-log.c
--- a/src/lib-index/mail-transaction-log.c	Mon Apr 13 16:11:15 2009 -0400
+++ b/src/lib-index/mail-transaction-log.c	Mon Apr 13 17:21:32 2009 -0400
@@ -160,6 +160,13 @@ void mail_transaction_log_move_to_memory
 {
 	struct mail_transaction_log_file *file;
 
+	if (!log->index->initial_mapped && log->files != NULL &&
+	    log->files->hdr.prev_file_seq != 0) {
+		/* we couldn't read dovecot.index and we don't have the first
+		   .log file, so just start from scratch */
+		mail_transaction_log_close(log);
+	}
+
 	if (log->head != NULL)
 		mail_transaction_log_file_move_to_memory(log->head);
 	else {


More information about the dovecot-cvs mailing list