dovecot-1.1: Sort index: Handle reset_id growing while adding no...

dovecot at dovecot.org dovecot at dovecot.org
Thu May 29 18:51:14 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/9c0d2413735d
changeset: 7567:9c0d2413735d
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 29 16:29:35 2008 +0300
description:
Sort index: Handle reset_id growing while adding non-wanted messages to sort
list.

diffstat:

1 file changed, 19 insertions(+), 4 deletions(-)
src/lib-storage/index/index-sort-string.c |   23 +++++++++++++++++++----

diffs (56 lines):

diff -r 8ae86f73f80d -r 9c0d2413735d src/lib-storage/index/index-sort-string.c
--- a/src/lib-storage/index/index-sort-string.c	Thu May 29 07:05:18 2008 +0300
+++ b/src/lib-storage/index/index-sort-string.c	Thu May 29 16:29:35 2008 +0300
@@ -36,6 +36,8 @@ struct sort_string_context {
 	uint32_t ext_id, last_seq, highest_reset_id;
 
 	unsigned int regetting:1;
+	unsigned int have_all_wanted:1;
+	unsigned int no_writing:1;
 };
 
 static char expunged_msg;
@@ -164,12 +166,18 @@ static void index_sort_node_add(struct s
 						 ctx->ext_id, &reset_id))
 			reset_id = 0;
 		if (reset_id != ctx->highest_reset_id) {
-			if (reset_id > ctx->highest_reset_id) {
+			if (reset_id < ctx->highest_reset_id) {
+				i_assert(expunged);
+				node->sort_id = 0;
+			} else if (ctx->have_all_wanted) {
+				/* a bit late to start changing the reset_id.
+				   the node lists aren't ordered by sequence
+				   anymore. */
+				node->sort_id = 0;
+				ctx->no_writing = TRUE;
+			} else {
 				ctx->highest_reset_id = reset_id;
 				index_sort_reget_sort_ids(ctx);
-			} else {
-				i_assert(expunged);
-				node->sort_id = 0;
 			}
 		}
 	}
@@ -599,6 +607,12 @@ static void index_sort_write_changed_sor
 	const struct mail_sort_node *nodes;
 	unsigned int i, count;
 
+	if (ctx->no_writing) {
+		/* our reset_id is already stale - don't even bother
+		   trying to write */
+		return;
+	}
+
 	mail_index_ext_reset_inc(t->trans, ext_id, ctx->highest_reset_id, FALSE);
 
 	/* add the missing sort IDs to index */
@@ -635,6 +649,7 @@ static void index_sort_add_missing(struc
 	unsigned int i, count;
 	uint32_t seq, next_seq;
 
+	ctx->have_all_wanted = TRUE;
 
 	seqs = array_get(&ctx->program->seqs, &count);
 	for (i = 0, next_seq = 1; i < count; i++) {


More information about the dovecot-cvs mailing list