annotate src/doveadm/dsync/dsync-mailbox.h @ 22715:20415dd0b85a

dsync: Add per-mailbox sync lock that is always used. Both importing and exporting gets the lock before they even sync the mailbox. The lock is kept until the import/export finishes. This guarantees that no matter how dsync is run, two dsyncs can't be working on the same mailbox at the same time. This lock is in addition to the optional per-user lock enabled by the -l parameter. If the -l parameter is used, the same lock timeout is used for the per-mailbox lock. Otherwise 30s timeout is used. This should help to avoid email duplication when replication is enabled for public namespaces, and maybe in some other rare situations as well.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 28 Dec 2017 14:10:23 +0200
parents 1f8b784712e1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14584
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 #ifndef DSYNC_MAILBOX_H
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2 #define DSYNC_MAILBOX_H
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "mail-storage.h"
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5
22715
20415dd0b85a dsync: Add per-mailbox sync lock that is always used.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22494
diff changeset
6 struct dsync_brain;
20415dd0b85a dsync: Add per-mailbox sync lock that is always used.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22494
diff changeset
7
14584
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 /* Mailbox that is going to be synced. Its name was already sent in the
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 mailbox tree. */
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 struct dsync_mailbox {
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 guid_128_t mailbox_guid;
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 bool mailbox_lost;
22494
1f8b784712e1 dsync: Ignore missing remote mailbox when doing unidirectional sync
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 16977
diff changeset
13 bool mailbox_ignore;
16977
8a7ecddca4ad dsync: Support syncing storages with 128bit GUIDs <-> string GUIDs.
Timo Sirainen <tss@iki.fi>
parents: 16376
diff changeset
14 bool have_guids, have_save_guids, have_only_guid128;
14584
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 uint32_t uid_validity, uid_next, messages_count, first_recent_uid;
15496
5d90e2aa1ba8 dsync: Use private modseqs to support syncing private flags in shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 14584
diff changeset
17 uint64_t highest_modseq, highest_pvt_modseq;
14584
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 ARRAY_TYPE(mailbox_cache_field) cache_fields;
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 };
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20
16025
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
21 struct dsync_mailbox_attribute {
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
22 enum mail_attribute_type type;
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
23 const char *key;
16052
0e5a359b7b7f lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents: 16025
diff changeset
24 /* if both values are NULL = not looked up yet / deleted */
0e5a359b7b7f lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents: 16025
diff changeset
25 const char *value;
0e5a359b7b7f lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents: 16025
diff changeset
26 struct istream *value_stream;
16025
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
27
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
28 time_t last_change; /* 0 = unknown */
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
29 uint64_t modseq; /* 0 = unknown */
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
30
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
31 bool deleted; /* attribute is known to have been deleted */
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
32 bool exported; /* internally used by exporting */
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
33 };
16052
0e5a359b7b7f lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents: 16025
diff changeset
34 #define DSYNC_ATTR_HAS_VALUE(attr) \
0e5a359b7b7f lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents: 16025
diff changeset
35 ((attr)->value != NULL || (attr)->value_stream != NULL)
16025
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
36
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
37 void dsync_mailbox_attribute_dup(pool_t pool,
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
38 const struct dsync_mailbox_attribute *src,
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
39 struct dsync_mailbox_attribute *dest_r);
c6082de4bf5b dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents: 15750
diff changeset
40
22715
20415dd0b85a dsync: Add per-mailbox sync lock that is always used.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22494
diff changeset
41 int dsync_mailbox_lock(struct dsync_brain *brain, struct mailbox *box,
20415dd0b85a dsync: Add per-mailbox sync lock that is always used.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22494
diff changeset
42 struct file_lock **lock_r);
20415dd0b85a dsync: Add per-mailbox sync lock that is always used.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22494
diff changeset
43
14584
b2076acc3715 Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 #endif