# HG changeset patch # User Timo Sirainen # Date 1384703945 -7200 # Node ID 8a7ecddca4ad42c9ae8675a9909fba5fbb94679e # Parent a04c7365299e7963553a80aa93dbc193a2529f48 dsync: Support syncing storages with 128bit GUIDs <-> string GUIDs. diff -r a04c7365299e -r 8a7ecddca4ad src/doveadm/dsync/dsync-brain-mailbox.c --- a/src/doveadm/dsync/dsync-brain-mailbox.c Sun Nov 17 17:15:42 2013 +0200 +++ b/src/doveadm/dsync/dsync-brain-mailbox.c Sun Nov 17 17:59:05 2013 +0200 @@ -184,6 +184,9 @@ (remote_dsync_box->have_save_guids || (brain->backup_recv && remote_dsync_box->have_guids))) import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS; + if (brain->local_dsync_box.have_only_guid128 || + remote_dsync_box->have_only_guid128) + import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_MAILS_USE_GUID128; brain->box_importer = brain->backup_send ? NULL : dsync_mailbox_import_init(brain->box, brain->log_scan, diff -r a04c7365299e -r 8a7ecddca4ad src/doveadm/dsync/dsync-ibc-stream.c --- a/src/doveadm/dsync/dsync-ibc-stream.c Sun Nov 17 17:15:42 2013 +0200 +++ b/src/doveadm/dsync/dsync-ibc-stream.c Sun Nov 17 17:59:05 2013 +0200 @@ -98,7 +98,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 have_guids have_save_guids" + .optional_keys = "mailbox_lost cache_fields have_guids have_save_guids have_only_guid128" }, { .name = "mailbox_attribute", .chr = 'A', @@ -1178,6 +1178,8 @@ dsync_serializer_encode_add(encoder, "have_guids", ""); if (dsync_box->have_save_guids) dsync_serializer_encode_add(encoder, "have_save_guids", ""); + if (dsync_box->have_only_guid128) + dsync_serializer_encode_add(encoder, "have_only_guid128", ""); dsync_serializer_encode_add(encoder, "uid_validity", dec2str(dsync_box->uid_validity)); dsync_serializer_encode_add(encoder, "uid_next", @@ -1281,6 +1283,8 @@ if (dsync_deserializer_decode_try(decoder, "have_save_guids", &value) || (box->have_guids && ibc->minor_version < DSYNC_PROTOCOL_MINOR_HAVE_SAVE_GUID)) box->have_save_guids = TRUE; + if (dsync_deserializer_decode_try(decoder, "have_only_guid128", &value)) + box->have_only_guid128 = 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"); diff -r a04c7365299e -r 8a7ecddca4ad src/doveadm/dsync/dsync-mailbox-import.c --- a/src/doveadm/dsync/dsync-mailbox-import.c Sun Nov 17 17:15:42 2013 +0200 +++ b/src/doveadm/dsync/dsync-mailbox-import.c Sun Nov 17 17:59:05 2013 +0200 @@ -103,6 +103,7 @@ unsigned int master_brain:1; unsigned int revert_local_changes:1; unsigned int mails_have_guids:1; + unsigned int mails_use_guid128:1; }; static void dsync_mailbox_save_newmails(struct dsync_mailbox_importer *importer, @@ -218,6 +219,8 @@ importer->debug = (flags & DSYNC_MAILBOX_IMPORT_FLAG_DEBUG) != 0; importer->mails_have_guids = (flags & DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS) != 0; + importer->mails_use_guid128 = + (flags & DSYNC_MAILBOX_IMPORT_FLAG_MAILS_USE_GUID128) != 0; mailbox_get_open_status(importer->box, STATUS_UIDNEXT | STATUS_HIGHESTMODSEQ | STATUS_HIGHESTPVTMODSEQ, @@ -463,12 +466,14 @@ } static bool -dsync_mail_change_guid_equals(const struct dsync_mail_change *change, +dsync_mail_change_guid_equals(struct dsync_mailbox_importer *importer, + const struct dsync_mail_change *change, const char *guid, const char **cmp_guid_r) { guid_128_t guid_128, change_guid_128; - if (change->type != DSYNC_MAIL_CHANGE_TYPE_EXPUNGE) { + if (change->type != DSYNC_MAIL_CHANGE_TYPE_EXPUNGE && + !importer->mails_use_guid128) { if (cmp_guid_r != NULL) *cmp_guid_r = change->guid; return strcmp(change->guid, guid) == 0; @@ -480,7 +485,7 @@ mail_generate_guid_128_hash(guid, guid_128); if (memcmp(change_guid_128, guid_128, GUID_128_SIZE) != 0) { if (cmp_guid_r != NULL) { - *cmp_guid_r = t_strdup_printf("%s(expunged, orig=%s)", + *cmp_guid_r = t_strdup_printf("%s(guid128, orig=%s)", binary_to_hex(change_guid_128, sizeof(change_guid_128)), change->guid); } @@ -760,7 +765,7 @@ dsync_mail_error(importer, importer->mail, "GUID"); return FALSE; } - if (!dsync_mail_change_guid_equals(change, guid, &cmp_guid)) { + if (!dsync_mail_change_guid_equals(importer, change, guid, &cmp_guid)) { dsync_import_unexpected_state(importer, t_strdup_printf( "Unexpected GUID mismatch for UID=%u: %s != %s", change->uid, guid, cmp_guid)); @@ -778,7 +783,8 @@ if (change->guid == NULL || change->guid[0] == '\0' || importer->cur_guid[0] == '\0') return TRUE; - if (!dsync_mail_change_guid_equals(change, importer->cur_guid, &cmp_guid)) { + if (!dsync_mail_change_guid_equals(importer, change, + importer->cur_guid, &cmp_guid)) { dsync_import_unexpected_state(importer, t_strdup_printf( "Unexpected GUID mismatch (2) for UID=%u: %s != %s", change->uid, importer->cur_guid, cmp_guid)); @@ -1294,7 +1300,8 @@ if (*change->guid != '\0' && *importer->cur_guid != '\0') { /* we have GUIDs, verify them */ - if (dsync_mail_change_guid_equals(change, importer->cur_guid, NULL)) + if (dsync_mail_change_guid_equals(importer, change, + importer->cur_guid, NULL)) return 1; else return 0; @@ -1343,7 +1350,8 @@ return FALSE; i_assert(local_change->type == DSYNC_MAIL_CHANGE_TYPE_EXPUNGE); - if (dsync_mail_change_guid_equals(local_change, change->guid, NULL)) + if (dsync_mail_change_guid_equals(importer, local_change, + change->guid, NULL)) importer->last_common_uid = change->uid; else if (change->type != DSYNC_MAIL_CHANGE_TYPE_EXPUNGE) dsync_mailbox_common_uid_found(importer); diff -r a04c7365299e -r 8a7ecddca4ad src/doveadm/dsync/dsync-mailbox-import.h --- a/src/doveadm/dsync/dsync-mailbox-import.h Sun Nov 17 17:15:42 2013 +0200 +++ b/src/doveadm/dsync/dsync-mailbox-import.h Sun Nov 17 17:59:05 2013 +0200 @@ -6,7 +6,8 @@ DSYNC_MAILBOX_IMPORT_FLAG_WANT_MAIL_REQUESTS = 0x02, DSYNC_MAILBOX_IMPORT_FLAG_REVERT_LOCAL_CHANGES = 0x04, DSYNC_MAILBOX_IMPORT_FLAG_DEBUG = 0x08, - DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS = 0x10 + DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS = 0x10, + DSYNC_MAILBOX_IMPORT_FLAG_MAILS_USE_GUID128 = 0x20 }; struct mailbox; diff -r a04c7365299e -r 8a7ecddca4ad src/doveadm/dsync/dsync-mailbox.h --- a/src/doveadm/dsync/dsync-mailbox.h Sun Nov 17 17:15:42 2013 +0200 +++ b/src/doveadm/dsync/dsync-mailbox.h Sun Nov 17 17:59:05 2013 +0200 @@ -8,7 +8,7 @@ struct dsync_mailbox { guid_128_t mailbox_guid; bool mailbox_lost; - bool have_guids, have_save_guids; + bool have_guids, have_save_guids, have_only_guid128; uint32_t uid_validity, uid_next, messages_count, first_recent_uid; uint64_t highest_modseq, highest_pvt_modseq; diff -r a04c7365299e -r 8a7ecddca4ad src/lib-storage/mail-storage-private.h --- a/src/lib-storage/mail-storage-private.h Sun Nov 17 17:15:42 2013 +0200 +++ b/src/lib-storage/mail-storage-private.h Sun Nov 17 17:59:05 2013 +0200 @@ -72,7 +72,10 @@ MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_SAVE_GUIDS = 0x80, /* message content can be unstructured binary data (e.g. zlib plugin is allowed to compress/decompress mails) */ - MAIL_STORAGE_CLASS_FLAG_BINARY_DATA = 0x100 + MAIL_STORAGE_CLASS_FLAG_BINARY_DATA = 0x100, + /* Message GUIDs can only be 128bit (always set + mailbox_status.have_only_guid128) */ + MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_GUID128 = 0x200 }; struct mail_binary_cache { diff -r a04c7365299e -r 8a7ecddca4ad src/lib-storage/mail-storage.c --- a/src/lib-storage/mail-storage.c Sun Nov 17 17:15:42 2013 +0200 +++ b/src/lib-storage/mail-storage.c Sun Nov 17 17:59:05 2013 +0200 @@ -1502,6 +1502,8 @@ status_r->have_guids = TRUE; if ((box->storage->class_flags & MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_SAVE_GUIDS) != 0) status_r->have_save_guids = TRUE; + if ((box->storage->class_flags & MAIL_STORAGE_CLASS_FLAG_HAVE_MAIL_GUID128) != 0) + status_r->have_only_guid128 = TRUE; } int mailbox_get_status(struct mailbox *box, diff -r a04c7365299e -r 8a7ecddca4ad src/lib-storage/mail-storage.h --- a/src/lib-storage/mail-storage.h Sun Nov 17 17:15:42 2013 +0200 +++ b/src/lib-storage/mail-storage.h Sun Nov 17 17:59:05 2013 +0200 @@ -282,6 +282,8 @@ unsigned int have_guids:1; /* mailbox_save_set_guid() works (always set) */ unsigned int have_save_guids:1; + /* GUIDs are always 128bit (always set) */ + unsigned int have_only_guid128:1; }; struct mailbox_cache_field {