]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: If mail_debug=yes, log cache compressions.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 28 Jul 2016 22:02:29 +0000 (01:02 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 4 Aug 2016 15:16:45 +0000 (18:16 +0300)
src/lib-index/mail-cache-compress.c
src/lib-index/mail-index.h
src/lib-storage/index/index-storage.c

index 1d47b22d97dae8e369d57f8943a921f7dcd725ac..dbe7c3b451439453a2d1793c52d71b218c73f692 100644 (file)
@@ -161,7 +161,7 @@ mail_cache_compress_get_fields(struct mail_cache_copy_context *ctx,
 
 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 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans,
        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 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans,
                        /* 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 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans,
                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 @@ mail_cache_compress_write(struct mail_cache *cache,
                          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 @@ mail_cache_compress_write(struct mail_cache *cache,
                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);
index bf4620db0ee782f602a89f5ff3d7137c43137cf7..50e09e4b96c251c0d53743fdf31d75cf394b7434 100644 (file)
@@ -34,7 +34,9 @@ enum mail_index_open_flags {
        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 {
index 529b29c714b848d659a5e2e24209c48558bd6962..f5fd50f789b35f0a13f3fe63d0472e8bca8949ea 100644 (file)
@@ -333,6 +333,8 @@ void index_storage_mailbox_alloc(struct mailbox *box, const char *vname,
                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);