]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_cache_decision_changed event
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 2 Apr 2020 20:45:49 +0000 (23:45 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 09:41:43 +0000 (12:41 +0300)
src/lib-index/mail-cache-decisions.c
src/lib-index/mail-cache-private.h
src/lib-index/mail-cache-purge.c

index 3687c2477848e8edbfcbb77c630cd94f62c172e7..79f07eea4e9828ab36295a8aaeeee52f539592ff 100644 (file)
 #include "ioloop.h"
 #include "mail-cache-private.h"
 
+struct event_passthrough *
+mail_cache_decision_changed_event(struct mail_cache *cache, struct event *event,
+                                 unsigned int field)
+{
+       return event_create_passthrough(event)->
+               set_name("mail_cache_decision_changed")->
+               add_str("field", cache->fields[field].field.name)->
+               add_int("last_used", cache->fields[field].field.last_used);
+}
+
 void mail_cache_decision_state_update(struct mail_cache_view *view,
                                      uint32_t seq, unsigned int field)
 {
@@ -119,6 +129,18 @@ void mail_cache_decision_state_update(struct mail_cache_view *view,
                cache->fields[field].field.decision = MAIL_CACHE_DECISION_YES;
                cache->fields[field].decision_dirty = TRUE;
                cache->field_header_write_pending = TRUE;
+
+               const char *reason = uid < hdr->day_first_uid[7] ?
+                       "old_mail" : "unordered_access";
+               struct event_passthrough *e =
+                       mail_cache_decision_changed_event(
+                               view->cache, view->cache->event, field)->
+                       add_str("reason", reason)->
+                       add_int("uid", uid)->
+                       add_str("old_decision", "temp")->
+                       add_str("new_decision", "yes");
+               e_debug(e->event(), "Changing field %s decision temp -> yes (uid=%u)",
+                       cache->fields[field].field.name, uid);
        } else {
                cache->fields[field].uid_highwater = uid;
        }
@@ -149,6 +171,15 @@ void mail_cache_decision_add(struct mail_cache_view *view, uint32_t seq,
 
        mail_index_lookup_uid(view->view, seq, &uid);
        cache->fields[field].uid_highwater = uid;
+
+       struct event_passthrough *e =
+               mail_cache_decision_changed_event(cache, cache->event, field)->
+               add_str("reason", "add")->
+               add_int("uid", uid)->
+               add_str("old_decision", "no")->
+               add_str("new_decision", "temp");
+       e_debug(e->event(), "Adding field %s to cache for the first time (uid=%u)",
+               cache->fields[field].field.name, uid);
 }
 
 int mail_cache_decisions_copy(struct mail_cache *src, struct mail_cache *dst)
index 69ed818660444532831631c02daf25f4982de137..e5cf62af30fe8aa8249df8b4478871e378cf1d3d 100644 (file)
@@ -271,6 +271,9 @@ int mail_cache_sync_reset_id(struct mail_cache *cache);
    in the cache file. */
 void mail_cache_decision_state_update(struct mail_cache_view *view,
                                      uint32_t seq, unsigned int field);
+struct event_passthrough *
+mail_cache_decision_changed_event(struct mail_cache *cache, struct event *event,
+                                 unsigned int field);
 
 int mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx,
                               uint32_t seq, const void *data,
index c9af9ba653729a0b2bcf5ae4c2c8a4bf61bcc485..7d2c864eda72ca71894134458e21b44316520c94 100644 (file)
@@ -15,6 +15,7 @@
 
 struct mail_cache_copy_context {
        struct mail_cache *cache;
+       struct event *event;
 
        buffer_t *buffer, *field_seen;
        ARRAY(unsigned int) bitmask_pos;
@@ -159,8 +160,20 @@ mail_cache_purge_get_fields(struct mail_cache_copy_context *ctx,
                /* change permanent decisions to temporary decisions.
                   if they're still permanent they'll get updated later. */
                field = &cache->fields[i].field;
-               if (field->decision == MAIL_CACHE_DECISION_YES)
+               if (field->decision == MAIL_CACHE_DECISION_YES) {
                        field->decision = MAIL_CACHE_DECISION_TEMP;
+
+                       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 "
+                               "cache decision yes -> temp "
+                               "(last_used=%"PRIdTIME_T")",
+                               field->name, field->last_used);
+               }
        }
        i_assert(j == used_fields_count);
 
@@ -211,6 +224,7 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans,
 
        i_zero(&ctx);
        ctx.cache = cache;
+       ctx.event = event;
        ctx.buffer = buffer_create_dynamic(default_pool, 4096);
        ctx.field_seen = buffer_create_dynamic(default_pool, 64);
        ctx.field_seen_value = 0;