]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: If state is invalid, exit with code 2 instead of tempfail.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 25 Apr 2016 11:38:35 +0000 (14:38 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 26 Apr 2016 08:27:45 +0000 (11:27 +0300)
We'll have dsync_mailbox_import_*() just return success to everything until
_deinit() is called. The _deinit() will return a failure and set "resync
needed"-flag, which caller will know how to handle.

src/doveadm/dsync/dsync-brain-mailbox.c
src/doveadm/dsync/dsync-brain-mails.c
src/doveadm/dsync/dsync-mailbox-import.c
src/doveadm/dsync/dsync-mailbox-import.h

index f71c7aa808e08688210930988fce4c096bbac49a..fa43537bd9705de1807e0bd108c0ef5efe850b69 100644 (file)
@@ -360,7 +360,7 @@ void dsync_brain_sync_mailbox_deinit(struct dsync_brain *brain)
        if (brain->box_importer != NULL) {
                uint32_t last_common_uid, last_messages_count;
                uint64_t last_common_modseq, last_common_pvt_modseq;
-               bool changes_during_sync;
+               bool changes_during_sync, require_full_resync;
 
                i_assert(brain->failed);
                (void)dsync_mailbox_import_deinit(&brain->box_importer,
@@ -370,7 +370,10 @@ void dsync_brain_sync_mailbox_deinit(struct dsync_brain *brain)
                                                  &last_common_pvt_modseq,
                                                  &last_messages_count,
                                                  &changes_during_sync,
+                                                 &require_full_resync,
                                                  &brain->mail_error);
+               if (require_full_resync)
+                       brain->require_full_resync = TRUE;
        }
        if (brain->log_scan != NULL)
                dsync_transaction_log_scan_deinit(&brain->log_scan);
index a9ab009c5c9d3f2366f1d839fcc5d7b968dbb869..5a934e4f662927393f1b9d2604d4024e19ab0543 100644 (file)
@@ -219,6 +219,7 @@ static bool dsync_brain_send_mail_request(struct dsync_brain *brain)
 static void dsync_brain_sync_half_finished(struct dsync_brain *brain)
 {
        struct dsync_mailbox_state state;
+       bool require_full_resync;
 
        if (brain->box_recv_state < DSYNC_BOX_STATE_RECV_LAST_COMMON ||
            brain->box_send_state < DSYNC_BOX_STATE_RECV_LAST_COMMON)
@@ -246,13 +247,25 @@ static void dsync_brain_sync_half_finished(struct dsync_brain *brain)
                                                &state.last_common_pvt_modseq,
                                                &state.last_messages_count,
                                                &state.changes_during_sync,
+                                               &require_full_resync,
                                                &brain->mail_error) < 0) {
-                       brain->failed = TRUE;
-                       return;
+                       if (require_full_resync) {
+                               /* don't treat this as brain failure or the
+                                  state won't be sent to the other brain.
+                                  this also means we'll continue syncing the
+                                  following mailboxes. */
+                               brain->require_full_resync = TRUE;
+                       } else {
+                               brain->failed = TRUE;
+                       }
                }
                if (state.changes_during_sync)
                        brain->changes_during_sync = TRUE;
        }
+       if (brain->require_full_resync) {
+               state.last_uidvalidity = 0;
+               state.changes_during_sync = TRUE;
+       }
        brain->mailbox_state = state;
        dsync_ibc_send_mailbox_state(brain->ibc, &state);
 }
index 1bd127de21e055a99e6341be7c620995213cf0d9..f561787dfb78578af49b129d7ae2b17f38008872 100644 (file)
@@ -108,6 +108,7 @@ struct dsync_mailbox_importer {
        enum mail_error mail_error;
 
        unsigned int failed:1;
+       unsigned int require_full_resync:1;
        unsigned int debug:1;
        unsigned int stateful_import:1;
        unsigned int last_common_uid_found:1;
@@ -157,8 +158,7 @@ dsync_import_unexpected_state(struct dsync_mailbox_importer *importer,
                          "(dsync must be run again without the state)",
                          mailbox_get_vname(importer->box), error);
        }
-       importer->mail_error = MAIL_ERROR_TEMP;
-       importer->failed = TRUE;
+       importer->require_full_resync = TRUE;
 }
 
 static void
@@ -1698,6 +1698,8 @@ int dsync_mailbox_import_change(struct dsync_mailbox_importer *importer,
 
        if (importer->failed)
                return -1;
+       if (importer->require_full_resync)
+               return 0;
 
        if (!importer->last_common_uid_found) {
                result = NULL;
@@ -1713,6 +1715,8 @@ int dsync_mailbox_import_change(struct dsync_mailbox_importer *importer,
 
        if (importer->failed)
                return -1;
+       if (importer->require_full_resync)
+               return 0;
 
        if (importer->last_common_uid_found) {
                /* a) uid <= last_common_uid for flag changes and expunges.
@@ -2437,6 +2441,8 @@ int dsync_mailbox_import_mail(struct dsync_mailbox_importer *importer,
 
        if (importer->failed)
                return -1;
+       if (importer->require_full_resync)
+               return 0;
 
        imp_debug(importer, "Import mail body for GUID=%s UID=%u",
                  mail->guid, mail->uid);
@@ -2750,6 +2756,7 @@ int dsync_mailbox_import_deinit(struct dsync_mailbox_importer **_importer,
                                uint64_t *last_common_pvt_modseq_r,
                                uint32_t *last_messages_count_r,
                                bool *changes_during_sync_r,
+                               bool *require_full_resync_r,
                                enum mail_error *error_r)
 {
        struct dsync_mailbox_importer *importer = *_importer;
@@ -2758,8 +2765,9 @@ int dsync_mailbox_import_deinit(struct dsync_mailbox_importer **_importer,
 
        *_importer = NULL;
        *changes_during_sync_r = FALSE;
+       *require_full_resync_r = importer->require_full_resync;
 
-       if (!success && !importer->failed) {
+       if ((!success || importer->require_full_resync) && !importer->failed) {
                importer->mail_error = MAIL_ERROR_TEMP;
                importer->failed = TRUE;
        }
index d3603ea62158ad663ff418e150132684adb1fb0d..8139d650edef4c790d13c56d251f5db6a9a47175 100644 (file)
@@ -49,6 +49,7 @@ int dsync_mailbox_import_deinit(struct dsync_mailbox_importer **importer,
                                uint64_t *last_common_pvt_modseq_r,
                                uint32_t *last_messages_count_r,
                                bool *changes_during_sync_r,
+                               bool *require_full_resync_r,
                                enum mail_error *error_r);
 
 const char *dsync_mailbox_import_get_proctitle(struct dsync_mailbox_importer *importer);