dovecot-2.1: lib-index: Allow updating cache's last_used field w...

dovecot at dovecot.org dovecot at dovecot.org
Sat Dec 10 08:42:37 EET 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/ce29836e369e
changeset: 13842:ce29836e369e
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Dec 10 08:42:26 2011 +0200
description:
lib-index: Allow updating cache's last_used field with mail_cache_register_fields()

diffstat:

 src/lib-index/mail-cache-compress.c  |   4 +-
 src/lib-index/mail-cache-decisions.c |   4 +-
 src/lib-index/mail-cache-fields.c    |  50 +++++++++++++++++++++++------------
 src/lib-index/mail-cache-private.h   |   1 -
 src/lib-index/mail-cache.h           |   2 +
 5 files changed, 39 insertions(+), 22 deletions(-)

diffs (162 lines):

diff -r 499e4916bed5 -r ce29836e369e src/lib-index/mail-cache-compress.c
--- a/src/lib-index/mail-cache-compress.c	Sat Dec 10 08:41:01 2011 +0200
+++ b/src/lib-index/mail-cache-compress.c	Sat Dec 10 08:42:26 2011 +0200
@@ -208,7 +208,7 @@
 			/* if the decision isn't forced and this field hasn't
 			   been accessed for a while, drop it */
 			if ((dec & MAIL_CACHE_DECISION_FORCED) == 0 &&
-			    (time_t)priv->last_used < max_drop_time &&
+			    priv->field.last_used < max_drop_time &&
 			    !priv->adding) {
 				dec = MAIL_CACHE_DECISION_NO;
 				priv->field.decision = dec;
@@ -218,7 +218,7 @@
 			if ((dec & ~MAIL_CACHE_DECISION_FORCED) ==
 			    MAIL_CACHE_DECISION_NO && !priv->adding) {
 				priv->used = FALSE;
-				priv->last_used = 0;
+				priv->field.last_used = 0;
 			}
 
 			ctx.field_file_map[i] = !priv->used ?
diff -r 499e4916bed5 -r ce29836e369e src/lib-index/mail-cache-decisions.c
--- a/src/lib-index/mail-cache-decisions.c	Sat Dec 10 08:41:01 2011 +0200
+++ b/src/lib-index/mail-cache-decisions.c	Sat Dec 10 08:42:26 2011 +0200
@@ -89,9 +89,9 @@
 		return;
 	}
 
-	if (ioloop_time - cache->fields[field].last_used > 3600*24) {
+	if (ioloop_time - cache->fields[field].field.last_used > 3600*24) {
 		/* update last_used about once a day */
-		cache->fields[field].last_used = (uint32_t)ioloop_time;
+		cache->fields[field].field.last_used = (uint32_t)ioloop_time;
 		if (cache->field_file_map[field] != (uint32_t)-1)
 			cache->field_header_write_pending = TRUE;
 	}
diff -r 499e4916bed5 -r ce29836e369e src/lib-index/mail-cache-fields.c
--- a/src/lib-index/mail-cache-fields.c	Sat Dec 10 08:41:01 2011 +0200
+++ b/src/lib-index/mail-cache-fields.c	Sat Dec 10 08:42:26 2011 +0200
@@ -65,11 +65,35 @@
 	return 0;
 }
 
