]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: Log reason why mailbox is synced with debug logging
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 18 Feb 2022 16:31:43 +0000 (18:31 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 28 Feb 2022 13:47:54 +0000 (15:47 +0200)
src/doveadm/dsync/dsync-brain-mailbox.c
src/doveadm/dsync/dsync-brain-mails.c
src/doveadm/dsync/dsync-brain-private.h

index ff15c3c738b2a3be66458bfba45a087ca1ee9255..759018fe4f471354b8e1bf71bfecc92cb56de3e4 100644 (file)
@@ -600,18 +600,46 @@ void dsync_brain_master_send_mailbox(struct dsync_brain *brain)
 
 bool dsync_boxes_need_sync(struct dsync_brain *brain,
                           const struct dsync_mailbox *box1,
-                          const struct dsync_mailbox *box2)
+                          const struct dsync_mailbox *box2,
+                          const char **reason_r)
 {
        if (brain->no_mail_sync)
                return FALSE;
-       if (brain->sync_type != DSYNC_BRAIN_SYNC_TYPE_CHANGED)
+       if (brain->sync_type != DSYNC_BRAIN_SYNC_TYPE_CHANGED) {
+               *reason_r = "Full sync";
                return TRUE;
-       return box1->highest_modseq != box2->highest_modseq ||
-               box1->highest_pvt_modseq != box2->highest_pvt_modseq ||
-               box1->messages_count != box2->messages_count ||
-               box1->uid_next != box2->uid_next ||
-               box1->uid_validity != box2->uid_validity ||
-               box1->first_recent_uid != box2->first_recent_uid;
+       }
+       if (box1->uid_validity != box2->uid_validity)
+               *reason_r = t_strdup_printf("UIDVALIDITY changed: %u -> %u",
+                       box1->uid_validity, box2->uid_validity);
+       else if (box1->uid_next != box2->uid_next)
+               *reason_r = t_strdup_printf("UIDNEXT changed: %u -> %u",
+                       box1->uid_next, box2->uid_next);
+       else if (box1->messages_count != box2->messages_count)
+               *reason_r = t_strdup_printf("Message count changed: %u -> %u",
+                       box1->messages_count, box2->messages_count);
+       else if (box1->highest_modseq != box2->highest_modseq) {
+               *reason_r = t_strdup_printf("HIGHESTMODSEQ changed %"
+                                           PRIu64" -> %"PRIu64,
+                                           box1->highest_modseq,
+                                           box2->highest_modseq);
+               if (box1->highest_modseq == 0 ||
+                   box2->highest_modseq == 0) {
+                       *reason_r = t_strdup_printf(
+                               "%s (Permanent MODSEQs aren't supported)",
+                               *reason_r);
+               }
+       } else if (box1->highest_pvt_modseq != box2->highest_pvt_modseq)
+               *reason_r = t_strdup_printf("Private HIGHESTMODSEQ changed %"
+                                           PRIu64" -> %"PRIu64,
+                                           box1->highest_pvt_modseq,
+                                           box2->highest_pvt_modseq);
+       else if (box1->first_recent_uid != box2->first_recent_uid)
+               *reason_r = t_strdup_printf("First RECENT UID changed: %u -> %u",
+                       box1->first_recent_uid, box2->first_recent_uid);
+       else
+               return FALSE;
+       return TRUE;
 }
 
 static int
@@ -776,7 +804,7 @@ bool dsync_brain_slave_recv_mailbox(struct dsync_brain *brain)
        struct dsync_mailbox local_dsync_box;
        struct mailbox *box;
        struct file_lock *lock;
-       const char *errstr, *resync_reason;
+       const char *errstr, *resync_reason, *reason;
        enum mail_error error;
        int ret;
        bool resync;
@@ -858,7 +886,7 @@ bool dsync_brain_slave_recv_mailbox(struct dsync_brain *brain)
        resync = !dsync_brain_mailbox_update_pre(brain, box, &local_dsync_box,
                                                 dsync_box, &resync_reason);
 
-       if (!dsync_boxes_need_sync(brain, &local_dsync_box, dsync_box)) {
+       if (!dsync_boxes_need_sync(brain, &local_dsync_box, dsync_box, &reason)) {
                /* no fields appear to have changed, skip this mailbox */
                if (brain->debug) {
                        i_debug("brain %c: Skipping unchanged mailbox %s",
@@ -870,6 +898,11 @@ bool dsync_brain_slave_recv_mailbox(struct dsync_brain *brain)
                mailbox_free(&box);
                return TRUE;
        }
+       if (brain->debug) {
+               i_debug("brain %c: Syncing mailbox %s: %s",
+                       brain->master_brain ? 'M' : 'S',
+                       guid_128_to_string(dsync_box->mailbox_guid), reason);
+       }
 
        /* start export/import */
        dsync_brain_sync_mailbox_init(brain, box, lock, &local_dsync_box, FALSE);
index 87478f348c0855b0356ad2f9cfa46ecbaaef1d02..3feea20f5f78fef51e445c9f5b7ab7ea6fe5e7a8 100644 (file)
@@ -21,7 +21,7 @@ const char *dsync_box_state_names[DSYNC_BOX_STATE_DONE+1] = {
 static bool dsync_brain_master_sync_recv_mailbox(struct dsync_brain *brain)
 {
        const struct dsync_mailbox *dsync_box;
-       const char *resync_reason;
+       const char *resync_reason, *reason;
        enum dsync_ibc_recv_ret ret;
        bool resync;
 
@@ -64,11 +64,17 @@ static bool dsync_brain_master_sync_recv_mailbox(struct dsync_brain *brain)
                                                 &brain->local_dsync_box,
                                                 dsync_box, &resync_reason);
 
-       if (!dsync_boxes_need_sync(brain, &brain->local_dsync_box, dsync_box)) {
+       if (!dsync_boxes_need_sync(brain, &brain->local_dsync_box, dsync_box,
+                                  &reason)) {
                /* no fields appear to have changed, skip this mailbox */
                dsync_brain_sync_mailbox_deinit(brain);
                return TRUE;
        }
+       if (brain->debug) {
+               i_debug("brain %c: Syncing mailbox %s: %s",
+                       brain->master_brain ? 'M' : 'S',
+                       guid_128_to_string(dsync_box->mailbox_guid), reason);
+       }
        if ((ret = dsync_brain_sync_mailbox_open(brain, dsync_box)) < 0)
                return TRUE;
        if (resync)
index 62bbac1f6fd2527b4cced3a7e605131f1ff22e7b..8dc8f609c12059f7dfc7e42913ede80d44f973e8 100644 (file)
@@ -148,7 +148,8 @@ bool dsync_brain_mailbox_update_pre(struct dsync_brain *brain,
                                    const char **reason_r);
 bool dsync_boxes_need_sync(struct dsync_brain *brain,
                           const struct dsync_mailbox *box1,
-                          const struct dsync_mailbox *box2);
+                          const struct dsync_mailbox *box2,
+                          const char **reason_r);
 void dsync_brain_sync_init_box_states(struct dsync_brain *brain);
 void dsync_brain_set_changes_during_sync(struct dsync_brain *brain,
                                         const char *reason);