changeset 20561:6f381c5ad896

lib-index: If mail_debug=yes, log cache compressions.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 29 Jul 2016 01:02:29 +0300
parents 3a71ed48cdf7
children 1e842633f27a
files src/lib-index/mail-cache-compress.c src/lib-index/mail-index.h src/lib-storage/index/index-storage.c
diffstat 3 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache-compress.c	Mon Jul 25 14:20:05 2016 -0400
+++ b/src/lib-index/mail-cache-compress.c	Fri Jul 29 01:02:29 2016 +0300
@@ -161,7 +161,7 @@
 
 static int
 mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans,
-		int fd, uint32_t *file_seq_r,
+		int fd, uint32_t *file_seq_r, uoff_t *file_size_r, uint32_t *max_uid_r,
 		ARRAY_TYPE(uint32_t) *ext_offsets)
 {
         struct mail_cache_copy_context ctx;
@@ -177,6 +177,8 @@
 	unsigned int i, used_fields_count, orig_fields_count, record_count;
 	time_t max_drop_time;
 
+	*max_uid_r = 0;
+
 	/* get the latest info on fields */
 	if (mail_cache_header_fields_read(cache) < 0)
 		return -1;
@@ -274,6 +276,7 @@
 			/* nothing cached */
 			ext_offset = 0;
 		} else {
+			mail_index_lookup_uid(view, seq, max_uid_r);
 			cache_rec.size = ctx.buffer->used;
 			ext_offset = output->offset;
 			buffer_write(ctx.buffer, 0, &cache_rec,
@@ -306,6 +309,7 @@
 		array_free(ext_offsets);
 		return -1;
 	}
+	*file_size_r = output->offset;
 	o_stream_destroy(&output);
 
 	if (cache->index->fsync_mode == FSYNC_MODE_ALWAYS) {
@@ -326,12 +330,14 @@
 			  int fd, const char *temp_path, bool *unlock)
 {
 	struct stat st;
-	uint32_t file_seq, old_offset;
+	uint32_t file_seq, old_offset, max_uid;
 	ARRAY_TYPE(uint32_t) ext_offsets;
 	const uint32_t *offsets;
+	uoff_t file_size;
 	unsigned int i, count;
 
-	if (mail_cache_copy(cache, trans, fd, &file_seq, &ext_offsets) < 0)
+	if (mail_cache_copy(cache, trans, fd, &file_seq, &file_size,
+			    &max_uid, &ext_offsets) < 0)
 		return -1;
 
 	if (fstat(fd, &st) < 0) {
@@ -345,6 +351,13 @@
 		return -1;
 	}
 
+	if ((cache->index->flags & MAIL_INDEX_OPEN_FLAG_DEBUG) != 0) {
+		i_debug("%s: Compressed, file_seq changed %u -> %u, "
+			"size=%"PRIuUOFF_T", max_uid=%u", cache->filepath,
+			cache->need_compress_file_seq, file_seq,
+			file_size, max_uid);
+	}
+
 	/* once we're sure that the compression was successful,
 	   update the offsets */
 	mail_index_ext_reset(trans, cache->ext_id, file_seq, TRUE);
--- a/src/lib-index/mail-index.h	Mon Jul 25 14:20:05 2016 -0400
+++ b/src/lib-index/mail-index.h	Fri Jul 29 01:02:29 2016 +0300
@@ -34,7 +34,9 @@
 	MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY	= 0x200,
 	/* We're only going to save new messages to the index.
 	   Avoid unnecessary reads. */
-	MAIL_INDEX_OPEN_FLAG_SAVEONLY		= 0x400
+	MAIL_INDEX_OPEN_FLAG_SAVEONLY		= 0x400,
+	/* Enable debug logging */
+	MAIL_INDEX_OPEN_FLAG_DEBUG		= 0x800,
 };
 
 enum mail_index_header_compat_flags {
--- a/src/lib-storage/index/index-storage.c	Mon Jul 25 14:20:05 2016 -0400
+++ b/src/lib-storage/index/index-storage.c	Fri Jul 29 01:02:29 2016 +0300
@@ -333,6 +333,8 @@
 		mail_storage_settings_to_index_flags(box->storage->set);
 	if ((box->flags & MAILBOX_FLAG_SAVEONLY) != 0)
 		ibox->index_flags |= MAIL_INDEX_OPEN_FLAG_SAVEONLY;
+	if (box->storage->user->mail_debug)
+		ibox->index_flags |= MAIL_INDEX_OPEN_FLAG_DEBUG;
 	ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL;
 	MODULE_CONTEXT_SET(box, index_storage_module, ibox);