+static void
+mail_cache_field_update(struct mail_cache *cache,
+			const struct mail_cache_field *newfield)
+{
+	struct mail_cache_field_private *orig;
+
+	i_assert(newfield->type < MAIL_CACHE_FIELD_COUNT);
+
+	orig = &cache->fields[newfield->idx];
+	if (newfield->decision != MAIL_CACHE_DECISION_NO &&
+	    orig->field.decision != newfield->decision) {
+		orig->field.decision = newfield->decision;
+		orig->decision_dirty = TRUE;
+	}
+	if (orig->field.last_used < newfield->last_used) {
+		orig->field.last_used = newfield->last_used;
+		orig->decision_dirty = TRUE;
+	}
+	if (orig->decision_dirty)
+		cache->field_header_write_pending = TRUE;
+
+	(void)field_type_verify(cache, newfield->idx,
+				newfield->type, newfield->field_size);
+}
+
 void mail_cache_register_fields(struct mail_cache *cache,
 				struct mail_cache_field *fields,
 				unsigned int fields_count)
 {
-	struct mail_cache_field *orig_field;
 	void *orig_key, *orig_value;
 	char *name;
 	unsigned int new_idx;
@@ -80,18 +104,9 @@
 		if (hash_table_lookup_full(cache->field_name_hash,
 					   fields[i].name,
 					   &orig_key, &orig_value)) {
-			i_assert(fields[i].type < MAIL_CACHE_FIELD_COUNT);
-
 			fields[i].idx =
 				POINTER_CAST_TO(orig_value, unsigned int);
-
-			orig_field = &cache->fields[fields[i].idx].field;
-			if (orig_field->decision == MAIL_CACHE_DECISION_NO)
-				orig_field->decision = fields[i].decision;
-
-			(void)field_type_verify(cache, fields[i].idx,
-						fields[i].type,
-						fields[i].field_size);
+			mail_cache_field_update(cache, &fields[i]);
 			continue;
 		}
 
@@ -130,6 +145,7 @@
 		name = p_strdup(cache->field_pool, fields[i].name);
 		cache->fields[idx].field = fields[i];
 		cache->fields[idx].field.name = name;
+		cache->fields[idx].field.last_used = fields[i].last_used;
 		cache->field_file_map[idx] = (uint32_t)-1;
 
 		if (!field_has_fixed_size(cache->fields[idx].field.type))
@@ -387,12 +403,12 @@
 		cache->file_field_map[i] = fidx;
 
 		/* update last_used if it's newer than ours */
-		if (last_used[i] > cache->fields[fidx].last_used)
-			cache->fields[fidx].last_used = last_used[i];
+		if (last_used[i] > cache->fields[fidx].field.last_used)
+			cache->fields[fidx].field.last_used = last_used[i];
 
 		dec = cache->fields[fidx].field.decision;
-		if ((time_t)cache->fields[fidx].last_used < max_drop_time &&
-		    cache->fields[fidx].last_used != 0 &&
+		if (cache->fields[fidx].field.last_used < max_drop_time &&
+		    cache->fields[fidx].field.last_used != 0 &&
 		    (dec & MAIL_CACHE_DECISION_FORCED) == 0 &&
 		    dec != MAIL_CACHE_DECISION_NO) {
 			/* time to drop this field. don't bother dropping
@@ -469,7 +485,7 @@
 	buffer = buffer_create_dynamic(pool_datastack_create(), 256);
 
 	copy_to_buf(cache, buffer, FALSE,
-		    offsetof(struct mail_cache_field_private, last_used),
+		    offsetof(struct mail_cache_field, last_used),
 		    sizeof(uint32_t));
 	ret = mail_cache_write(cache, buffer->data, buffer->used,
 			       offset + MAIL_CACHE_FIELD_LAST_USED());
@@ -532,7 +548,7 @@
 
 	/* we have to keep the field order for the existing fields. */
 	copy_to_buf(cache, dest, TRUE,
-		    offsetof(struct mail_cache_field_private, last_used),
+		    offsetof(struct mail_cache_field, last_used),
 		    sizeof(uint32_t));
 	copy_to_buf(cache, dest, TRUE,
 		    offsetof(struct mail_cache_field, field_size),
diff -r 499e4916bed5 -r ce29836e369e src/lib-index/mail-cache-private.h
--- a/src/lib-index/mail-cache-private.h	Sat Dec 10 08:41:01 2011 +0200
+++ b/src/lib-index/mail-cache-private.h	Sat Dec 10 08:42:26 2011 +0200
@@ -117,7 +117,6 @@
 	struct mail_cache_field field;
 
 	uint32_t uid_highwater;
-	uint32_t last_used;
 
 	/* Unused fields aren't written to cache file */
 	unsigned int used:1;
diff -r 499e4916bed5 -r ce29836e369e src/lib-index/mail-cache.h
--- a/src/lib-index/mail-cache.h	Sat Dec 10 08:41:01 2011 +0200
+++ b/src/lib-index/mail-cache.h	Sat Dec 10 08:42:26 2011 +0200
@@ -38,6 +38,8 @@
 	enum mail_cache_field_type type;
 	unsigned int field_size;
 	enum mail_cache_decision_type decision;
+	/* If higher than the current last_used field, update it */
+	time_t last_used;
 };
 
 struct mail_cache *mail_cache_open_or_create(struct mail_index *index);


More information about the dovecot-cvs mailing list