From: Timo Sirainen Date: Thu, 2 Apr 2020 20:45:49 +0000 (+0300) Subject: lib-index: Add mail_cache_decision_changed event X-Git-Tag: 2.3.11.2~363 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4db539d8fc542ebb44e01b28fbbcdd75787e7157;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Add mail_cache_decision_changed event --- diff --git a/src/lib-index/mail-cache-decisions.c b/src/lib-index/mail-cache-decisions.c index 3687c24778..79f07eea4e 100644 --- a/src/lib-index/mail-cache-decisions.c +++ b/src/lib-index/mail-cache-decisions.c @@ -70,6 +70,16 @@ #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) diff --git a/src/lib-index/mail-cache-private.h b/src/lib-index/mail-cache-private.h index 69ed818660..e5cf62af30 100644 --- a/src/lib-index/mail-cache-private.h +++ b/src/lib-index/mail-cache-private.h @@ -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, diff --git a/src/lib-index/mail-cache-purge.c b/src/lib-index/mail-cache-purge.c index c9af9ba653..7d2c864eda 100644 --- a/src/lib-index/mail-cache-purge.c +++ b/src/lib-index/mail-cache-purge.c @@ -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;