changeset 15372:d2860e8fc774

lib-index: If a cache record is larger than 64 kB, don't add it to cache file. This shouldn't affect anything except mails that probably shouldn't exist in the first place.
author Timo Sirainen <tss@iki.fi>
date Sat, 03 Nov 2012 19:35:54 +0200
parents 67afcb730109
children 8323e81785e2
files src/lib-index/mail-cache-compress.c src/lib-index/mail-cache-private.h src/lib-index/mail-cache-transaction.c
diffstat 3 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache-compress.c	Sat Nov 03 19:25:35 2012 +0200
+++ b/src/lib-index/mail-cache-compress.c	Sat Nov 03 19:35:54 2012 +0200
@@ -253,11 +253,12 @@
 		while (mail_cache_lookup_iter_next(&iter, &field) > 0)
 			mail_cache_compress_field(&ctx, &field);
 
-		cache_rec.size = buffer_get_used_size(ctx.buffer);
-		if (cache_rec.size == sizeof(cache_rec)) {
+		if (ctx.buffer->used == sizeof(cache_rec) ||
+		    ctx.buffer->used > MAIL_CACHE_RECORD_MAX_SIZE) {
 			/* nothing cached */
 			ext_offset = 0;
 		} else {
+			cache_rec.size = ctx.buffer->used;
 			ext_offset = output->offset;
 			buffer_write(ctx.buffer, 0, &cache_rec,
 				     sizeof(cache_rec));
--- a/src/lib-index/mail-cache-private.h	Sat Nov 03 19:25:35 2012 +0200
+++ b/src/lib-index/mail-cache-private.h	Sat Nov 03 19:35:54 2012 +0200
@@ -24,6 +24,9 @@
    the latest cache header. */
 #define MAIL_CACHE_HEADER_FIELD_CONTINUE_COUNT 4
 
+/* If cache record becomes larger than this, don't add it. */
+#define MAIL_CACHE_RECORD_MAX_SIZE (64*1024)
+
 #define MAIL_CACHE_LOCK_TIMEOUT 10
 #define MAIL_CACHE_LOCK_CHANGE_TIMEOUT 300
 
--- a/src/lib-index/mail-cache-transaction.c	Sat Nov 03 19:25:35 2012 +0200
+++ b/src/lib-index/mail-cache-transaction.c	Sat Nov 03 19:35:54 2012 +0200
@@ -367,6 +367,13 @@
 
 	i_assert(!ctx->cache->locked);
 
+	if (array_count(&ctx->cache_data_seq) == 0) {
+		/* we had done some changes, but they were aborted. */
+		i_assert(ctx->last_rec_pos == 0);
+		ctx->min_seq = 0;
+		return 0;
+	}
+
 	if (mail_cache_transaction_lock(ctx) <= 0)
 		return -1;
 
@@ -424,6 +431,11 @@
 	rec->size = size - ctx->last_rec_pos;
 	i_assert(rec->size > sizeof(*rec));
 
+	if (rec->size > MAIL_CACHE_RECORD_MAX_SIZE) {
+		buffer_set_used_size(ctx->cache_data, ctx->last_rec_pos);
+		return;
+	}
+
 	if (ctx->min_seq > ctx->prev_seq || ctx->min_seq == 0)
 		ctx->min_seq = ctx->prev_seq;
 	array_append(&ctx->cache_data_seq, &ctx->prev_seq, 1);