dovecot-2.2: lib-index: When writing new index, rotate the log f...

dovecot at dovecot.org dovecot at dovecot.org
Sun Oct 4 18:54:11 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/8322fc090a57
changeset: 19282:8322fc090a57
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Oct 04 21:49:08 2015 +0300
description:
lib-index: When writing new index, rotate the log file first before writing it.
This way the index contains the new log's seq+offset instead of having to
recreate the index almost immediately afterwards.

diffstat:

 src/lib-index/mail-index-write.c |  23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diffs (44 lines):

diff -r b483fba06083 -r 8322fc090a57 src/lib-index/mail-index-write.c
--- a/src/lib-index/mail-index-write.c	Fri Oct 02 19:02:47 2015 +0300
+++ b/src/lib-index/mail-index-write.c	Sun Oct 04 21:49:08 2015 +0300
@@ -118,13 +118,29 @@
 void mail_index_write(struct mail_index *index, bool want_rotate)
 {
 	struct mail_index_map *map = index->map;
-	const struct mail_index_header *hdr = &map->hdr;
+	struct mail_index_header *hdr = &map->hdr;
 
 	i_assert(index->log_sync_locked);
 
 	if (index->readonly)
 		return;
 
+	/* rotate the .log before writing index, so the index will point to
+	   the latest log. */
+	if (want_rotate &&
+	    hdr->log_file_seq == index->log->head->hdr.file_seq &&
+	    hdr->log_file_tail_offset == hdr->log_file_head_offset) {
+		if (mail_transaction_log_rotate(index->log, FALSE) == 0) {
+			struct mail_transaction_log_file *file =
+				index->log->head;
+			i_assert(file->hdr.prev_file_seq == hdr->log_file_seq);
+			i_assert(file->hdr.prev_file_offset == hdr->log_file_head_offset);
+			hdr->log_file_seq = file->hdr.file_seq;
+			hdr->log_file_head_offset =
+				hdr->log_file_tail_offset = file->hdr.hdr_size;
+		}
+	}
+
 	if (!MAIL_INDEX_IS_IN_MEMORY(index)) {
 		if (mail_index_recreate(index) < 0) {
 			(void)mail_index_move_to_memory(index);
@@ -135,9 +151,4 @@
 	index->last_read_log_file_seq = hdr->log_file_seq;
 	index->last_read_log_file_head_offset = hdr->log_file_head_offset;
 	index->last_read_log_file_tail_offset = hdr->log_file_tail_offset;
-
-	if (want_rotate &&
-	    hdr->log_file_seq == index->log->head->hdr.file_seq &&
-	    hdr->log_file_tail_offset == hdr->log_file_head_offset)
-		(void)mail_transaction_log_rotate(index->log, FALSE);
 }


More information about the dovecot-cvs mailing list