Mercurial > dovecot > core-2.2
annotate src/doveadm/dsync/dsync-brain.c @ 18177:f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
If one side has old mails that don't exist on the other side, they are
ignored (not synced and not deleted).
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 19 Jan 2015 23:43:37 +0200 |
parents | 3009a1a6f6d5 |
children | 39d00448490f |
rev | line source |
---|---|
18137 | 1 /* Copyright (c) 2013-2015 Dovecot authors, see the included COPYING file */ |
9559 | 2 |
3 #include "lib.h" | |
4 #include "array.h" | |
5 #include "hash.h" | |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
6 #include "hostpid.h" |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
7 #include "str.h" |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
8 #include "process-title.h" |
16540
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
9 #include "settings-parser.h" |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
10 #include "master-service.h" |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
11 #include "master-service-settings.h" |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
12 #include "mail-namespace.h" |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
13 #include "dsync-mailbox-tree.h" |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
14 #include "dsync-ibc.h" |
9559 | 15 #include "dsync-brain-private.h" |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
16 #include "dsync-mailbox-import.h" |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
17 #include "dsync-mailbox-export.h" |
9559 | 18 |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
19 #include <sys/stat.h> |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
20 |
16538
83bea7e1f136
dsync: State names were wrong in debug/error messages.
Timo Sirainen <tss@iki.fi>
parents:
16503
diff
changeset
|
21 static const char *dsync_state_names[] = { |
83bea7e1f136
dsync: State names were wrong in debug/error messages.
Timo Sirainen <tss@iki.fi>
parents:
16503
diff
changeset
|
22 "master_recv_handshake", |
83bea7e1f136
dsync: State names were wrong in debug/error messages.
Timo Sirainen <tss@iki.fi>
parents:
16503
diff
changeset
|
23 "slave_recv_handshake", |
83bea7e1f136
dsync: State names were wrong in debug/error messages.
Timo Sirainen <tss@iki.fi>
parents:
16503
diff
changeset
|
24 "master_send_last_common", |
83bea7e1f136
dsync: State names were wrong in debug/error messages.
Timo Sirainen <tss@iki.fi>
parents:
16503
diff
changeset
|
25 "slave_recv_last_common", |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
26 "send_mailbox_tree", |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
27 "send_mailbox_tree_deletes", |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
28 "recv_mailbox_tree", |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
29 "recv_mailbox_tree_deletes", |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
30 "master_send_mailbox", |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
31 "slave_recv_mailbox", |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
32 "sync_mails", |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
33 "done" |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
34 }; |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
35 |
17271
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
36 static void dsync_brain_mailbox_states_dump(struct dsync_brain *brain); |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
37 |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
38 static const char *dsync_brain_get_proctitle(struct dsync_brain *brain) |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
39 { |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
40 string_t *str = t_str_new(128); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
41 const char *import_title, *export_title; |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
42 |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
43 str_append_c(str, '['); |
17279
fac4e7320676
dsync: If dsync was started via doveadm-server, show the remote client's IP address in ps output.
Timo Sirainen <tss@iki.fi>
parents:
17271
diff
changeset
|
44 if (brain->process_title_prefix != NULL) |
fac4e7320676
dsync: If dsync was started via doveadm-server, show the remote client's IP address in ps output.
Timo Sirainen <tss@iki.fi>
parents:
17271
diff
changeset
|
45 str_append(str, brain->process_title_prefix); |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
46 str_append(str, brain->user->username); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
47 if (brain->box == NULL) { |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
48 str_append_c(str, ' '); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
49 str_append(str, dsync_state_names[brain->state]); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
50 } else { |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
51 str_append_c(str, ' '); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
52 str_append(str, mailbox_get_vname(brain->box)); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
53 import_title = brain->box_importer == NULL ? "" : |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
54 dsync_mailbox_import_get_proctitle(brain->box_importer); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
55 export_title = brain->box_exporter == NULL ? "" : |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
56 dsync_mailbox_export_get_proctitle(brain->box_exporter); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
57 if (import_title[0] == '\0' && export_title[0] == '\0') { |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
58 str_printfa(str, " send:%s recv:%s", |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
59 dsync_box_state_names[brain->box_send_state], |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
60 dsync_box_state_names[brain->box_recv_state]); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
61 } else { |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
62 if (import_title[0] != '\0') { |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
63 str_append(str, " import:"); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
64 str_append(str, import_title); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
65 } |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
66 if (export_title[0] != '\0') { |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
67 str_append(str, " export:"); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
68 str_append(str, export_title); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
69 } |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
70 } |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
71 } |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
72 str_append_c(str, ']'); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
73 return str_c(str); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
74 } |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
75 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
76 static void dsync_brain_run_io(void *context) |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
77 { |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
78 struct dsync_brain *brain = context; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
79 bool changed, try_pending; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
80 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
81 if (dsync_ibc_has_failed(brain->ibc)) { |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
82 io_loop_stop(current_ioloop); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
83 brain->failed = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
84 return; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
85 } |
11687
b37c85676f8e
dsync: When -v parameter is given, show progress counter of saving new messages.
Timo Sirainen <tss@iki.fi>
parents:
11684
diff
changeset
|
86 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
87 try_pending = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
88 do { |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
89 if (!dsync_brain_run(brain, &changed)) { |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
90 io_loop_stop(current_ioloop); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
91 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
92 } |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
93 if (changed) |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
94 try_pending = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
95 else if (try_pending) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
96 if (dsync_ibc_has_pending_data(brain->ibc)) |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
97 changed = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
98 try_pending = FALSE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
99 } |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
100 } while (changed); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
101 } |
11727
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
102 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
103 static struct dsync_brain * |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
104 dsync_brain_common_init(struct mail_user *user, struct dsync_ibc *ibc) |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
105 { |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
106 struct dsync_brain *brain; |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
107 const struct master_service_settings *service_set; |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
108 pool_t pool; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
109 |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
110 service_set = master_service_settings_get(master_service); |
16801
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
111 mail_user_ref(user); |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
112 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
113 pool = pool_alloconly_create("dsync brain", 10240); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
114 brain = p_new(pool, struct dsync_brain, 1); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
115 brain->pool = pool; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
116 brain->user = user; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
117 brain->ibc = ibc; |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
118 brain->sync_type = DSYNC_BRAIN_SYNC_TYPE_UNKNOWN; |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
119 brain->lock_fd = -1; |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
120 brain->verbose_proctitle = service_set->verbose_proctitle; |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
121 hash_table_create(&brain->mailbox_states, pool, 0, |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
122 guid_128_hash, guid_128_cmp); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
123 p_array_init(&brain->remote_mailbox_states, pool, 64); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
124 return brain; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
125 } |
9559 | 126 |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
127 static void |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
128 dsync_brain_set_flags(struct dsync_brain *brain, enum dsync_brain_flags flags) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
129 { |
15744
b4e2b3b54f0a
dsync: Renamed "guid_requests" to "mail_requests"
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
130 brain->mail_requests = |
b4e2b3b54f0a
dsync: Renamed "guid_requests" to "mail_requests"
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
131 (flags & DSYNC_BRAIN_FLAG_SEND_MAIL_REQUESTS) != 0; |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
132 brain->backup_send = (flags & DSYNC_BRAIN_FLAG_BACKUP_SEND) != 0; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
133 brain->backup_recv = (flags & DSYNC_BRAIN_FLAG_BACKUP_RECV) != 0; |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15355
diff
changeset
|
134 brain->debug = (flags & DSYNC_BRAIN_FLAG_DEBUG) != 0; |
15836
607758d425e7
dsync: Renamed -a parameter to -N. It also now skips invisible namespaces.
Timo Sirainen <tss@iki.fi>
parents:
15825
diff
changeset
|
135 brain->sync_visible_namespaces = |
607758d425e7
dsync: Renamed -a parameter to -N. It also now skips invisible namespaces.
Timo Sirainen <tss@iki.fi>
parents:
15825
diff
changeset
|
136 (flags & DSYNC_BRAIN_FLAG_SYNC_VISIBLE_NAMESPACES) != 0; |
16084
38774adaddaf
dsync: -m '' parameter now syncs mailbox list, but no actual mails.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
137 brain->no_mail_sync = (flags & DSYNC_BRAIN_FLAG_NO_MAIL_SYNC) != 0; |
16561
0144704e1b99
dsync: Added -1 parameter to do a "one way sync" without reverting changes.
Timo Sirainen <tss@iki.fi>
parents:
16541
diff
changeset
|
138 brain->no_backup_overwrite = |
0144704e1b99
dsync: Added -1 parameter to do a "one way sync" without reverting changes.
Timo Sirainen <tss@iki.fi>
parents:
16541
diff
changeset
|
139 (flags & DSYNC_BRAIN_FLAG_NO_BACKUP_OVERWRITE) != 0; |
17845
d2e1b3f6d13b
dsync: Added DSYNC_BRAIN_FLAG_NO_MAIL_PREFETCH to avoid opening mails unnecessarily.
Timo Sirainen <tss@iki.fi>
parents:
17800
diff
changeset
|
140 brain->no_mail_prefetch = |
d2e1b3f6d13b
dsync: Added DSYNC_BRAIN_FLAG_NO_MAIL_PREFETCH to avoid opening mails unnecessarily.
Timo Sirainen <tss@iki.fi>
parents:
17800
diff
changeset
|
141 (flags & DSYNC_BRAIN_FLAG_NO_MAIL_PREFETCH) != 0; |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
142 } |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
143 |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
144 struct dsync_brain * |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
145 dsync_brain_master_init(struct mail_user *user, struct dsync_ibc *ibc, |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
146 enum dsync_brain_sync_type sync_type, |
16396 | 147 enum dsync_brain_flags flags, |
148 const struct dsync_brain_settings *set) | |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
149 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
150 struct dsync_ibc_settings ibc_set; |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
151 struct dsync_brain *brain; |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
152 struct mail_namespace *const *nsp; |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
153 string_t *sync_ns_str = NULL; |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
154 const char *error; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
155 |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
156 i_assert(sync_type != DSYNC_BRAIN_SYNC_TYPE_UNKNOWN); |
16396 | 157 i_assert(sync_type != DSYNC_BRAIN_SYNC_TYPE_STATE || |
158 (set->state != NULL && *set->state != '\0')); | |
16538
83bea7e1f136
dsync: State names were wrong in debug/error messages.
Timo Sirainen <tss@iki.fi>
parents:
16503
diff
changeset
|
159 i_assert(N_ELEMENTS(dsync_state_names) == DSYNC_STATE_DONE+1); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
160 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
161 brain = dsync_brain_common_init(user, ibc); |
17279
fac4e7320676
dsync: If dsync was started via doveadm-server, show the remote client's IP address in ps output.
Timo Sirainen <tss@iki.fi>
parents:
17271
diff
changeset
|
162 brain->process_title_prefix = |
fac4e7320676
dsync: If dsync was started via doveadm-server, show the remote client's IP address in ps output.
Timo Sirainen <tss@iki.fi>
parents:
17271
diff
changeset
|
163 p_strdup(brain->pool, set->process_title_prefix); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
164 brain->sync_type = sync_type; |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
165 if (array_count(&set->sync_namespaces) > 0) { |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
166 sync_ns_str = t_str_new(128); |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
167 p_array_init(&brain->sync_namespaces, brain->pool, |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
168 array_count(&set->sync_namespaces)); |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
169 array_foreach(&set->sync_namespaces, nsp) { |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
170 str_append(sync_ns_str, (*nsp)->prefix); |
17219
f0b8cf119b7f
dsync: Fixed giving -n "" followed by other -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17200
diff
changeset
|
171 str_append_c(sync_ns_str, '\n'); |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
172 array_append(&brain->sync_namespaces, nsp, 1); |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
173 } |
17221
e75851b65900
dsync: Fix to previous commit to actually compile..
Timo Sirainen <tss@iki.fi>
parents:
17219
diff
changeset
|
174 str_delete(sync_ns_str, str_len(sync_ns_str)-1, 1); |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
175 } |
17800
eff79a80e0c9
dsync: Moved all doveadm-specific code to doveadm-dsync.c
Timo Sirainen <tss@iki.fi>
parents:
17377
diff
changeset
|
176 brain->alt_char = set->mailbox_alt_char == '\0' ? '_' : |
eff79a80e0c9
dsync: Moved all doveadm-specific code to doveadm-dsync.c
Timo Sirainen <tss@iki.fi>
parents:
17377
diff
changeset
|
177 set->mailbox_alt_char; |
18177
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
178 brain->sync_since_timestamp = set->sync_since_timestamp; |
16396 | 179 brain->sync_box = p_strdup(brain->pool, set->sync_box); |
16398
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16396
diff
changeset
|
180 brain->exclude_mailboxes = set->exclude_mailboxes == NULL ? NULL : |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16396
diff
changeset
|
181 p_strarray_dup(brain->pool, set->exclude_mailboxes); |
16396 | 182 memcpy(brain->sync_box_guid, set->sync_box_guid, |
183 sizeof(brain->sync_box_guid)); | |
184 brain->lock_timeout = set->lock_timeout_secs; | |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
185 brain->master_brain = TRUE; |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
186 dsync_brain_set_flags(brain, flags); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
187 |
17271
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
188 if (sync_type != DSYNC_BRAIN_SYNC_TYPE_STATE) |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
189 ; |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
190 else if (dsync_mailbox_states_import(brain->mailbox_states, brain->pool, |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
191 set->state, &error) < 0) { |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
192 hash_table_clear(brain->mailbox_states, FALSE); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
193 i_error("Saved sync state is invalid, " |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
194 "falling back to full sync: %s", error); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
195 brain->sync_type = sync_type = DSYNC_BRAIN_SYNC_TYPE_FULL; |
17271
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
196 } else { |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
197 if (brain->debug) { |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
198 i_debug("brain %c: Imported mailbox states:", |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
199 brain->master_brain ? 'M' : 'S'); |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
200 dsync_brain_mailbox_states_dump(brain); |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
201 } |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
202 } |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
203 dsync_brain_mailbox_trees_init(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
204 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
205 memset(&ibc_set, 0, sizeof(ibc_set)); |
15815
e7aabd79c9d5
dsync: Use full hostname+domain when comparing if hosts are different in locking.
Timo Sirainen <tss@iki.fi>
parents:
15782
diff
changeset
|
206 ibc_set.hostname = my_hostdomain(); |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
207 ibc_set.sync_ns_prefixes = sync_ns_str == NULL ? |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
208 NULL : str_c(sync_ns_str); |
16396 | 209 ibc_set.sync_box = set->sync_box; |
16398
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16396
diff
changeset
|
210 ibc_set.exclude_mailboxes = set->exclude_mailboxes; |
18177
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
211 ibc_set.sync_since_timestamp = set->sync_since_timestamp; |
16396 | 212 memcpy(ibc_set.sync_box_guid, set->sync_box_guid, |
16110
c51873a8e0d9
doveadm sync/backup: Added -g <guid> to sync only the specified mailbox (by GUID)
Timo Sirainen <tss@iki.fi>
parents:
16089
diff
changeset
|
213 sizeof(ibc_set.sync_box_guid)); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
214 ibc_set.sync_type = sync_type; |
16396 | 215 ibc_set.lock_timeout = set->lock_timeout_secs; |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
216 /* reverse the backup direction for the slave */ |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
217 ibc_set.brain_flags = flags & ~(DSYNC_BRAIN_FLAG_BACKUP_SEND | |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
218 DSYNC_BRAIN_FLAG_BACKUP_RECV); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
219 if ((flags & DSYNC_BRAIN_FLAG_BACKUP_SEND) != 0) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
220 ibc_set.brain_flags |= DSYNC_BRAIN_FLAG_BACKUP_RECV; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
221 else if ((flags & DSYNC_BRAIN_FLAG_BACKUP_RECV) != 0) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
222 ibc_set.brain_flags |= DSYNC_BRAIN_FLAG_BACKUP_SEND; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
223 dsync_ibc_send_handshake(ibc, &ibc_set); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
224 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
225 dsync_ibc_set_io_callback(ibc, dsync_brain_run_io, brain); |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
226 brain->state = DSYNC_STATE_MASTER_RECV_HANDSHAKE; |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
227 return brain; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
228 } |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
229 |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
230 struct dsync_brain * |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
231 dsync_brain_slave_init(struct mail_user *user, struct dsync_ibc *ibc, |
17279
fac4e7320676
dsync: If dsync was started via doveadm-server, show the remote client's IP address in ps output.
Timo Sirainen <tss@iki.fi>
parents:
17271
diff
changeset
|
232 bool local, const char *process_title_prefix) |
9559 | 233 { |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
234 struct dsync_ibc_settings ibc_set; |
9559 | 235 struct dsync_brain *brain; |
236 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
237 brain = dsync_brain_common_init(user, ibc); |
17279
fac4e7320676
dsync: If dsync was started via doveadm-server, show the remote client's IP address in ps output.
Timo Sirainen <tss@iki.fi>
parents:
17271
diff
changeset
|
238 brain->process_title_prefix = |
fac4e7320676
dsync: If dsync was started via doveadm-server, show the remote client's IP address in ps output.
Timo Sirainen <tss@iki.fi>
parents:
17271
diff
changeset
|
239 p_strdup(brain->pool, process_title_prefix); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
240 brain->state = DSYNC_STATE_SLAVE_RECV_HANDSHAKE; |
11734
ba9f33f9c6c3
dsync: If verbosity is enabled, log why desyncing was caused.
Timo Sirainen <tss@iki.fi>
parents:
11727
diff
changeset
|
241 |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
242 if (local) { |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
243 /* both master and slave are running within the same process, |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
244 update the proctitle only for master. */ |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
245 brain->verbose_proctitle = FALSE; |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
246 } |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
247 |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
248 memset(&ibc_set, 0, sizeof(ibc_set)); |
15815
e7aabd79c9d5
dsync: Use full hostname+domain when comparing if hosts are different in locking.
Timo Sirainen <tss@iki.fi>
parents:
15782
diff
changeset
|
249 ibc_set.hostname = my_hostdomain(); |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
250 dsync_ibc_send_handshake(ibc, &ibc_set); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
251 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
252 dsync_ibc_set_io_callback(ibc, dsync_brain_run_io, brain); |
9559 | 253 return brain; |
254 } | |
255 | |
16801
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
256 static void dsync_brain_purge(struct dsync_brain *brain) |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
257 { |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
258 struct mail_namespace *ns; |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
259 struct mail_storage *storage; |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
260 |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
261 for (ns = brain->user->namespaces; ns != NULL; ns = ns->next) { |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
262 if (!dsync_brain_want_namespace(brain, ns)) |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
263 continue; |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
264 |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
265 storage = mail_namespace_get_default_storage(ns); |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
266 if (mail_storage_purge(storage) < 0) { |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
267 i_error("Purging namespace '%s' failed: %s", ns->prefix, |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
268 mail_storage_get_last_error(storage, NULL)); |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
269 } |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
270 } |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
271 } |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
272 |
9559 | 273 int dsync_brain_deinit(struct dsync_brain **_brain) |
274 { | |
275 struct dsync_brain *brain = *_brain; | |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
276 int ret; |
11680
49b226835cd2
dsync: Another try at not increasing mailbox uidnext/highestmodseq on failure
Timo Sirainen <tss@iki.fi>
parents:
11677
diff
changeset
|
277 |
9559 | 278 *_brain = NULL; |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
279 |
15986
f6377e089dee
dsync: If I/O gets stalled, log the state in which it happened.
Timo Sirainen <tss@iki.fi>
parents:
15836
diff
changeset
|
280 if (dsync_ibc_has_timed_out(brain->ibc)) { |
f6377e089dee
dsync: If I/O gets stalled, log the state in which it happened.
Timo Sirainen <tss@iki.fi>
parents:
15836
diff
changeset
|
281 i_error("Timeout during state=%s%s", |
f6377e089dee
dsync: If I/O gets stalled, log the state in which it happened.
Timo Sirainen <tss@iki.fi>
parents:
15836
diff
changeset
|
282 dsync_state_names[brain->state], |
f6377e089dee
dsync: If I/O gets stalled, log the state in which it happened.
Timo Sirainen <tss@iki.fi>
parents:
15836
diff
changeset
|
283 brain->state != DSYNC_STATE_SYNC_MAILS ? "" : |
f6377e089dee
dsync: If I/O gets stalled, log the state in which it happened.
Timo Sirainen <tss@iki.fi>
parents:
15836
diff
changeset
|
284 t_strdup_printf(" (send=%s recv=%s)", |
f6377e089dee
dsync: If I/O gets stalled, log the state in which it happened.
Timo Sirainen <tss@iki.fi>
parents:
15836
diff
changeset
|
285 dsync_box_state_names[brain->box_send_state], |
f6377e089dee
dsync: If I/O gets stalled, log the state in which it happened.
Timo Sirainen <tss@iki.fi>
parents:
15836
diff
changeset
|
286 dsync_box_state_names[brain->box_recv_state])); |
f6377e089dee
dsync: If I/O gets stalled, log the state in which it happened.
Timo Sirainen <tss@iki.fi>
parents:
15836
diff
changeset
|
287 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
288 if (dsync_ibc_has_failed(brain->ibc) || |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
289 brain->state != DSYNC_STATE_DONE) |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
290 brain->failed = TRUE; |
15632
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
291 dsync_ibc_close_mail_streams(brain->ibc); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
292 |
16801
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
293 if (brain->purge && !brain->failed) |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
294 dsync_brain_purge(brain); |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
295 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
296 if (brain->box != NULL) |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
297 dsync_brain_sync_mailbox_deinit(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
298 if (brain->local_tree_iter != NULL) |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
299 dsync_mailbox_tree_iter_deinit(&brain->local_tree_iter); |
16541
07e314199f56
dsync: Don't crash at deinit when dsync fails early.
Timo Sirainen <tss@iki.fi>
parents:
16540
diff
changeset
|
300 if (brain->local_mailbox_tree != NULL) |
07e314199f56
dsync: Don't crash at deinit when dsync fails early.
Timo Sirainen <tss@iki.fi>
parents:
16540
diff
changeset
|
301 dsync_mailbox_tree_deinit(&brain->local_mailbox_tree); |
07e314199f56
dsync: Don't crash at deinit when dsync fails early.
Timo Sirainen <tss@iki.fi>
parents:
16540
diff
changeset
|
302 if (brain->remote_mailbox_tree != NULL) |
07e314199f56
dsync: Don't crash at deinit when dsync fails early.
Timo Sirainen <tss@iki.fi>
parents:
16540
diff
changeset
|
303 dsync_mailbox_tree_deinit(&brain->remote_mailbox_tree); |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
304 if (brain->mailbox_states_iter != NULL) |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
305 hash_table_iterate_deinit(&brain->mailbox_states_iter); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
306 hash_table_destroy(&brain->mailbox_states); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
307 |
17377
a21ac1261487
dsync: mailbox_metadata.cache_fields must be copied to permanent memory.
Timo Sirainen <tss@iki.fi>
parents:
17282
diff
changeset
|
308 if (brain->dsync_box_pool != NULL) |
a21ac1261487
dsync: mailbox_metadata.cache_fields must be copied to permanent memory.
Timo Sirainen <tss@iki.fi>
parents:
17282
diff
changeset
|
309 pool_unref(&brain->dsync_box_pool); |
a21ac1261487
dsync: mailbox_metadata.cache_fields must be copied to permanent memory.
Timo Sirainen <tss@iki.fi>
parents:
17282
diff
changeset
|
310 |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
311 if (brain->lock_fd != -1) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
312 /* unlink the lock file before it gets unlocked */ |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
313 if (unlink(brain->lock_path) < 0) |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
314 i_error("unlink(%s) failed: %m", brain->lock_path); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
315 file_lock_free(&brain->lock); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
316 i_close_fd(&brain->lock_fd); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
317 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
318 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
319 ret = brain->failed ? -1 : 0; |
16801
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
320 mail_user_unref(&brain->user); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
321 pool_unref(&brain->pool); |
9559 | 322 return ret; |
323 } | |
324 | |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
325 static int |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
326 dsync_brain_lock(struct dsync_brain *brain, const char *remote_hostname) |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
327 { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
328 struct stat st1, st2; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
329 const char *home; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
330 int ret; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
331 |
15825
df29194c1ab6
dsync: Fix to checking which side should do the locking.
Timo Sirainen <tss@iki.fi>
parents:
15816
diff
changeset
|
332 if ((ret = strcmp(remote_hostname, my_hostdomain())) < 0) { |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
333 /* locking done by remote */ |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
334 return 0; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
335 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
336 if (ret == 0 && !brain->master_brain) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
337 /* running dsync within the same server. |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
338 locking done by master brain. */ |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
339 return 0; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
340 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
341 |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
342 if ((ret = mail_user_get_home(brain->user, &home)) < 0) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
343 i_error("Couldn't look up user's home dir"); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
344 return -1; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
345 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
346 if (ret == 0) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
347 i_error("User has no home directory"); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
348 return -1; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
349 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
350 |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
351 brain->lock_path = p_strconcat(brain->pool, home, |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
352 "/"DSYNC_LOCK_FILENAME, NULL); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
353 for (;;) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
354 brain->lock_fd = creat(brain->lock_path, 0600); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
355 if (brain->lock_fd == -1) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
356 i_error("Couldn't create lock %s: %m", |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
357 brain->lock_path); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
358 return -1; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
359 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
360 |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
361 if (file_wait_lock(brain->lock_fd, brain->lock_path, F_WRLCK, |
16089
b436c1f6bd06
dsync: Use fcntl() locking instead of flock().
Timo Sirainen <tss@iki.fi>
parents:
16084
diff
changeset
|
362 FILE_LOCK_METHOD_FCNTL, brain->lock_timeout, |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
363 &brain->lock) <= 0) { |
16251
e41a13ae504d
dsync: If dsync fails due to lock timeout, give a better error message.
Timo Sirainen <tss@iki.fi>
parents:
16222
diff
changeset
|
364 if (errno == EAGAIN) { |
e41a13ae504d
dsync: If dsync fails due to lock timeout, give a better error message.
Timo Sirainen <tss@iki.fi>
parents:
16222
diff
changeset
|
365 i_error("Couldn't lock %s: Timed out after %u seconds", |
e41a13ae504d
dsync: If dsync fails due to lock timeout, give a better error message.
Timo Sirainen <tss@iki.fi>
parents:
16222
diff
changeset
|
366 brain->lock_path, brain->lock_timeout); |
e41a13ae504d
dsync: If dsync fails due to lock timeout, give a better error message.
Timo Sirainen <tss@iki.fi>
parents:
16222
diff
changeset
|
367 } else { |
e41a13ae504d
dsync: If dsync fails due to lock timeout, give a better error message.
Timo Sirainen <tss@iki.fi>
parents:
16222
diff
changeset
|
368 i_error("Couldn't lock %s: %m", brain->lock_path); |
e41a13ae504d
dsync: If dsync fails due to lock timeout, give a better error message.
Timo Sirainen <tss@iki.fi>
parents:
16222
diff
changeset
|
369 } |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
370 break; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
371 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
372 if (fstat(brain->lock_fd, &st1) < 0) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
373 if (errno != ESTALE) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
374 i_error("fstat(%s) failed: %m", brain->lock_path); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
375 break; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
376 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
377 } else if (stat(brain->lock_path, &st2) < 0) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
378 if (errno != ENOENT) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
379 i_error("stat(%s) failed: %m", brain->lock_path); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
380 break; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
381 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
382 } else if (st1.st_ino == st2.st_ino) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
383 /* success */ |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
384 return 0; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
385 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
386 /* file was recreated, try again */ |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
387 i_close_fd(&brain->lock_fd); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
388 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
389 i_close_fd(&brain->lock_fd); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
390 return -1; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
391 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
392 |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
393 static bool dsync_brain_master_recv_handshake(struct dsync_brain *brain) |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
394 { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
395 const struct dsync_ibc_settings *ibc_set; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
396 |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
397 i_assert(brain->master_brain); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
398 |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
399 if (dsync_ibc_recv_handshake(brain->ibc, &ibc_set) == 0) |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
400 return FALSE; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
401 |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
402 if (brain->lock_timeout > 0) { |
15816
adb9857a3879
dsync: If locking fails, fail instead of continuing.
Timo Sirainen <tss@iki.fi>
parents:
15815
diff
changeset
|
403 if (dsync_brain_lock(brain, ibc_set->hostname) < 0) { |
adb9857a3879
dsync: If locking fails, fail instead of continuing.
Timo Sirainen <tss@iki.fi>
parents:
15815
diff
changeset
|
404 brain->failed = TRUE; |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
405 return FALSE; |
15816
adb9857a3879
dsync: If locking fails, fail instead of continuing.
Timo Sirainen <tss@iki.fi>
parents:
15815
diff
changeset
|
406 } |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
407 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
408 |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
409 brain->state = brain->sync_type == DSYNC_BRAIN_SYNC_TYPE_STATE ? |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
410 DSYNC_STATE_MASTER_SEND_LAST_COMMON : |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
411 DSYNC_STATE_SEND_MAILBOX_TREE; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
412 return TRUE; |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
413 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
414 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
415 static bool dsync_brain_slave_recv_handshake(struct dsync_brain *brain) |
9559 | 416 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
417 const struct dsync_ibc_settings *ibc_set; |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
418 struct mail_namespace *ns; |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
419 const char *const *prefixes; |
9559 | 420 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
421 i_assert(!brain->master_brain); |
9559 | 422 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
423 if (dsync_ibc_recv_handshake(brain->ibc, &ibc_set) == 0) |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
424 return FALSE; |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
425 |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
426 if (ibc_set->lock_timeout > 0) { |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
427 brain->lock_timeout = ibc_set->lock_timeout; |
15816
adb9857a3879
dsync: If locking fails, fail instead of continuing.
Timo Sirainen <tss@iki.fi>
parents:
15815
diff
changeset
|
428 if (dsync_brain_lock(brain, ibc_set->hostname) < 0) { |
adb9857a3879
dsync: If locking fails, fail instead of continuing.
Timo Sirainen <tss@iki.fi>
parents:
15815
diff
changeset
|
429 brain->failed = TRUE; |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
430 return FALSE; |
15816
adb9857a3879
dsync: If locking fails, fail instead of continuing.
Timo Sirainen <tss@iki.fi>
parents:
15815
diff
changeset
|
431 } |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
432 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
433 |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
434 if (ibc_set->sync_ns_prefixes != NULL) { |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
435 p_array_init(&brain->sync_namespaces, brain->pool, 4); |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
436 prefixes = t_strsplit(ibc_set->sync_ns_prefixes, "\n"); |
17200
3e1a69e0cda9
dsync: Fixed using -n "" parameter
Timo Sirainen <tss@iki.fi>
parents:
17170
diff
changeset
|
437 if (prefixes[0] == NULL) { |
3e1a69e0cda9
dsync: Fixed using -n "" parameter
Timo Sirainen <tss@iki.fi>
parents:
17170
diff
changeset
|
438 /* ugly workaround for strsplit API: there was one |
3e1a69e0cda9
dsync: Fixed using -n "" parameter
Timo Sirainen <tss@iki.fi>
parents:
17170
diff
changeset
|
439 prefix="" entry */ |
3e1a69e0cda9
dsync: Fixed using -n "" parameter
Timo Sirainen <tss@iki.fi>
parents:
17170
diff
changeset
|
440 static const char *empty_prefix[] = { "", NULL }; |
3e1a69e0cda9
dsync: Fixed using -n "" parameter
Timo Sirainen <tss@iki.fi>
parents:
17170
diff
changeset
|
441 prefixes = empty_prefix; |
3e1a69e0cda9
dsync: Fixed using -n "" parameter
Timo Sirainen <tss@iki.fi>
parents:
17170
diff
changeset
|
442 } |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
443 for (; *prefixes != NULL; prefixes++) { |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
444 ns = mail_namespace_find(brain->user->namespaces, |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
445 *prefixes); |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
446 if (ns == NULL) { |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
447 i_error("Namespace not found: '%s'", *prefixes); |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
448 brain->failed = TRUE; |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
449 return FALSE; |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
450 } |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
451 array_append(&brain->sync_namespaces, &ns, 1); |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
452 } |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
453 } |
15471
88ac919f8afe
dsync: Added back support for syncing only one mailbox (-m parameter)
Timo Sirainen <tss@iki.fi>
parents:
15469
diff
changeset
|
454 brain->sync_box = p_strdup(brain->pool, ibc_set->sync_box); |
16398
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16396
diff
changeset
|
455 brain->exclude_mailboxes = ibc_set->exclude_mailboxes == NULL ? NULL : |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16396
diff
changeset
|
456 p_strarray_dup(brain->pool, ibc_set->exclude_mailboxes); |
18177
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
457 brain->sync_since_timestamp = ibc_set->sync_since_timestamp; |
16110
c51873a8e0d9
doveadm sync/backup: Added -g <guid> to sync only the specified mailbox (by GUID)
Timo Sirainen <tss@iki.fi>
parents:
16089
diff
changeset
|
458 memcpy(brain->sync_box_guid, ibc_set->sync_box_guid, |
c51873a8e0d9
doveadm sync/backup: Added -g <guid> to sync only the specified mailbox (by GUID)
Timo Sirainen <tss@iki.fi>
parents:
16089
diff
changeset
|
459 sizeof(brain->sync_box_guid)); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
460 i_assert(brain->sync_type == DSYNC_BRAIN_SYNC_TYPE_UNKNOWN); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
461 brain->sync_type = ibc_set->sync_type; |
16801
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
462 |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
463 dsync_brain_set_flags(brain, ibc_set->brain_flags); |
16801
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
464 /* this flag is only set on the remote slave brain */ |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
465 brain->purge = (ibc_set->brain_flags & |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
466 DSYNC_BRAIN_FLAG_PURGE_REMOTE) != 0; |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
467 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
468 dsync_brain_mailbox_trees_init(brain); |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
469 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
470 if (brain->sync_type == DSYNC_BRAIN_SYNC_TYPE_STATE) |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
471 brain->state = DSYNC_STATE_SLAVE_RECV_LAST_COMMON; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
472 else |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
473 brain->state = DSYNC_STATE_SEND_MAILBOX_TREE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
474 return TRUE; |
11727
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
475 } |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
476 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
477 static void dsync_brain_master_send_last_common(struct dsync_brain *brain) |
9559 | 478 { |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
479 struct dsync_mailbox_state *state; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
480 uint8_t *guid; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
481 enum dsync_ibc_send_ret ret = DSYNC_IBC_SEND_RET_OK; |
11727
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
482 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
483 i_assert(brain->master_brain); |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
484 |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
485 if (brain->mailbox_states_iter == NULL) { |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
486 brain->mailbox_states_iter = |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
487 hash_table_iterate_init(brain->mailbox_states); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
488 } |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
489 |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
490 for (;;) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
491 if (ret == DSYNC_IBC_SEND_RET_FULL) |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
492 return; |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
493 if (!hash_table_iterate(brain->mailbox_states_iter, |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
494 brain->mailbox_states, &guid, &state)) |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
495 break; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
496 ret = dsync_ibc_send_mailbox_state(brain->ibc, state); |
9638
b11a3eda2477
dsync: Use expunged messages' GUIDs to determine what to do with missing messages at end of mailbox.
Timo Sirainen <tss@iki.fi>
parents:
9592
diff
changeset
|
497 } |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
498 hash_table_iterate_deinit(&brain->mailbox_states_iter); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
499 |
16222
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
500 dsync_ibc_send_end_of_list(brain->ibc, DSYNC_IBC_EOL_MAILBOX_STATE); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
501 brain->state = DSYNC_STATE_SEND_MAILBOX_TREE; |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
502 } |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
503 |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
504 static void dsync_mailbox_state_add(struct dsync_brain *brain, |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
505 const struct dsync_mailbox_state *state) |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
506 { |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
507 struct dsync_mailbox_state *dupstate; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
508 uint8_t *guid_p; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
509 |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
510 dupstate = p_new(brain->pool, struct dsync_mailbox_state, 1); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
511 *dupstate = *state; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
512 guid_p = dupstate->mailbox_guid; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
513 hash_table_insert(brain->mailbox_states, guid_p, dupstate); |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
514 } |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
515 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
516 static bool dsync_brain_slave_recv_last_common(struct dsync_brain *brain) |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
517 { |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
518 struct dsync_mailbox_state state; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
519 enum dsync_ibc_recv_ret ret; |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
520 bool changed = FALSE; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
521 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
522 i_assert(!brain->master_brain); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
523 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
524 while ((ret = dsync_ibc_recv_mailbox_state(brain->ibc, &state)) > 0) { |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
525 dsync_mailbox_state_add(brain, &state); |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
526 changed = TRUE; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
527 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
528 if (ret == DSYNC_IBC_RECV_RET_FINISHED) { |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
529 brain->state = DSYNC_STATE_SEND_MAILBOX_TREE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
530 changed = TRUE; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
531 } |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
532 return changed; |
10371 | 533 } |
534 | |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
535 static bool dsync_brain_run_real(struct dsync_brain *brain, bool *changed_r) |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
536 { |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
537 enum dsync_state orig_state = brain->state; |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
538 enum dsync_box_state orig_box_recv_state = brain->box_recv_state; |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
539 enum dsync_box_state orig_box_send_state = brain->box_send_state; |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
540 bool changed = FALSE, ret = TRUE; |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
541 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
542 if (brain->failed) |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
543 return FALSE; |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
544 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
545 switch (brain->state) { |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
546 case DSYNC_STATE_MASTER_RECV_HANDSHAKE: |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
547 changed = dsync_brain_master_recv_handshake(brain); |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
548 break; |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
549 case DSYNC_STATE_SLAVE_RECV_HANDSHAKE: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
550 changed = dsync_brain_slave_recv_handshake(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
551 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
552 case DSYNC_STATE_MASTER_SEND_LAST_COMMON: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
553 dsync_brain_master_send_last_common(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
554 changed = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
555 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
556 case DSYNC_STATE_SLAVE_RECV_LAST_COMMON: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
557 changed = dsync_brain_slave_recv_last_common(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
558 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
559 case DSYNC_STATE_SEND_MAILBOX_TREE: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
560 dsync_brain_send_mailbox_tree(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
561 changed = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
562 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
563 case DSYNC_STATE_RECV_MAILBOX_TREE: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
564 changed = dsync_brain_recv_mailbox_tree(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
565 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
566 case DSYNC_STATE_SEND_MAILBOX_TREE_DELETES: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
567 dsync_brain_send_mailbox_tree_deletes(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
568 changed = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
569 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
570 case DSYNC_STATE_RECV_MAILBOX_TREE_DELETES: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
571 changed = dsync_brain_recv_mailbox_tree_deletes(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
572 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
573 case DSYNC_STATE_MASTER_SEND_MAILBOX: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
574 dsync_brain_master_send_mailbox(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
575 changed = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
576 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
577 case DSYNC_STATE_SLAVE_RECV_MAILBOX: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
578 changed = dsync_brain_slave_recv_mailbox(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
579 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
580 case DSYNC_STATE_SYNC_MAILS: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
581 changed = dsync_brain_sync_mails(brain); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
582 break; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
583 case DSYNC_STATE_DONE: |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
584 changed = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
585 ret = FALSE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
586 break; |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
587 } |
16539
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
588 if (brain->verbose_proctitle) { |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
589 if (orig_state != brain->state || |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
590 orig_box_recv_state != brain->box_recv_state || |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
591 orig_box_send_state != brain->box_send_state || |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
592 ++brain->proctitle_update_counter % 100 == 0) |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
593 process_title_set(dsync_brain_get_proctitle(brain)); |
b5876fa03b0e
dsync: If verbose_proctitle=yes, show the current state in it.
Timo Sirainen <tss@iki.fi>
parents:
16538
diff
changeset
|
594 } |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
595 *changed_r = changed; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
596 return brain->failed ? FALSE : ret; |
10371 | 597 } |
598 | |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
599 bool dsync_brain_run(struct dsync_brain *brain, bool *changed_r) |
9559 | 600 { |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
601 bool ret; |
10373
036db604f86c
dsync: Fixed problems with syncing mailbox names that are invalid on other side.
Timo Sirainen <tss@iki.fi>
parents:
10371
diff
changeset
|
602 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
603 *changed_r = FALSE; |
9559 | 604 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
14939
diff
changeset
|
605 if (dsync_ibc_has_failed(brain->ibc)) { |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
606 brain->failed = TRUE; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
607 return FALSE; |
12028
6ef21adeb61d
dsync: If worker fails, abort earlier.
Timo Sirainen <tss@iki.fi>
parents:
11971
diff
changeset
|
608 } |
6ef21adeb61d
dsync: If worker fails, abort earlier.
Timo Sirainen <tss@iki.fi>
parents:
11971
diff
changeset
|
609 |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
610 T_BEGIN { |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
611 ret = dsync_brain_run_real(brain, changed_r); |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
612 } T_END; |
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
613 return ret; |
10368
9f2e8d230bd5
dsync: If some uid/modseq changes couldn't be done, exit with different value.
Timo Sirainen <tss@iki.fi>
parents:
10356
diff
changeset
|
614 } |
12124
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
615 |
17271
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
616 static void dsync_brain_mailbox_states_dump(struct dsync_brain *brain) |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
617 { |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
618 struct hash_iterate_context *iter; |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
619 struct dsync_mailbox_state *state; |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
620 uint8_t *guid; |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
621 |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
622 iter = hash_table_iterate_init(brain->mailbox_states); |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
623 while (hash_table_iterate(iter, brain->mailbox_states, &guid, &state)) { |
17282
9669c9a8984f
dsync: Include messages_count in the mailbox states.
Timo Sirainen <tss@iki.fi>
parents:
17279
diff
changeset
|
624 i_debug("brain %c: Mailbox %s state: uidvalidity=%u uid=%u modseq=%llu pvt_modseq=%llu messages=%u changes_during_sync=%d", |
17271
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
625 brain->master_brain ? 'M' : 'S', |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
626 guid_128_to_string(guid), |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
627 state->last_uidvalidity, |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
628 state->last_common_uid, |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
629 (unsigned long long)state->last_common_modseq, |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
630 (unsigned long long)state->last_common_pvt_modseq, |
17282
9669c9a8984f
dsync: Include messages_count in the mailbox states.
Timo Sirainen <tss@iki.fi>
parents:
17279
diff
changeset
|
631 state->last_messages_count, |
17271
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
632 state->changes_during_sync); |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
633 } |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
634 hash_table_iterate_deinit(&iter); |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
635 } |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
636 |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
637 void dsync_brain_get_state(struct dsync_brain *brain, string_t *output) |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
638 { |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
639 struct hash_iterate_context *iter; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
640 struct dsync_mailbox_node *node; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
641 const struct dsync_mailbox_state *new_state; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
642 struct dsync_mailbox_state *state; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
643 const uint8_t *guid_p; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
644 uint8_t *guid; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
645 |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
646 /* update mailbox states */ |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
647 array_foreach(&brain->remote_mailbox_states, new_state) { |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
648 guid_p = new_state->mailbox_guid; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
649 state = hash_table_lookup(brain->mailbox_states, guid_p); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
650 if (state != NULL) |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
651 *state = *new_state; |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
652 else |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
653 dsync_mailbox_state_add(brain, new_state); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
654 } |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
655 |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
656 /* remove nonexistent mailboxes */ |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
657 iter = hash_table_iterate_init(brain->mailbox_states); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
658 while (hash_table_iterate(iter, brain->mailbox_states, &guid, &state)) { |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
659 node = dsync_mailbox_tree_lookup_guid(brain->local_mailbox_tree, |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
660 guid); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
661 if (node == NULL || |
17271
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
662 node->existence != DSYNC_MAILBOX_NODE_EXISTS) { |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
663 if (brain->debug) { |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
664 i_debug("brain %c: Removed state for deleted mailbox %s", |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
665 brain->master_brain ? 'M' : 'S', |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
666 guid_128_to_string(guid)); |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
667 } |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
668 hash_table_remove(brain->mailbox_states, guid); |
17271
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
669 } |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
670 } |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
671 hash_table_iterate_deinit(&iter); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
672 |
17271
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
673 if (brain->debug) { |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
674 i_debug("brain %c: Exported mailbox states:", |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
675 brain->master_brain ? 'M' : 'S'); |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
676 dsync_brain_mailbox_states_dump(brain); |
bb5deb884303
dsync: Added more debug output
Timo Sirainen <tss@iki.fi>
parents:
17221
diff
changeset
|
677 } |
15232
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
678 dsync_mailbox_states_export(brain->mailbox_states, output); |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
679 } |
6c850258002f
doveadm sync/backup: Added -s <state> parameter to do a fast stateful sync.
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
680 |
16253
1a58d4bcb49c
dsync: -U parameter never updated replicator's full_sync state.
Timo Sirainen <tss@iki.fi>
parents:
16251
diff
changeset
|
681 enum dsync_brain_sync_type dsync_brain_get_sync_type(struct dsync_brain *brain) |
1a58d4bcb49c
dsync: -U parameter never updated replicator's full_sync state.
Timo Sirainen <tss@iki.fi>
parents:
16251
diff
changeset
|
682 { |
1a58d4bcb49c
dsync: -U parameter never updated replicator's full_sync state.
Timo Sirainen <tss@iki.fi>
parents:
16251
diff
changeset
|
683 return brain->sync_type; |
1a58d4bcb49c
dsync: -U parameter never updated replicator's full_sync state.
Timo Sirainen <tss@iki.fi>
parents:
16251
diff
changeset
|
684 } |
1a58d4bcb49c
dsync: -U parameter never updated replicator's full_sync state.
Timo Sirainen <tss@iki.fi>
parents:
16251
diff
changeset
|
685 |
12124
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
686 bool dsync_brain_has_failed(struct dsync_brain *brain) |
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
687 { |
14584
b2076acc3715
Initial version of dsync rewrite.
Timo Sirainen <tss@iki.fi>
parents:
14253
diff
changeset
|
688 return brain->failed; |
12124
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
689 } |
16454
5593d6129712
dsync: If unexpected changes happened during sync, log a warning and exit with code 2.
Timo Sirainen <tss@iki.fi>
parents:
16398
diff
changeset
|
690 |
5593d6129712
dsync: If unexpected changes happened during sync, log a warning and exit with code 2.
Timo Sirainen <tss@iki.fi>
parents:
16398
diff
changeset
|
691 bool dsync_brain_has_unexpected_changes(struct dsync_brain *brain) |
5593d6129712
dsync: If unexpected changes happened during sync, log a warning and exit with code 2.
Timo Sirainen <tss@iki.fi>
parents:
16398
diff
changeset
|
692 { |
5593d6129712
dsync: If unexpected changes happened during sync, log a warning and exit with code 2.
Timo Sirainen <tss@iki.fi>
parents:
16398
diff
changeset
|
693 return brain->changes_during_sync; |
5593d6129712
dsync: If unexpected changes happened during sync, log a warning and exit with code 2.
Timo Sirainen <tss@iki.fi>
parents:
16398
diff
changeset
|
694 } |
16540
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
695 |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
696 bool dsync_brain_want_namespace(struct dsync_brain *brain, |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
697 struct mail_namespace *ns) |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
698 { |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
699 struct mail_namespace *const *nsp; |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
700 |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
701 if (array_is_created(&brain->sync_namespaces)) { |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
702 array_foreach(&brain->sync_namespaces, nsp) { |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
703 if (ns == *nsp) |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
704 return TRUE; |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
705 } |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
706 return FALSE; |
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
707 } |
16540
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
708 if (ns->alias_for != NULL) { |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
709 /* always skip aliases */ |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
710 return FALSE; |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
711 } |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
712 if (brain->sync_visible_namespaces) { |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
713 if ((ns->flags & NAMESPACE_FLAG_HIDDEN) == 0) |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
714 return TRUE; |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
715 if ((ns->flags & (NAMESPACE_FLAG_LIST_PREFIX | |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
716 NAMESPACE_FLAG_LIST_CHILDREN)) != 0) |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
717 return TRUE; |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
718 return FALSE; |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
719 } else { |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
720 return strcmp(ns->unexpanded_set->location, |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
721 SETTING_STRVAR_UNEXPANDED) == 0; |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
722 } |
84014270ee37
dsync: Don't try to find mailboxes from unwanted namespaces.
Timo Sirainen <tss@iki.fi>
parents:
16539
diff
changeset
|
723 } |