dovecot-2.2: lib-index: If a cache record is larger than 64 kB, ...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Nov 3 19:35:59 EET 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/d2860e8fc774
changeset: 15372:d2860e8fc774
user: Timo Sirainen <tss at iki.fi>
date: Sat Nov 03 19:35:54 2012 +0200
description:
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.
diffstat:
src/lib-index/mail-cache-compress.c | 5 +++--
src/lib-index/mail-cache-private.h | 3 +++
src/lib-index/mail-cache-transaction.c | 12 ++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diffs (60 lines):
diff -r 67afcb730109 -r d2860e8fc774 src/lib-index/mail-cache-compress.c
--- 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));
diff -r 67afcb730109 -r d2860e8fc774 src/lib-index/mail-cache-private.h
--- 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
diff -r 67afcb730109 -r d2860e8fc774 src/lib-index/mail-cache-transaction.c
--- 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);
More information about the dovecot-cvs
mailing list