Mercurial > dovecot > core-2.2
changeset 15750:5a1fc3723371
dsync: Automatically figure out which mailboxes can sync with message GUIDs.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 11 Feb 2013 00:28:28 +0200 |
parents | 91f60f0d72df |
children | 45c39743f406 |
files | src/doveadm/dsync/doveadm-dsync.c src/doveadm/dsync/dsync-brain-mailbox.c src/doveadm/dsync/dsync-brain-mails.c src/doveadm/dsync/dsync-brain-private.h src/doveadm/dsync/dsync-brain.c src/doveadm/dsync/dsync-brain.h src/doveadm/dsync/dsync-ibc-stream.c src/doveadm/dsync/dsync-mailbox.h |
diffstat | 8 files changed, 62 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/src/doveadm/dsync/doveadm-dsync.c Mon Feb 11 00:26:15 2013 +0200 +++ b/src/doveadm/dsync/doveadm-dsync.c Mon Feb 11 00:28:28 2013 +0200 @@ -419,8 +419,7 @@ remote_error_input, ctx); } - brain_flags = DSYNC_BRAIN_FLAG_MAILS_HAVE_GUIDS | - DSYNC_BRAIN_FLAG_SEND_MAIL_REQUESTS; + brain_flags = DSYNC_BRAIN_FLAG_SEND_MAIL_REQUESTS; if (ctx->sync_all_namespaces) brain_flags |= DSYNC_BRAIN_FLAG_SYNC_ALL_NAMESPACES;
--- a/src/doveadm/dsync/dsync-brain-mailbox.c Mon Feb 11 00:26:15 2013 +0200 +++ b/src/doveadm/dsync/dsync-brain-mailbox.c Mon Feb 11 00:28:28 2013 +0200 @@ -136,45 +136,9 @@ } } -int dsync_brain_sync_mailbox_open(struct dsync_brain *brain) -{ - enum dsync_mailbox_exporter_flags exporter_flags = 0; - uint32_t last_common_uid, highest_wanted_uid; - uint64_t last_common_modseq, last_common_pvt_modseq; - - i_assert(brain->log_scan == NULL); - - last_common_uid = brain->mailbox_state.last_common_uid; - last_common_modseq = brain->mailbox_state.last_common_modseq; - last_common_pvt_modseq = brain->mailbox_state.last_common_pvt_modseq; - highest_wanted_uid = last_common_uid == 0 ? - (uint32_t)-1 : last_common_uid; - if (dsync_transaction_log_scan_init(brain->box->view, - brain->box->view_pvt, - highest_wanted_uid, - last_common_modseq, - last_common_pvt_modseq, - &brain->log_scan) < 0) { - i_error("Failed to read transaction log for mailbox %s", - mailbox_get_vname(brain->box)); - brain->failed = TRUE; - return -1; - } - - if (!brain->mail_requests) - exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_AUTO_EXPORT_MAILS; - if (brain->mails_have_guids) - exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_MAILS_HAVE_GUIDS; - - brain->box_exporter = brain->backup_recv ? NULL : - dsync_mailbox_export_init(brain->box, brain->log_scan, - last_common_uid, - exporter_flags); - return 0; -} - -void dsync_brain_sync_mailbox_init_remote(struct dsync_brain *brain, - const struct dsync_mailbox *remote_dsync_box) +static void +dsync_brain_sync_mailbox_init_remote(struct dsync_brain *brain, + const struct dsync_mailbox *remote_dsync_box) { enum dsync_mailbox_import_flags import_flags = 0; const struct dsync_mailbox_state *state; @@ -221,6 +185,46 @@ import_flags); } +int dsync_brain_sync_mailbox_open(struct dsync_brain *brain, + const struct dsync_mailbox *remote_dsync_box) +{ + enum dsync_mailbox_exporter_flags exporter_flags = 0; + uint32_t last_common_uid, highest_wanted_uid; + uint64_t last_common_modseq, last_common_pvt_modseq; + + i_assert(brain->log_scan == NULL); + + last_common_uid = brain->mailbox_state.last_common_uid; + last_common_modseq = brain->mailbox_state.last_common_modseq; + last_common_pvt_modseq = brain->mailbox_state.last_common_pvt_modseq; + highest_wanted_uid = last_common_uid == 0 ? + (uint32_t)-1 : last_common_uid; + if (dsync_transaction_log_scan_init(brain->box->view, + brain->box->view_pvt, + highest_wanted_uid, + last_common_modseq, + last_common_pvt_modseq, + &brain->log_scan) < 0) { + i_error("Failed to read transaction log for mailbox %s", + mailbox_get_vname(brain->box)); + brain->failed = TRUE; + return -1; + } + + if (!brain->mail_requests) + exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_AUTO_EXPORT_MAILS; + if (brain->local_dsync_box.have_guids && + remote_dsync_box->have_guids) + exporter_flags |= DSYNC_MAILBOX_EXPORTER_FLAG_MAILS_HAVE_GUIDS; + + brain->box_exporter = brain->backup_recv ? NULL : + dsync_mailbox_export_init(brain->box, brain->log_scan, + last_common_uid, + exporter_flags); + dsync_brain_sync_mailbox_init_remote(brain, remote_dsync_box); + return 0; +} + void dsync_brain_sync_mailbox_deinit(struct dsync_brain *brain) { i_assert(brain->box != NULL); @@ -294,6 +298,7 @@ dsync_box_r->highest_modseq = status.highest_modseq; dsync_box_r->highest_pvt_modseq = status.highest_pvt_modseq; dsync_box_r->cache_fields = *metadata.cache_fields; + dsync_box_r->have_guids = status.have_guids; return 1; } @@ -626,8 +631,8 @@ /* start export/import */ dsync_brain_sync_mailbox_init(brain, box, &local_dsync_box, FALSE); - if (dsync_brain_sync_mailbox_open(brain) == 0) - dsync_brain_sync_mailbox_init_remote(brain, dsync_box); + if (dsync_brain_sync_mailbox_open(brain, dsync_box) < 0) + return TRUE; brain->state = DSYNC_STATE_SYNC_MAILS; return TRUE;
--- a/src/doveadm/dsync/dsync-brain-mails.c Mon Feb 11 00:26:15 2013 +0200 +++ b/src/doveadm/dsync/dsync-brain-mails.c Mon Feb 11 00:28:28 2013 +0200 @@ -53,9 +53,8 @@ dsync_brain_sync_mailbox_deinit(brain); return TRUE; } - if (dsync_brain_sync_mailbox_open(brain) < 0) + if (dsync_brain_sync_mailbox_open(brain, dsync_box) < 0) return TRUE; - dsync_brain_sync_mailbox_init_remote(brain, dsync_box); dsync_brain_sync_init_box_states(brain); return TRUE; }
--- a/src/doveadm/dsync/dsync-brain-private.h Mon Feb 11 00:26:15 2013 +0200 +++ b/src/doveadm/dsync/dsync-brain-private.h Mon Feb 11 00:28:28 2013 +0200 @@ -78,7 +78,6 @@ unsigned int master_brain:1; unsigned int mail_requests:1; - unsigned int mails_have_guids:1; unsigned int backup_send:1; unsigned int backup_recv:1; unsigned int debug:1; @@ -108,9 +107,8 @@ void dsync_brain_master_send_mailbox(struct dsync_brain *brain); bool dsync_brain_slave_recv_mailbox(struct dsync_brain *brain); -int dsync_brain_sync_mailbox_open(struct dsync_brain *brain); -void dsync_brain_sync_mailbox_init_remote(struct dsync_brain *brain, - const struct dsync_mailbox *remote_dsync_box); +int dsync_brain_sync_mailbox_open(struct dsync_brain *brain, + const struct dsync_mailbox *remote_dsync_box); bool dsync_brain_sync_mails(struct dsync_brain *brain); #endif
--- a/src/doveadm/dsync/dsync-brain.c Mon Feb 11 00:26:15 2013 +0200 +++ b/src/doveadm/dsync/dsync-brain.c Mon Feb 11 00:28:28 2013 +0200 @@ -72,8 +72,6 @@ { brain->mail_requests = (flags & DSYNC_BRAIN_FLAG_SEND_MAIL_REQUESTS) != 0; - brain->mails_have_guids = - (flags & DSYNC_BRAIN_FLAG_MAILS_HAVE_GUIDS) != 0; brain->backup_send = (flags & DSYNC_BRAIN_FLAG_BACKUP_SEND) != 0; brain->backup_recv = (flags & DSYNC_BRAIN_FLAG_BACKUP_RECV) != 0; brain->debug = (flags & DSYNC_BRAIN_FLAG_DEBUG) != 0;
--- a/src/doveadm/dsync/dsync-brain.h Mon Feb 11 00:26:15 2013 +0200 +++ b/src/doveadm/dsync/dsync-brain.h Mon Feb 11 00:28:28 2013 +0200 @@ -6,12 +6,11 @@ struct dsync_ibc; enum dsync_brain_flags { - DSYNC_BRAIN_FLAG_MAILS_HAVE_GUIDS = 0x01, - DSYNC_BRAIN_FLAG_SEND_MAIL_REQUESTS = 0x02, - DSYNC_BRAIN_FLAG_BACKUP_SEND = 0x04, - DSYNC_BRAIN_FLAG_BACKUP_RECV = 0x08, - DSYNC_BRAIN_FLAG_DEBUG = 0x10, - DSYNC_BRAIN_FLAG_SYNC_ALL_NAMESPACES = 0x20 + DSYNC_BRAIN_FLAG_SEND_MAIL_REQUESTS = 0x01, + DSYNC_BRAIN_FLAG_BACKUP_SEND = 0x02, + DSYNC_BRAIN_FLAG_BACKUP_RECV = 0x04, + DSYNC_BRAIN_FLAG_DEBUG = 0x08, + DSYNC_BRAIN_FLAG_SYNC_ALL_NAMESPACES = 0x10 }; enum dsync_brain_sync_type {
--- a/src/doveadm/dsync/dsync-ibc-stream.c Mon Feb 11 00:26:15 2013 +0200 +++ b/src/doveadm/dsync/dsync-ibc-stream.c Mon Feb 11 00:28:28 2013 +0200 @@ -61,7 +61,7 @@ { .name = "handshake", .chr = 'H', .optional_keys = "sync_ns_prefix sync_box sync_type debug sync_all_namespaces " - "mails_have_guids send_mail_requests backup_send backup_recv" + "send_mail_requests backup_send backup_recv" }, { .name = "mailbox_state", .chr = 'S', @@ -83,7 +83,7 @@ .chr = 'B', .required_keys = "mailbox_guid uid_validity uid_next messages_count " "first_recent_uid highest_modseq highest_pvt_modseq", - .optional_keys = "mailbox_lost cache_fields" + .optional_keys = "mailbox_lost cache_fields have_guids" }, { .name = "mail_change", .chr = 'C', @@ -533,8 +533,6 @@ } i_assert(sync_type[0] != '\0'); dsync_serializer_encode_add(encoder, "sync_type", sync_type); - if ((set->brain_flags & DSYNC_BRAIN_FLAG_MAILS_HAVE_GUIDS) != 0) - dsync_serializer_encode_add(encoder, "mails_have_guids", ""); if ((set->brain_flags & DSYNC_BRAIN_FLAG_SEND_MAIL_REQUESTS) != 0) dsync_serializer_encode_add(encoder, "send_mail_requests", ""); if ((set->brain_flags & DSYNC_BRAIN_FLAG_BACKUP_SEND) != 0) @@ -595,8 +593,6 @@ return DSYNC_IBC_RECV_RET_TRYAGAIN; } } - if (dsync_deserializer_decode_try(decoder, "mails_have_guids", &value)) - set->brain_flags |= DSYNC_BRAIN_FLAG_MAILS_HAVE_GUIDS; if (dsync_deserializer_decode_try(decoder, "send_mail_requests", &value)) set->brain_flags |= DSYNC_BRAIN_FLAG_SEND_MAIL_REQUESTS; if (dsync_deserializer_decode_try(decoder, "backup_send", &value)) @@ -997,6 +993,8 @@ if (dsync_box->mailbox_lost) dsync_serializer_encode_add(encoder, "mailbox_lost", ""); + if (dsync_box->have_guids) + dsync_serializer_encode_add(encoder, "have_guids", ""); dsync_serializer_encode_add(encoder, "uid_validity", dec2str(dsync_box->uid_validity)); dsync_serializer_encode_add(encoder, "uid_next", @@ -1095,6 +1093,8 @@ if (dsync_deserializer_decode_try(decoder, "mailbox_lost", &value)) box->mailbox_lost = TRUE; + if (dsync_deserializer_decode_try(decoder, "have_guids", &value)) + box->have_guids = TRUE; value = dsync_deserializer_decode_get(decoder, "uid_validity"); if (str_to_uint32(value, &box->uid_validity) < 0) { dsync_ibc_input_error(ibc, decoder, "Invalid uid_validity");
--- a/src/doveadm/dsync/dsync-mailbox.h Mon Feb 11 00:26:15 2013 +0200 +++ b/src/doveadm/dsync/dsync-mailbox.h Mon Feb 11 00:28:28 2013 +0200 @@ -8,6 +8,7 @@ struct dsync_mailbox { guid_128_t mailbox_guid; bool mailbox_lost; + bool have_guids; uint32_t uid_validity, uid_next, messages_count, first_recent_uid; uint64_t highest_modseq, highest_pvt_modseq;