dovecot: int/ext/mailbox sync offset changes: Combined mailbox a...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 15 23:52:51 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/420a386fa27a
changeset: 5749:420a386fa27a
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 15 23:52:47 2007 +0300
description:
int/ext/mailbox sync offset changes: Combined mailbox and int offsets to
"tail" offset and renamed ext offset to "head". This makes it clearer how
they're supposed to be used.

diffstat:

12 files changed, 107 insertions(+), 112 deletions(-)
src/lib-index/mail-index-map.c               |    4 -
src/lib-index/mail-index-private.h           |    4 +
src/lib-index/mail-index-sync-update.c       |   69 ++++++++++++--------------
src/lib-index/mail-index-sync.c              |   37 ++++++-------
src/lib-index/mail-index-view-sync.c         |   25 ++++-----
src/lib-index/mail-index-view.c              |    2 
src/lib-index/mail-index.h                   |    9 +--
src/lib-index/mail-transaction-log-append.c  |   14 ++---
src/lib-index/mail-transaction-log-file.c    |   31 +++++------
src/lib-index/mail-transaction-log-private.h |   10 +--
src/lib-index/mail-transaction-log.c         |   10 +--
src/lib-index/mail-transaction-log.h         |    4 +

diffs (truncated from 541 to 300 lines):

diff -r 25ec1a8ec702 -r 420a386fa27a src/lib-index/mail-index-map.c
--- a/src/lib-index/mail-index-map.c	Fri Jun 15 23:49:52 2007 +0300
+++ b/src/lib-index/mail-index-map.c	Fri Jun 15 23:52:47 2007 +0300
@@ -697,8 +697,8 @@ static int mail_index_map_latest_file(st
 		return ret;
 	}
 
-	index->last_read_log_file_index_offset =
-		new_map->hdr.log_file_index_int_offset;
+	index->last_read_log_file_tail_offset =
+		new_map->hdr.log_file_tail_offset;
 	mail_index_unmap(index, map);
 	*map = new_map;
 	return 1;
