]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: mailbox_cache_purge*() - Add reason string
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 3 Apr 2020 08:06:15 +0000 (11:06 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 09:41:43 +0000 (12:41 +0300)
Include the reason in the mail_cache_purge_* events also.

src/doveadm/doveadm-mail-mailbox-cache.c
src/lib-index/mail-cache-decisions.c
src/lib-index/mail-cache-purge.c
src/lib-index/mail-cache-transaction.c
src/lib-index/mail-cache.h
src/lib-index/mail-index-sync.c
src/lib-storage/index/index-rebuild.c

index 01326ad36d347bb27fff82b06d59c1a774a41ecb..eb396b9b406a09d291d4c9acea7ed4b2facf8345 100644 (file)
@@ -328,7 +328,8 @@ static void cmd_mailbox_cache_remove_init(struct doveadm_mail_cmd_context *_ctx,
 static int cmd_mailbox_cache_purge_run_box(struct mailbox_cache_cmd_context *ctx,
                                           struct mailbox *box)
 {
-       if (mail_cache_purge(box->cache, (uint32_t)-1) < 0) {
+       if (mail_cache_purge(box->cache, (uint32_t)-1,
+                            "doveadm mailbox cache purge") < 0) {
                mailbox_set_index_error(box);
                doveadm_mail_failed_mailbox(&ctx->ctx, box);
                return -1;
index 79f07eea4e9828ab36295a8aaeeee52f539592ff..1a0083b3b8d89bc494411594b3328b579962a48a 100644 (file)
@@ -201,5 +201,5 @@ int mail_cache_decisions_copy(struct mail_cache *src, struct mail_cache *dst)
           that the fields are updated even if the cache was already created
           and no purging was done. */
        dst->field_header_write_pending = TRUE;
-       return mail_cache_purge(dst, 0);
+       return mail_cache_purge(dst, 0, "copy cache decisions");
 }
index 7d2c864eda72ca71894134458e21b44316520c94..49fef81ed44e66af07a942f2d4dd78b5ed9f5fdd 100644 (file)
@@ -166,7 +166,6 @@ mail_cache_purge_get_fields(struct mail_cache_copy_context *ctx,
                        struct event_passthrough *e =
                                mail_cache_decision_changed_event(
                                        cache, ctx->event, i)->
-                               add_str("reason", "purge")->
                                add_str("old_decision", "yes")->
                                add_str("new_decision", "temp");
                        e_debug(e->event(), "Purge changes field %s "
@@ -183,8 +182,8 @@ mail_cache_purge_get_fields(struct mail_cache_copy_context *ctx,
 
 static int
 mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans,
-               struct event *event, int fd, uint32_t *file_seq_r,
-               uoff_t *file_size_r, uint32_t *max_uid_r,
+               struct event *event, int fd, const char *reason,
+               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;
@@ -200,6 +199,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;
 
+       i_assert(reason != NULL);
+
        *max_uid_r = 0;
 
        /* get the latest info on fields */
@@ -218,9 +219,10 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans,
        hdr.file_seq = get_next_file_seq(cache);
        o_stream_nsend(output, &hdr, sizeof(hdr));
 
+       event_add_str(event, "reason", reason);
        event_add_int(event, "file_seq", hdr.file_seq);
        event_set_name(event, "mail_cache_purge_started");
-       e_debug(event, "Purging (new file_seq=%u)", hdr.file_seq);
+       e_debug(event, "Purging (new file_seq=%u): %s", hdr.file_seq, reason);
 
        i_zero(&ctx);
        ctx.cache = cache;
@@ -368,7 +370,8 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans,
 static int
 mail_cache_purge_write(struct mail_cache *cache,
                       struct mail_index_transaction *trans,
-                      int fd, const char *temp_path, bool *unlock)
+                      int fd, const char *temp_path, const char *
+                      reason, bool *unlock)
 {
        struct event *event;
        struct stat st;
@@ -392,8 +395,8 @@ mail_cache_purge_write(struct mail_cache *cache,
        event_add_int(event, "prev_file_size", prev_file_size);
        event_add_int(event, "prev_deleted_records", prev_deleted_records);
 
-       if (mail_cache_copy(cache, trans, event, fd, &file_seq, &file_size,
-                           &max_uid, &ext_offsets) < 0)
+       if (mail_cache_copy(cache, trans, event, fd, reason,
+                           &file_seq, &file_size, &max_uid, &ext_offsets) < 0)
                return -1;
 
        if (fstat(fd, &st) < 0) {
@@ -481,7 +484,7 @@ mail_cache_purge_has_file_changed(struct mail_cache *cache,
 static int mail_cache_purge_locked(struct mail_cache *cache,
                                   uint32_t purge_file_seq,
                                   struct mail_index_transaction *trans,
-                                  bool *unlock)
+                                  const char *reason, bool *unlock)
 {
        const char *temp_path;
        int fd, ret;
@@ -513,7 +516,7 @@ static int mail_cache_purge_locked(struct mail_cache *cache,
        fd = mail_index_create_tmp_file(cache->index, cache->filepath, &temp_path);
        if (fd == -1)
                return -1;
-       if (mail_cache_purge_write(cache, trans, fd, temp_path, unlock) < 0) {
+       if (mail_cache_purge_write(cache, trans, fd, temp_path, reason, unlock) < 0) {
                i_close_fd(&fd);
                i_unlink(temp_path);
                return -1;
@@ -533,7 +536,7 @@ static int mail_cache_purge_locked(struct mail_cache *cache,
 static int
 mail_cache_purge_full(struct mail_cache *cache,
                      struct mail_index_transaction *trans,
-                     uint32_t purge_file_seq)
+                     uint32_t purge_file_seq, const char *reason)
 {
        bool unlock = FALSE;
        int ret;
@@ -570,7 +573,7 @@ mail_cache_purge_full(struct mail_cache *cache,
                unlock = TRUE;
        }
        cache->purging = TRUE;
-       ret = mail_cache_purge_locked(cache, purge_file_seq, trans, &unlock);
+       ret = mail_cache_purge_locked(cache, purge_file_seq, trans, reason, &unlock);
        cache->purging = FALSE;
        if (unlock)
                mail_cache_unlock(cache);
@@ -585,12 +588,13 @@ mail_cache_purge_full(struct mail_cache *cache,
 
 int mail_cache_purge_with_trans(struct mail_cache *cache,
                                struct mail_index_transaction *trans,
-                               uint32_t purge_file_seq)
+                               uint32_t purge_file_seq, const char *reason)
 {
-       return mail_cache_purge_full(cache, trans, purge_file_seq);
+       return mail_cache_purge_full(cache, trans, purge_file_seq, reason);
 }
 
-int mail_cache_purge(struct mail_cache *cache, uint32_t purge_file_seq)
+int mail_cache_purge(struct mail_cache *cache, uint32_t purge_file_seq,
+                    const char *reason)
 {
        struct mail_index_view *view;
        struct mail_index_transaction *trans;
@@ -615,7 +619,8 @@ int mail_cache_purge(struct mail_cache *cache, uint32_t purge_file_seq)
                MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
        if (ret < 0)
                ;
-       else if ((ret = mail_cache_purge_full(cache, trans, purge_file_seq)) < 0)
+       else if ((ret = mail_cache_purge_full(cache, trans, purge_file_seq,
+                                             reason)) < 0)
                mail_index_transaction_rollback(&trans);
        else {
                if (mail_index_transaction_commit(&trans) < 0)
index 21378adc4e5991da096af78bd2b7c4e113efbc3f..c6f2e0680a5e6d66993a0b6942c60806d3a79e78 100644 (file)
@@ -201,7 +201,8 @@ bool mail_cache_transactions_have_changes(struct mail_cache *cache)
 }
 
 static int
-mail_cache_transaction_purge(struct mail_cache_transaction_ctx *ctx)
+mail_cache_transaction_purge(struct mail_cache_transaction_ctx *ctx,
+                            const char *reason)
 {
        struct mail_cache *cache = ctx->cache;
 
@@ -210,7 +211,7 @@ mail_cache_transaction_purge(struct mail_cache_transaction_ctx *ctx)
        uint32_t purge_file_seq =
                MAIL_CACHE_IS_UNUSABLE(cache) ? 0 : cache->hdr->file_seq;
 
-       int ret = mail_cache_purge(cache, purge_file_seq);
+       int ret = mail_cache_purge(cache, purge_file_seq, reason);
        /* already written cache records must be forgotten, but records in
           memory can still be written to the new cache file */
        mail_cache_transaction_forget_flushed(ctx, TRUE);
@@ -229,7 +230,7 @@ static int mail_cache_transaction_lock(struct mail_cache_transaction_ctx *ctx)
                        return -1;
 
                if (!ctx->tried_purging) {
-                       if (mail_cache_transaction_purge(ctx) < 0)
+                       if (mail_cache_transaction_purge(ctx, "creating cache") < 0)
                                return -1;
                        return mail_cache_transaction_lock(ctx);
                } else {
@@ -245,7 +246,7 @@ static int mail_cache_transaction_lock(struct mail_cache_transaction_ctx *ctx)
                if (cache->hdr->continued_record_count > 0 ||
                    cache->hdr->deleted_record_count > 0) {
                        mail_cache_unlock(cache);
-                       (void)mail_cache_transaction_purge(ctx);
+                       (void)mail_cache_transaction_purge(ctx, "cache is too large");
                        return mail_cache_transaction_lock(ctx);
                }
        }
index 2bce3eb3a7cdfca35c0a1c295e50fae59b91845f..3f6803e60ad0ebb77bc8b5f799da3cf65676869b 100644 (file)
@@ -76,8 +76,9 @@ bool mail_cache_need_purge(struct mail_cache *cache);
    done always regardless of file_seq. */
 int mail_cache_purge_with_trans(struct mail_cache *cache,
                                struct mail_index_transaction *trans,
-                               uint32_t purge_file_seq);
-int mail_cache_purge(struct mail_cache *cache, uint32_t purge_file_seq);
+                               uint32_t purge_file_seq, const char *reason);
+int mail_cache_purge(struct mail_cache *cache, uint32_t purge_file_seq,
+                    const char *reason);
 /* Returns TRUE if there is at least something in the cache. */
 bool mail_cache_exists(struct mail_cache *cache);
 /* Open and read cache header. Returns 1 if ok, 0 if cache doesn't exist or it
index c1510cc8b708fc3fc85b9269d1733785bc166363..0e17ba1e2400af6b76bdfc7c0df76ae4b7f94f49 100644 (file)
@@ -942,7 +942,8 @@ int mail_index_sync_commit(struct mail_index_sync_ctx **_ctx)
        if (ret == 0 && mail_cache_need_purge(index->cache) &&
            !mail_cache_transactions_have_changes(index->cache)) {
                if (mail_cache_purge(index->cache,
-                                    index->cache->need_purge_file_seq) < 0) {
+                                    index->cache->need_purge_file_seq,
+                                    "syncing") < 0) {
                        /* can't really do anything if it fails */
                }
                /* Make sure the newly committed cache record offsets are
index 17a5e43a7aed069850b15ddb90bca4bf119c23e4..b6cac3d226ed4142ec6cd81a1bdd400d77059963 100644 (file)
@@ -240,7 +240,7 @@ void index_index_rebuild_deinit(struct index_rebuild_context **_ctx,
 
        /* initialize cache file with the old field decisions */
        (void)mail_cache_purge_with_trans(ctx->box->cache, ctx->trans,
-                                         (uint32_t)-1);
+                                         (uint32_t)-1, "rebuilding index");
        index_rebuild_header(ctx, cb);
        index_rebuild_box_name_header(ctx);
        if (ctx->backup_index != NULL) {