diff -r 25ec1a8ec702 -r 420a386fa27a src/lib-index/mail-index-private.h
--- a/src/lib-index/mail-index-private.h	Fri Jun 15 23:49:52 2007 +0300
+++ b/src/lib-index/mail-index-private.h	Fri Jun 15 23:52:47 2007 +0300
@@ -159,7 +159,9 @@ struct mail_index {
 	const struct mail_index_header *hdr;
 	struct mail_index_map *map;
 	uint32_t indexid;
-	uint32_t last_read_log_file_index_offset;
+	/* last known log_file_tail_offset in main index file. used for
+	   optimizing main index updates. */
+	uint32_t last_read_log_file_tail_offset;
 
 	int lock_type, shared_lock_count, excl_lock_count;
 	unsigned int lock_id;
diff -r 25ec1a8ec702 -r 420a386fa27a src/lib-index/mail-index-sync-update.c
--- a/src/lib-index/mail-index-sync-update.c	Fri Jun 15 23:49:52 2007 +0300
+++ b/src/lib-index/mail-index-sync-update.c	Fri Jun 15 23:52:47 2007 +0300
@@ -9,6 +9,7 @@
 #include "mail-transaction-log.h"
 #include "mail-transaction-log-private.h"
 
+#if 0 // FIXME: can we / do we want to support this?
 static void
 mail_index_sync_update_log_offset(struct mail_index_sync_map_ctx *ctx,
 				  struct mail_index_map *map, bool eol)
@@ -32,22 +33,11 @@ mail_index_sync_update_log_offset(struct
 		prev_offset = ctx->ext_intro_offset;
 	}
 
-	i_assert(prev_offset >= map->hdr.log_file_index_int_offset ||
-		 prev_seq > map->hdr.log_file_seq);
-	map->hdr.log_file_index_int_offset = prev_offset;
-
-	/* we might be in the middle of syncing internal transactions, with
-	   some of the following external transactions already synced. */
-	i_assert(prev_seq > map->hdr.log_file_seq ||
-		 prev_offset >= map->hdr.log_file_index_ext_offset || !eol);
-	if (map->hdr.log_file_seq != prev_seq ||
-	    prev_offset > map->hdr.log_file_index_ext_offset) {
-		map->hdr.log_file_seq = prev_seq;
-		map->hdr.log_file_index_ext_offset = prev_offset;
-	}
-}
-
-#if 0 // FIXME: can we / do we want to support this?
+	i_assert(prev_seq == map->hdr.log_file_seq);
+	i_assert(prev_offset >= map->hdr.log_file_head_offset);
+	map->hdr.log_file_head_offset = prev_offset;
+}
+
 static int
 mail_index_map_msync(struct mail_index *index, struct mail_index_map *map)
 {
@@ -730,7 +720,7 @@ int mail_index_sync_map(struct mail_inde
 	const struct mail_transaction_header *thdr;
 	const void *tdata;
 	uint32_t prev_seq, mailbox_sync_seq;
-	uoff_t prev_offset, mailbox_sync_offset;
+	uoff_t start_offset, prev_offset, mailbox_sync_offset;
 	int ret;
 	bool had_dirty;
 
@@ -748,15 +738,16 @@ int mail_index_sync_map(struct mail_inde
 		/* this isn't necessary correct currently, but it should be
 		   close enough */
 		log_size = index->log->head->last_size;
-		if (log_size > map->hdr.log_file_index_int_offset &&
-		    log_size - map->hdr.log_file_index_int_offset > index_size)
+		if (log_size > map->hdr.log_file_tail_offset &&
+		    log_size - map->hdr.log_file_tail_offset > index_size)
 			return 0;
 	}
 
+	start_offset = type == MAIL_INDEX_SYNC_HANDLER_FILE ?
+		map->hdr.log_file_tail_offset : map->hdr.log_file_head_offset;
 	view = mail_index_view_open_with_map(index, map);
 	if (mail_transaction_log_view_set(view->log_view,
-					  map->hdr.log_file_seq,
-					  map->hdr.log_file_index_int_offset,
+					  map->hdr.log_file_seq, start_offset,
 					  (uint32_t)-1, (uoff_t)-1) <= 0) {
 		/* can't use it. sync by re-reading index. */
 		mail_index_view_close(&view);
@@ -806,12 +797,16 @@ int mail_index_sync_map(struct mail_inde
 		mail_transaction_log_view_get_prev_pos(view->log_view,
 						       &prev_seq, &prev_offset);
 
-		if ((thdr->type & MAIL_TRANSACTION_EXTERNAL) != 0) {
-			/* see if this transaction is already synced */
-			if (prev_seq < view->map->hdr.log_file_seq ||
-			    (prev_seq == view->map->hdr.log_file_seq &&
-			     prev_offset <
-			     view->map->hdr.log_file_index_ext_offset))
+		if (LOG_IS_BEFORE(prev_seq, prev_offset,
+				  view->map->hdr.log_file_seq,
+				  view->map->hdr.log_file_head_offset)) {
+			/* this has been synced already. we're here only to call
+			   expunge handlers and extension update handlers. */
+			i_assert(type == MAIL_INDEX_SYNC_HANDLER_FILE);
+
+			if ((thdr->type & MAIL_TRANSACTION_EXTERNAL) != 0)
+				continue;
+			if ((thdr->type & MAIL_TRANSACTION_EXT_MASK) == 0)
 				continue;
 		}
 
@@ -827,15 +822,17 @@ int mail_index_sync_map(struct mail_inde
 		mail_index_sync_update_hdr_dirty_flag(map);
 
 	/* update sync position */
-	// FIXME: eol=TRUE gives intro errors
-	mail_index_sync_update_log_offset(&sync_map_ctx, map, FALSE);
-
-	/* although mailbox_sync_update gets updated by the header update
-	   records, transaction log syncing can internally also update
-	   mailbox_sync_max_offset to skip over following external
-	   transactions. use it to avoid extra unneeded log reading. */
-	map->hdr.log_file_mailbox_offset =
-		index->log->head->mailbox_sync_max_offset;
+	mail_transaction_log_view_get_prev_pos(view->log_view,
+					       &prev_seq, &prev_offset);
+	i_assert(index->log->head->hdr.file_seq == prev_seq);
+	map->hdr.log_file_seq = prev_seq;
+	map->hdr.log_file_head_offset = prev_offset;
+
+	/* transaction log tracks internally the current tail offset.
+	   besides using header updates, it also updates the offset to skip
+	   over following external transactions to avoid extra unneeded log
+	   reading. */
+	map->hdr.log_file_tail_offset = index->log->head->max_tail_offset;
 
 	if (map->write_base_header) {
 		i_assert(MAIL_INDEX_MAP_IS_IN_MEMORY(map));
diff -r 25ec1a8ec702 -r 420a386fa27a src/lib-index/mail-index-sync.c
--- a/src/lib-index/mail-index-sync.c	Fri Jun 15 23:49:52 2007 +0300
+++ b/src/lib-index/mail-index-sync.c	Fri Jun 15 23:52:47 2007 +0300
@@ -22,7 +22,7 @@ struct mail_index_sync_ctx {
 
 	ARRAY_DEFINE(sync_list, struct mail_index_sync_list);
 	uint32_t next_uid;
-	uint32_t last_mailbox_seq, last_mailbox_offset;
+	uint32_t last_tail_seq, last_tail_offset;
 
 	uint32_t append_uid_first, append_uid_last;
 
@@ -211,8 +211,8 @@ mail_index_sync_update_mailbox_pos(struc
 	mail_transaction_log_view_get_prev_pos(ctx->view->log_view,
 					       &seq, &offset);
 
-	ctx->last_mailbox_seq = seq;
-	ctx->last_mailbox_offset = offset + ctx->hdr->size + sizeof(*ctx->hdr);
+	ctx->last_tail_seq = seq;
+	ctx->last_tail_offset = offset + ctx->hdr->size + sizeof(*ctx->hdr);
 }
 
 static int
@@ -302,7 +302,7 @@ mail_index_need_sync(struct mail_index *
 
 	if (hdr->log_file_seq < log_file_seq ||
 	     (hdr->log_file_seq == log_file_seq &&
-	      hdr->log_file_mailbox_offset < log_file_offset))
+	      hdr->log_file_tail_offset < log_file_offset))
 		return TRUE;
 
 	/* already synced */
@@ -373,11 +373,9 @@ int mail_index_sync_begin(struct mail_in
 		return 0;
 	}
 
-	if (hdr->log_file_index_int_offset > hdr->log_file_index_ext_offset ||
+	if (hdr->log_file_tail_offset > hdr->log_file_head_offset ||
 	    hdr->log_file_seq > seq ||
-	    (hdr->log_file_seq == seq &&
-	     (hdr->log_file_index_ext_offset > offset ||
-	      hdr->log_file_mailbox_offset > offset))) {
+	    (hdr->log_file_seq == seq && hdr->log_file_tail_offset > offset)) {
 		/* broken sync positions. fix them. */
 		mail_index_set_error(index,
 			"broken sync positions in index file %s",
@@ -394,8 +392,8 @@ int mail_index_sync_begin(struct mail_in
 	ctx->lock_id = lock_id;
 	ctx->sync_recent = sync_recent;
 	ctx->sync_dirty = sync_dirty;
-	ctx->last_mailbox_seq = hdr->log_file_seq;
-	ctx->last_mailbox_offset = hdr->log_file_mailbox_offset;
+	ctx->last_tail_seq = hdr->log_file_seq;
+	ctx->last_tail_offset = hdr->log_file_tail_offset;
 
 	ctx->view = mail_index_view_open(index);
 
@@ -406,7 +404,7 @@ int mail_index_sync_begin(struct mail_in
 	/* 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_mailbox_offset) < 0) {
+					 hdr->log_file_tail_offset) < 0) {
                 mail_index_sync_rollback(&ctx);
 		return -1;
 	}
@@ -721,7 +719,7 @@ static void mail_index_write(struct mail
 		mail_index_unlock(index, lock_id);
 	}
 
-	index->last_read_log_file_index_offset = hdr->log_file_index_int_offset;
+	index->last_read_log_file_tail_offset = hdr->log_file_tail_offset;
 
 	map->write_atomic = FALSE;
 	map->write_seq_first = map->write_seq_last = 0;
@@ -729,8 +727,7 @@ static void mail_index_write(struct mail
 	map->write_ext_header = FALSE;
 
 	if (want_rotate &&
-	    hdr->log_file_index_int_offset == hdr->log_file_index_ext_offset &&
-	    hdr->log_file_index_int_offset == hdr->log_file_mailbox_offset)
+	    hdr->log_file_tail_offset == hdr->log_file_head_offset)
 		(void)mail_transaction_log_rotate(index->log);
 }
 
@@ -745,11 +742,9 @@ mail_index_sync_update_mailbox_offset(st
 					       &seq, &offset);
 	mail_transaction_log_set_mailbox_sync_pos(ctx->index->log, seq, offset);
 
-	/* This sync may have seen only external transactions, in which case
-	   it's not required to write the mailbox sync offset. Otherwise we
-	   must update the offset even if nothing else is going to be
-	   written. */
-	if (hdr->log_file_mailbox_offset != ctx->last_mailbox_offset)
+	/* If tail offset has changed, make sure it gets written to
+	   transaction log. */
+	if (hdr->log_file_tail_offset != ctx->last_tail_offset)
 		ctx->ext_trans->log_updates = TRUE;
 }
 
@@ -788,8 +783,8 @@ int mail_index_sync_commit(struct mail_i
 
 	/* FIXME: create a better rule? */
 	want_rotate = mail_transaction_log_want_rotate(index->log);
-	diff = index->map->hdr.log_file_index_int_offset -
-		index->last_read_log_file_index_offset;
+	diff = index->map->hdr.log_file_tail_offset -
+		index->last_read_log_file_tail_offset;
 	if (ret == 0 && (diff > 1024 || want_rotate))
 		mail_index_write(index, want_rotate);
 	mail_index_sync_end(_ctx);
diff -r 25ec1a8ec702 -r 420a386fa27a src/lib-index/mail-index-view-sync.c
--- a/src/lib-index/mail-index-view-sync.c	Fri Jun 15 23:49:52 2007 +0300
+++ b/src/lib-index/mail-index-view-sync.c	Fri Jun 15 23:52:47 2007 +0300
@@ -119,7 +119,7 @@ static int view_sync_set_log_view_range(
 	ret = mail_transaction_log_view_set(view->log_view,
 					    tail_seq, tail_offset,
 					    hdr->log_file_seq,
-					    hdr->log_file_index_int_offset);
+					    hdr->log_file_head_offset);
 	if (ret <= 0) {
 		if (ret == 0) {
 			/* FIXME: use the new index to get needed changes */
@@ -256,8 +256,7 @@ static void mail_index_view_check(struct
 
 #define VIEW_IS_SYNCED_TO_SAME(hdr, tail_seq, tail_offset) \
 	((hdr)->log_file_seq == (tail_seq) && \
-	 (hdr)->log_file_index_int_offset == (tail_offset) && \
-	 (hdr)->log_file_index_ext_offset == (tail_offset))
+	 (hdr)->log_file_head_offset == (tail_offset))
 
 int mail_index_view_sync_begin(struct mail_index_view *view,
                                enum mail_index_view_sync_type sync_type,
@@ -525,14 +524,14 @@ mail_index_view_sync_get_next_transactio
 
 		mail_transaction_log_view_get_prev_pos(log_view, &seq, &offset);
 
-		/* if we started from a map that we didn't create ourself,
-		   some of the external transactions may already be synced.
-		   at the end of view sync we'll update the file_seq=0 in the
-		   header so that this check always becomes FALSE for
-		   subsequent syncs. */
-		synced_to_map = offset < view->hdr.log_file_index_ext_offset &&
-			seq == view->hdr.log_file_seq &&
-			(hdr->type & MAIL_TRANSACTION_EXTERNAL) != 0;
+		/* If we started from a map that we didn't create ourself,
+		   some of the transactions may already be synced. at the end
+		   of this view sync we'll update file_seq=0 so that this check
+		   always becomes FALSE for subsequent syncs. */
+		synced_to_map = view->map->hdr.log_file_seq != 0 &&
+			!LOG_IS_BEFORE(seq, offset,
+				       view->map->hdr.log_file_seq,
+				       view->map->hdr.log_file_head_offset);


More information about the dovecot-cvs mailing list