annotate src/director/director.c @ 22566:98b21e27d66c

director: When director is removed, notify it before disconnecting This way the removed director will know that it's been removed, and it can also more quickly forward the removal to other directors.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 14 Sep 2017 17:48:50 +0300
parents 17b1e65e6d70
children 4a0792a03f5a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21390
2e2563132d5f Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21370
diff changeset
1 /* Copyright (c) 2010-2017 Dovecot authors, see the included COPYING file */
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "ioloop.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "array.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "str.h"
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
7 #include "strescape.h"
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
8 #include "log-throttle.h"
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
9 #include "ipc-client.h"
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
10 #include "program-client.h"
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
11 #include "var-expand.h"
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
12 #include "istream.h"
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
13 #include "ostream.h"
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
14 #include "iostream-temp.h"
21076
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
15 #include "mail-user-hash.h"
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #include "user-directory.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include "mail-host.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include "director-host.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 #include "director-connection.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #include "director.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
22 #define DIRECTOR_IPC_PROXY_PATH "ipc"
11327
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
23 #define DIRECTOR_RECONNECT_RETRY_SECS 60
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
24 #define DIRECTOR_RECONNECT_TIMEOUT_MSECS (30*1000)
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
25 #define DIRECTOR_USER_MOVE_TIMEOUT_MSECS (30*1000)
14472
3acc1451ab56 director: Decreased timeout for resending lost SYNC request.
Timo Sirainen <tss@iki.fi>
parents: 14468
diff changeset
26 #define DIRECTOR_SYNC_TIMEOUT_MSECS (5*1000)
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
27 #define DIRECTOR_RING_MIN_WAIT_SECS 20
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
28 #define DIRECTOR_QUICK_RECONNECT_TIMEOUT_MSECS 1000
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
29 #define DIRECTOR_DELAYED_DIR_REMOVE_MSECS (1000*30)
11327
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
30
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
31 bool director_debug;
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
32
20985
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
33 const char *user_kill_state_names[USER_KILL_STATE_DELAY+1] = {
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
34 "none",
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
35 "killing",
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
36 "notify-received",
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
37 "waiting-for-notify",
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
38 "waiting-for-everyone",
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
39 "flushing",
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
40 "delay",
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
41 };
52a725c67e83 director: Code cleanup - move enum user_kill_state to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20982
diff changeset
42
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
43 static struct log_throttle *user_move_throttle;
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
44 static struct log_throttle *user_kill_fail_throttle;
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
45
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
46 static const struct log_throttle_settings director_log_throttle_settings = {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
47 .throttle_at_max_per_interval = 100,
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
48 .unthrottle_at_max_per_interval = 2,
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
49 };
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
50
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
51 static void
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
52 director_user_kill_finish_delayed(struct director *dir, struct user *user,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
53 bool skip_delay);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
54
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 static bool director_is_self_ip_set(struct director *dir)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 struct ip_addr ip;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 net_get_ip_any4(&ip);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 if (net_ip_compare(&dir->self_ip, &ip))
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 net_get_ip_any6(&ip);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 if (net_ip_compare(&dir->self_ip, &ip))
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 static void director_find_self_ip(struct director *dir)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 struct director_host *const *hosts;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 unsigned int i, count;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 hosts = array_get(&dir->dir_hosts, &count);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 for (i = 0; i < count; i++) {
11341
7d3d6ee01bfc director: Use net_try_bind() to try to find our own IP.
Timo Sirainen <tss@iki.fi>
parents: 11339
diff changeset
77 if (net_try_bind(&hosts[i]->ip) == 0) {
7d3d6ee01bfc director: Use net_try_bind() to try to find our own IP.
Timo Sirainen <tss@iki.fi>
parents: 11339
diff changeset
78 dir->self_ip = hosts[i]->ip;
7d3d6ee01bfc director: Use net_try_bind() to try to find our own IP.
Timo Sirainen <tss@iki.fi>
parents: 11339
diff changeset
79 return;
7d3d6ee01bfc director: Use net_try_bind() to try to find our own IP.
Timo Sirainen <tss@iki.fi>
parents: 11339
diff changeset
80 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 }
11341
7d3d6ee01bfc director: Use net_try_bind() to try to find our own IP.
Timo Sirainen <tss@iki.fi>
parents: 11339
diff changeset
82 i_fatal("director_servers doesn't list ourself");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84
13935
b8fa70a81c8c director: Find director's own IP earlier in init.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
85 void director_find_self(struct director *dir)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 if (dir->self_host != NULL)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89
11339
ed633bfb8c59 director: Fixed finding the director's own IP in case system has multiple.
Timo Sirainen <tss@iki.fi>
parents: 11338
diff changeset
90 if (!director_is_self_ip_set(dir))
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 director_find_self_ip(dir);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 dir->self_host = director_host_lookup(dir, &dir->self_ip,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 dir->self_port);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 if (dir->self_host == NULL) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 i_fatal("director_servers doesn't list ourself (%s:%u)",
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 net_ip2addr(&dir->self_ip), dir->self_port);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 dir->self_host->self = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 static unsigned int director_find_self_idx(struct director *dir)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 struct director_host *const *hosts;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 unsigned int i, count;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 i_assert(dir->self_host != NULL);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 hosts = array_get(&dir->dir_hosts, &count);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 for (i = 0; i < count; i++) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 if (hosts[i] == dir->self_host)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 return i;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 i_unreached();
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
117 static bool
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
118 director_has_outgoing_connection(struct director *dir,
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
119 struct director_host *host)
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
120 {
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
121 struct director_connection *const *connp;
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
122
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
123 array_foreach(&dir->connections, connp) {
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
124 if (director_connection_get_host(*connp) == host &&
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
125 !director_connection_is_incoming(*connp))
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
126 return TRUE;
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
127 }
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
128 return FALSE;
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
129 }
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
130
22563
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
131 static void
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
132 director_log_connect(struct director *dir, struct director_host *host,
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
133 const char *reason)
22563
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
134 {
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
135 string_t *str = t_str_new(128);
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
136
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
137 if (host->last_network_failure > 0) {
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
138 str_printfa(str, ", last network failure %ds ago",
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
139 (int)(ioloop_time - host->last_network_failure));
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
140 }
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
141 if (host->last_protocol_failure > 0) {
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
142 str_printfa(str, ", last protocol failure %ds ago",
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
143 (int)(ioloop_time - host->last_protocol_failure));
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
144 }
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
145 i_info("Connecting to %s:%u (as %s%s): %s",
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
146 net_ip2addr(&host->ip), host->port,
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
147 net_ip2addr(&dir->self_ip), str_c(str), reason);
22563
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
148 }
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
149
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
150 int director_connect_host(struct director *dir, struct director_host *host,
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
151 const char *reason)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 {
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18729
diff changeset
153 in_port_t port;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 int fd;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
156 if (director_has_outgoing_connection(dir, host))
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
157 return 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
159 director_log_connect(dir, host, reason);
11572
659bb1a26da4 director: Added initial testing framework and some debugging output.
Timo Sirainen <tss@iki.fi>
parents: 11355
diff changeset
160 port = dir->test_port != 0 ? dir->test_port : host->port;
659bb1a26da4 director: Added initial testing framework and some debugging output.
Timo Sirainen <tss@iki.fi>
parents: 11355
diff changeset
161 fd = net_connect_ip(&host->ip, port, &dir->self_ip);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 if (fd == -1) {
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
163 host->last_network_failure = ioloop_time;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 i_error("connect(%s) failed: %m", host->name);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 return -1;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 }
12934
2b7af3a16521 director: Reset hosts' last_failed timestamps when they're suspected to be working again.
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
167 /* Reset timestamp so that director_connect() won't skip this host
2b7af3a16521 director: Reset hosts' last_failed timestamps when they're suspected to be working again.
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
168 while we're still trying to connect to it */
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
169 host->last_network_failure = 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
171 (void)director_connection_init_out(dir, fd, host);
11327
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
172 return 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
175 static struct director_host *
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
176 director_get_preferred_right_host(struct director *dir)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
177 {
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
178 struct director_host *const *hosts, *host;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
179 unsigned int i, count, self_idx;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
180
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
181 hosts = array_get(&dir->dir_hosts, &count);
14388
a71bc8dbe53d director: Avoid crashing if all directors are removed when reconnecting.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
182 if (count == 1) {
a71bc8dbe53d director: Avoid crashing if all directors are removed when reconnecting.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
183 /* self */
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
184 return NULL;
14388
a71bc8dbe53d director: Avoid crashing if all directors are removed when reconnecting.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
185 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
186
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
187 self_idx = director_find_self_idx(dir);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
188 for (i = 0; i < count; i++) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
189 host = hosts[(self_idx + i + 1) % count];
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
190 if (!host->removed)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
191 return host;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
192 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
193 /* self, with some removed hosts */
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
194 return NULL;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
195 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
196
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
197 static void director_quick_reconnect_retry(struct director *dir)
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
198 {
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
199 director_connect(dir, "Alone in director ring - trying to connect to others");
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
200 }
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
201
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
202 static bool director_wait_for_others(struct director *dir)
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
203 {
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
204 struct director_host *const *hostp;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
205
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
206 /* don't assume we're alone until we've attempted to connect
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
207 to others for a while */
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
208 if (dir->ring_first_alone != 0 &&
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
209 ioloop_time - dir->ring_first_alone > DIRECTOR_RING_MIN_WAIT_SECS)
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
210 return FALSE;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
211
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
212 if (dir->ring_first_alone == 0)
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
213 dir->ring_first_alone = ioloop_time;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
214 /* reset all failures and try again */
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
215 array_foreach(&dir->dir_hosts, hostp) {
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
216 (*hostp)->last_network_failure = 0;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
217 (*hostp)->last_protocol_failure = 0;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
218 }
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
219 if (dir->to_reconnect != NULL)
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
220 timeout_remove(&dir->to_reconnect);
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
221 dir->to_reconnect = timeout_add(DIRECTOR_QUICK_RECONNECT_TIMEOUT_MSECS,
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
222 director_quick_reconnect_retry, dir);
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
223 return TRUE;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
224 }
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
225
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
226 void director_connect(struct director *dir, const char *reason)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228 struct director_host *const *hosts;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229 unsigned int i, count, self_idx;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 self_idx = director_find_self_idx(dir);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
232
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 /* try to connect to first working server on our right side.
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234 the left side is supposed to connect to us. */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 hosts = array_get(&dir->dir_hosts, &count);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 for (i = 1; i < count; i++) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
237 unsigned int idx = (self_idx + i) % count;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
239 if (hosts[idx]->removed)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
240 continue;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
241
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
242 if (hosts[idx]->last_network_failure +
11349
350208d17fcd director: Fixes to connecting to remote director.
Timo Sirainen <tss@iki.fi>
parents: 11343
diff changeset
243 DIRECTOR_RECONNECT_RETRY_SECS > ioloop_time) {
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
244 /* connection failed recently, don't try retrying here */
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
245 continue;
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
246 }
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
247 if (hosts[idx]->last_protocol_failure +
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
248 DIRECTOR_PROTOCOL_FAILURE_RETRY_SECS > ioloop_time) {
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
249 /* the director recently sent invalid protocol data,
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
250 don't try retrying yet */
11349
350208d17fcd director: Fixes to connecting to remote director.
Timo Sirainen <tss@iki.fi>
parents: 11343
diff changeset
251 continue;
350208d17fcd director: Fixes to connecting to remote director.
Timo Sirainen <tss@iki.fi>
parents: 11343
diff changeset
252 }
350208d17fcd director: Fixes to connecting to remote director.
Timo Sirainen <tss@iki.fi>
parents: 11343
diff changeset
253
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
254 if (director_connect_host(dir, hosts[idx], reason) == 0) {
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
255 /* success */
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
256 return;
12935
e9139f74c451 director: Improved debug/error logging.
Timo Sirainen <tss@iki.fi>
parents: 12934
diff changeset
257 }
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
258 }
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
259
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
260 if (count > 1 && director_wait_for_others(dir))
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
261 return;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
262
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
263 /* we're the only one */
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
264 if (count > 1) {
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
265 i_warning("director: Couldn't connect to right side, "
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
266 "we must be the only director left");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267 }
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
268 if (dir->left != NULL) {
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
269 /* since we couldn't connect to it,
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
270 it must have failed recently */
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
271 i_warning("director: Assuming %s is dead, disconnecting",
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
272 director_connection_get_name(dir->left));
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
273 director_connection_deinit(&dir->left,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
274 "This connection is dead?");
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
275 }
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
276 dir->ring_min_version = DIRECTOR_VERSION_MINOR;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
277 if (!dir->ring_handshaked)
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
278 director_set_ring_handshaked(dir);
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
279 else
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
280 director_set_ring_synced(dir);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282
11343
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
283 void director_set_ring_handshaked(struct director *dir)
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
284 {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
285 i_assert(!dir->ring_handshaked);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
286
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
287 if (dir->to_handshake_warning != NULL)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
288 timeout_remove(&dir->to_handshake_warning);
11343
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
289 if (dir->ring_handshake_warning_sent) {
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
290 i_warning("Directors have been connected, "
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
291 "continuing delayed requests");
11343
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
292 dir->ring_handshake_warning_sent = FALSE;
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
293 }
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
294 dir_debug("Director ring handshaked");
11343
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
295
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
296 dir->ring_handshaked = TRUE;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
297 director_set_ring_synced(dir);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
298 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
299
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
300 static void director_reconnect_timeout(struct director *dir)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
301 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
302 struct director_host *cur_host, *preferred_host =
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
303 director_get_preferred_right_host(dir);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
304
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
305 cur_host = dir->right == NULL ? NULL :
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
306 director_connection_get_host(dir->right);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
307
14388
a71bc8dbe53d director: Avoid crashing if all directors are removed when reconnecting.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
308 if (preferred_host == NULL) {
a71bc8dbe53d director: Avoid crashing if all directors are removed when reconnecting.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
309 /* all directors have been removed, try again later */
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
310 } else if (cur_host != preferred_host) {
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
311 (void)director_connect_host(dir, preferred_host,
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
312 "Reconnect attempt to preferred director");
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
313 } else {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
314 /* the connection hasn't finished sync yet.
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
315 keep this timeout for now. */
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
316 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
317 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
318
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
319 void director_set_ring_synced(struct director *dir)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
320 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
321 struct director_host *host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
322
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
323 i_assert(!dir->ring_synced);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
324 i_assert((dir->left != NULL && dir->right != NULL) ||
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
325 (dir->left == NULL && dir->right == NULL));
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
326
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
327 if (dir->to_handshake_warning != NULL)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
328 timeout_remove(&dir->to_handshake_warning);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
329 if (dir->ring_handshake_warning_sent) {
18064
389f084b3d2a director: When logging a warning about ring being synced again, log how many seconds it took
Timo Sirainen <tss@iki.fi>
parents: 17464
diff changeset
330 i_warning("Ring is synced, continuing delayed requests "
19292
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
331 "(syncing took %d secs, hosts_hash=%u)",
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
332 (int)(ioloop_time - dir->ring_last_sync_time),
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
333 mail_hosts_hash(dir->mail_hosts));
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
334 dir->ring_handshake_warning_sent = FALSE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
335 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
336
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
337 host = dir->right == NULL ? NULL :
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
338 director_connection_get_host(dir->right);
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
339
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
340 if (dir->to_reconnect != NULL)
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
341 timeout_remove(&dir->to_reconnect);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
342 if (host != director_get_preferred_right_host(dir)) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
343 /* try to reconnect to preferred host later */
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
344 dir->to_reconnect =
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
345 timeout_add(DIRECTOR_RECONNECT_TIMEOUT_MSECS,
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
346 director_reconnect_timeout, dir);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
347 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
348
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
349 if (dir->left != NULL)
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
350 director_connection_set_synced(dir->left, TRUE);
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
351 if (dir->right != NULL)
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
352 director_connection_set_synced(dir->right, TRUE);
13941
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
353 if (dir->to_sync != NULL)
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
354 timeout_remove(&dir->to_sync);
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
355 dir->ring_synced = TRUE;
13921
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
356 dir->ring_last_sync_time = ioloop_time;
19287
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19108
diff changeset
357 mail_hosts_set_synced(dir->mail_hosts);
11343
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
358 director_set_state_changed(dir);
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
359 }
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
360
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
361 void director_sync_send(struct director *dir, struct director_host *host,
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
362 uint32_t seq, unsigned int minor_version,
19293
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
363 unsigned int timestamp, unsigned int hosts_hash)
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
364 {
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
365 string_t *str;
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
366
19954
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
367 if (host == dir->self_host)
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
368 dir->last_sync_sent_ring_change_counter = dir->ring_change_counter;
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
369
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
370 str = t_str_new(128);
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
371 str_printfa(str, "SYNC\t%s\t%u\t%u",
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
372 net_ip2addr(&host->ip), host->port, seq);
14431
084064444f89 director: Don't try to send the new SYNC parameter to old director versions.
Timo Sirainen <tss@iki.fi>
parents: 14409
diff changeset
373 if (minor_version > 0 &&
084064444f89 director: Don't try to send the new SYNC parameter to old director versions.
Timo Sirainen <tss@iki.fi>
parents: 14409
diff changeset
374 director_connection_get_minor_version(dir->right) > 0) {
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
375 /* only minor_version>0 supports extra parameters */
19293
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
376 str_printfa(str, "\t%u\t%u\t%u", minor_version,
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
377 timestamp, hosts_hash);
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
378 }
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
379 str_append_c(str, '\n');
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
380 director_connection_send(dir->right, str_c(str));
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
381
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
382 /* ping our connections in case either of them are hanging.
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
383 if they are, we want to know it fast. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
384 if (dir->left != NULL)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
385 director_connection_ping(dir->left);
17464
203b3a6f508f Removed pointless NULL checks.
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
386 director_connection_ping(dir->right);
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
387 }
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
388
13941
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
389 bool director_resend_sync(struct director *dir)
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
390 {
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
391 if (!dir->ring_synced && dir->left != NULL && dir->right != NULL) {
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
392 /* send a new SYNC in case the previous one got dropped */
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
393 dir->self_host->last_sync_timestamp = ioloop_time;
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
394 director_sync_send(dir, dir->self_host, dir->sync_seq,
19293
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
395 DIRECTOR_VERSION_MINOR, ioloop_time,
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
396 mail_hosts_hash(dir->mail_hosts));
13941
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
397 if (dir->to_sync != NULL)
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
398 timeout_reset(dir->to_sync);
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
399 return TRUE;
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
400 }
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
401 return FALSE;
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
402 }
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
403
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
404 static void director_sync_timeout(struct director *dir)
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
405 {
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
406 i_assert(!dir->ring_synced);
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
407
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
408 if (director_resend_sync(dir))
22560
9a300e778b20 director: When logging "ring SYNC lost", include sync seq number in message
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22559
diff changeset
409 i_error("Ring SYNC seq=%u appears to have got lost, resending", dir->sync_seq);
13941
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
410 }
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
411
13921
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
412 void director_set_ring_unsynced(struct director *dir)
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
413 {
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
414 if (dir->ring_synced) {
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
415 dir->ring_synced = FALSE;
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
416 dir->ring_last_sync_time = ioloop_time;
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
417 }
13941
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
418
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
419 if (dir->to_sync == NULL) {
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
420 dir->to_sync = timeout_add(DIRECTOR_SYNC_TIMEOUT_MSECS,
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
421 director_sync_timeout, dir);
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
422 } else {
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
423 timeout_reset(dir->to_sync);
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
424 }
13921
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
425 }
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
426
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
427 static void director_sync(struct director *dir)
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
428 {
14491
a5b7dda1db6d director: Director ring needs to be set unsynced immediately even when sycning is frozen.
Timo Sirainen <tss@iki.fi>
parents: 14487
diff changeset
429 /* we're synced again when we receive this SYNC back */
a5b7dda1db6d director: Director ring needs to be set unsynced immediately even when sycning is frozen.
Timo Sirainen <tss@iki.fi>
parents: 14487
diff changeset
430 dir->sync_seq++;
14652
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
431 if (dir->right == NULL && dir->left == NULL) {
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
432 /* we're alone. if we're already synced,
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
433 don't become unsynced. */
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
434 return;
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
435 }
14491
a5b7dda1db6d director: Director ring needs to be set unsynced immediately even when sycning is frozen.
Timo Sirainen <tss@iki.fi>
parents: 14487
diff changeset
436 director_set_ring_unsynced(dir);
a5b7dda1db6d director: Director ring needs to be set unsynced immediately even when sycning is frozen.
Timo Sirainen <tss@iki.fi>
parents: 14487
diff changeset
437
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
438 if (dir->sync_frozen) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
439 dir->sync_pending = TRUE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
440 return;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
441 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
442 if (dir->right == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
443 i_assert(!dir->ring_synced ||
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
444 (dir->left == NULL && dir->right == NULL));
22561
06361c8455a7 director: Improve debugging: Log ring desync when there is no right connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22560
diff changeset
445 dir_debug("Ring is desynced (seq=%u, no right connection)",
06361c8455a7 director: Improve debugging: Log ring desync when there is no right connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22560
diff changeset
446 dir->sync_seq);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
447 return;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
448 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
449
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
450 dir_debug("Ring is desynced (seq=%u, sending SYNC to %s)",
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
451 dir->sync_seq, dir->right == NULL ? "(nowhere)" :
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
452 director_connection_get_name(dir->right));
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
453
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
454 /* send PINGs to our connections more rapidly until we've synced again.
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
455 if the connection has actually died, we don't need to wait (and
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
456 delay requests) for as long to detect it */
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
457 if (dir->left != NULL)
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
458 director_connection_set_synced(dir->left, FALSE);
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
459 director_connection_set_synced(dir->right, FALSE);
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
460 director_sync_send(dir, dir->self_host, dir->sync_seq,
19293
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
461 DIRECTOR_VERSION_MINOR, ioloop_time,
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
462 mail_hosts_hash(dir->mail_hosts));
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
463 }
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
464
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
465 void director_sync_freeze(struct director *dir)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
466 {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
467 struct director_connection *const *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
468
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
469 i_assert(!dir->sync_frozen);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
470 i_assert(!dir->sync_pending);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
471
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
472 array_foreach(&dir->connections, connp)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
473 director_connection_cork(*connp);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
474 dir->sync_frozen = TRUE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
475 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
476
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
477 void director_sync_thaw(struct director *dir)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
478 {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
479 struct director_connection *const *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
480
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
481 i_assert(dir->sync_frozen);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
482
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
483 dir->sync_frozen = FALSE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
484 if (dir->sync_pending) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
485 dir->sync_pending = FALSE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
486 director_sync(dir);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
487 }
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
488 array_foreach(&dir->connections, connp)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
489 director_connection_uncork(*connp);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
490 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
491
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
492 void director_notify_ring_added(struct director_host *added_host,
22562
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
493 struct director_host *src, bool log)
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
494 {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
495 const char *cmd;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
496
22562
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
497 if (log) {
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
498 i_info("Adding director %s to ring (requested by %s)",
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
499 added_host->name, src->name);
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
500 }
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
501
19954
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
502 added_host->dir->ring_change_counter++;
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
503 cmd = t_strdup_printf("DIRECTOR\t%s\t%u\n",
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
504 net_ip2addr(&added_host->ip), added_host->port);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
505 director_update_send(added_host->dir, src, cmd);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
506 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
507
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
508 static void director_delayed_dir_remove_timeout(struct director *dir)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
509 {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
510 struct director_host *const *hosts, *host;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
511 unsigned int i, count;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
512
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
513 timeout_remove(&dir->to_remove_dirs);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
514
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
515 hosts = array_get(&dir->dir_hosts, &count);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
516 for (i = 0; i < count; ) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
517 if (hosts[i]->removed) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
518 host = hosts[i];
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
519 director_host_free(&host);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
520 hosts = array_get(&dir->dir_hosts, &count);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
521 } else {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
522 i++;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
523 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
524 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
525 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
526
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
527 void director_ring_remove(struct director_host *removed_host,
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
528 struct director_host *src)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
529 {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
530 struct director *dir = removed_host->dir;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
531 struct director_connection *const *conns, *conn;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
532 unsigned int i, count;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
533 const char *cmd;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
534
22562
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
535 i_info("Removing director %s from ring (requested by %s)",
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
536 removed_host->name, src->name);
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
537
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
538 if (removed_host->self) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
539 /* others will just disconnect us */
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
540 return;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
541 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
542
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
543 /* mark the host as removed and fully remove it later. this delay is
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
544 needed, because the removal may trigger director reconnections,
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
545 which may send the director back and we don't want to re-add it */
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
546 removed_host->removed = TRUE;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
547 if (dir->to_remove_dirs == NULL) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
548 dir->to_remove_dirs =
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
549 timeout_add(DIRECTOR_DELAYED_DIR_REMOVE_MSECS,
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
550 director_delayed_dir_remove_timeout, dir);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
551 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
552
22566
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
553 /* if our left or ride side gets removed, notify them first
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
554 before disconnecting. */
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
555 cmd = t_strdup_printf("DIRECTOR-REMOVE\t%s\t%u\n",
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
556 net_ip2addr(&removed_host->ip),
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
557 removed_host->port);
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
558 director_update_send_version(dir, src,
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
559 DIRECTOR_VERSION_RING_REMOVE, cmd);
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
560
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
561 /* disconnect any connections to the host */
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
562 conns = array_get(&dir->connections, &count);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
563 for (i = 0; i < count; ) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
564 conn = conns[i];
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
565 if (director_connection_get_host(conn) != removed_host)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
566 i++;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
567 else {
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
568 director_connection_deinit(&conn, "Removing from ring");
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
569 conns = array_get(&dir->connections, &count);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
570 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
571 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
572 if (dir->right == NULL)
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
573 director_connect(dir, "Reconnecting after director was removed");
22559
29e61d343a60 doveadm director ring remove: Wait ring sync before and after removal
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22551
diff changeset
574 director_sync(dir);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
575 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
576
19293
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
577 static void
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
578 director_send_host(struct director *dir, struct director_host *src,
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
579 struct director_host *orig_src,
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
580 struct mail_host *host)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
581 {
19408
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
582 const char *host_tag = mail_host_get_tag(host);
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
583 string_t *str;
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
584
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
585 if (orig_src == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
586 orig_src = dir->self_host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
587 orig_src->last_seq++;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
588 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
589
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
590 str = t_str_new(128);
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
591 str_printfa(str, "HOST\t%s\t%u\t%u\t%s\t%u",
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
592 net_ip2addr(&orig_src->ip), orig_src->port,
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
593 orig_src->last_seq,
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
594 net_ip2addr(&host->ip), host->vhost_count);
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
595 if (dir->ring_min_version >= DIRECTOR_VERSION_TAGS_V2) {
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18661
diff changeset
596 str_append_c(str, '\t');
19408
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
597 str_append_tabescaped(str, host_tag);
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
598 } else if (host_tag[0] != '\0' &&
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
599 dir->ring_min_version < DIRECTOR_VERSION_TAGS_V2) {
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
600 if (dir->ring_min_version < DIRECTOR_VERSION_TAGS) {
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
601 i_error("Ring has directors that don't support tags - removing host %s with tag '%s'",
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
602 net_ip2addr(&host->ip), host_tag);
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
603 } else {
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
604 i_error("Ring has directors that support mixed versions of tags - removing host %s with tag '%s'",
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
605 net_ip2addr(&host->ip), host_tag);
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
606 }
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
607 director_remove_host(dir, NULL, NULL, host);
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
608 return;
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18661
diff changeset
609 }
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18661
diff changeset
610 if (dir->ring_min_version >= DIRECTOR_VERSION_UPDOWN) {
19310
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
611 str_printfa(str, "\t%c%ld\t", host->down ? 'D' : 'U',
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18661
diff changeset
612 (long)host->last_updown_change);
19310
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
613 /* add any further version checks here - these directors ignore
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
614 any extra unknown arguments */
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
615 if (host->hostname != NULL)
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
616 str_append_tabescaped(str, host->hostname);
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
617 }
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
618 str_append_c(str, '\n');
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
619 director_update_send(dir, src, str_c(str));
19293
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
620 }
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
621
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
622 void director_resend_hosts(struct director *dir)
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
623 {
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
624 struct mail_host *const *hostp;
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
625
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
626 array_foreach(mail_hosts_get(dir->mail_hosts), hostp)
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
627 director_send_host(dir, dir->self_host, NULL, *hostp);
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
628 }
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
629
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
630 void director_update_host(struct director *dir, struct director_host *src,
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
631 struct director_host *orig_src,
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
632 struct mail_host *host)
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
633 {
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
634 /* update state in case this is the first mail host being added */
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
635 director_set_state_changed(dir);
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
636
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
637 dir_debug("Updating host %s vhost_count=%u "
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
638 "down=%d last_updown_change=%ld (hosts_hash=%u)",
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
639 net_ip2addr(&host->ip), host->vhost_count, host->down,
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
640 (long)host->last_updown_change,
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
641 mail_hosts_hash(dir->mail_hosts));
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
642
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
643 director_send_host(dir, src, orig_src, host);
19287
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19108
diff changeset
644
19507
3326e9fda5c1 director: Don't mark the host desynced if director is alone in ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19411
diff changeset
645 /* mark the host desynced until ring is synced again. except if we're
3326e9fda5c1 director: Don't mark the host desynced if director is alone in ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19411
diff changeset
646 alone in the ring that never happens. */
3326e9fda5c1 director: Don't mark the host desynced if director is alone in ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19411
diff changeset
647 if (dir->right != NULL || dir->left != NULL)
3326e9fda5c1 director: Don't mark the host desynced if director is alone in ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19411
diff changeset
648 host->desynced = TRUE;
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
649 director_sync(dir);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
650 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
651
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
652 void director_remove_host(struct director *dir, struct director_host *src,
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
653 struct director_host *orig_src,
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
654 struct mail_host *host)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
655 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
656 struct user_directory *users = host->tag->users;
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
657
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
658 if (src != NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
659 if (orig_src == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
660 orig_src = dir->self_host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
661 orig_src->last_seq++;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
662 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
663
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
664 director_update_send(dir, src, t_strdup_printf(
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
665 "HOST-REMOVE\t%s\t%u\t%u\t%s\n",
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
666 net_ip2addr(&orig_src->ip), orig_src->port,
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
667 orig_src->last_seq, net_ip2addr(&host->ip)));
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
668 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
669
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
670 user_directory_remove_host(users, host);
19407
39cfca637d60 director: Code cleanup - make most mail_host_*() list parameters unnecessary.
Timo Sirainen <tss@iki.fi>
parents: 19310
diff changeset
671 mail_host_remove(host);
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
672 director_sync(dir);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
673 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
674
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11353
diff changeset
675 void director_flush_host(struct director *dir, struct director_host *src,
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
676 struct director_host *orig_src,
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11353
diff changeset
677 struct mail_host *host)
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11353
diff changeset
678 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
679 struct user_directory *users = host->tag->users;
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
680
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
681 if (orig_src == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
682 orig_src = dir->self_host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
683 orig_src->last_seq++;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
684 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
685
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11353
diff changeset
686 director_update_send(dir, src, t_strdup_printf(
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
687 "HOST-FLUSH\t%s\t%u\t%u\t%s\n",
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
688 net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq,
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
689 net_ip2addr(&host->ip)));
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
690 user_directory_remove_host(users, host);
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
691 director_sync(dir);
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11353
diff changeset
692 }
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11353
diff changeset
693
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
694 void director_update_user(struct director *dir, struct director_host *src,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
695 struct user *user)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
696 {
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
697 i_assert(src != NULL);
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
698
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
699 i_assert(!user->weak);
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
700 director_update_send(dir, src, t_strdup_printf("USER\t%u\t%s\n",
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
701 user->username_hash, net_ip2addr(&user->host->ip)));
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
702 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
703
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
704 void director_update_user_weak(struct director *dir, struct director_host *src,
17259
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
705 struct director_connection *src_conn,
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
706 struct director_host *orig_src,
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
707 struct user *user)
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
708 {
17259
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
709 const char *cmd;
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
710
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
711 i_assert(src != NULL);
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
712 i_assert(user->weak);
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
713
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
714 if (orig_src == NULL) {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
715 orig_src = dir->self_host;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
716 orig_src->last_seq++;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
717 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
718
17259
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
719 cmd = t_strdup_printf("USER-WEAK\t%s\t%u\t%u\t%u\t%s\n",
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
720 net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq,
17259
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
721 user->username_hash, net_ip2addr(&user->host->ip));
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
722
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
723 if (src != dir->self_host && dir->left != NULL && dir->right != NULL &&
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
724 director_connection_get_host(dir->left) ==
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
725 director_connection_get_host(dir->right)) {
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
726 /* only two directors in this ring and we're forwarding
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
727 USER-WEAK from one director back to itself via another
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
728 so it sees we've received it. we can't use
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
729 director_update_send() for this, because it doesn't send
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
730 data back to the source. */
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
731 if (dir->right == src_conn)
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
732 director_connection_send(dir->left, cmd);
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
733 else if (dir->left == src_conn)
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
734 director_connection_send(dir->right, cmd);
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
735 else
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
736 i_unreached();
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
737 } else {
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
738 director_update_send(dir, src, cmd);
6269063f8408 director: Fixed handling weak users when there were exactly 2 director servers in the ring.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
739 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
740 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
741
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
742 static void
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
743 director_flush_user_continue(int result, struct director_kill_context *ctx)
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
744 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
745 struct director *dir = ctx->dir;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
746 ctx->callback_pending = FALSE;
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
747
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
748 struct user *user = user_directory_lookup(ctx->tag->users,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
749 ctx->username_hash);
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
750
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
751 if (result == 0) {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
752 struct istream *is = iostream_temp_finish(&ctx->reply, (size_t)-1);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
753 char *data;
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
754 i_stream_set_return_partial_line(is, TRUE);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
755 data = i_stream_read_next_line(is);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
756 i_error("%s: Failed to flush user hash %u in host %s: %s",
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
757 ctx->socket_path,
20941
868cf176e7ff director: Fix crash handling director_flush_socket when user is freed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20940
diff changeset
758 ctx->username_hash,
868cf176e7ff director: Fix crash handling director_flush_socket when user is freed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20940
diff changeset
759 net_ip2addr(&ctx->host_ip),
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
760 data == NULL ? "(no output to stdout)" : data);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
761 while((data = i_stream_read_next_line(is)) != NULL) {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
762 i_error("%s: Failed to flush user hash %u in host %s: %s",
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
763 ctx->socket_path,
20941
868cf176e7ff director: Fix crash handling director_flush_socket when user is freed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20940
diff changeset
764 ctx->username_hash,
868cf176e7ff director: Fix crash handling director_flush_socket when user is freed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20940
diff changeset
765 net_ip2addr(&ctx->host_ip),
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
766 data);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
767 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
768 i_stream_unref(&is);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
769 } else {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
770 o_stream_unref(&ctx->reply);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
771 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
772 program_client_destroy(&ctx->pclient);
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
773
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
774 if (!DIRECTOR_KILL_CONTEXT_IS_VALID(user, ctx)) {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
775 /* user was already freed - ignore */
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
776 dir_debug("User %u freed while flushing, result=%d",
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
777 ctx->username_hash, result);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
778 i_assert(ctx->to_move == NULL);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
779 i_free(ctx);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
780 } else {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
781 /* ctx is freed later via user->kill_ctx */
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
782 dir_debug("Flushing user %u finished, result=%d",
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
783 ctx->username_hash, result);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
784 director_user_kill_finish_delayed(dir, user, result == 1);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
785 }
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
786 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
787
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
788 static void
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
789 director_flush_user(struct director *dir, struct user *user)
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
790 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
791 struct director_kill_context *ctx = user->kill_ctx;
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
792 struct var_expand_table tab[] = {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
793 { 'i', net_ip2addr(&user->host->ip), "ip" },
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
794 { 'h', user->host->hostname, "host" },
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
795 { '\0', NULL, NULL }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
796 };
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
797
20982
d9d2da1b7ecb director: Execute director_flush_socket only from one director.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
798 /* Execute flush script, if set. Only the director that started the
d9d2da1b7ecb director: Execute director_flush_socket only from one director.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
799 user moving will call the flush script. Having each director do it
d9d2da1b7ecb director: Execute director_flush_socket only from one director.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
800 would be redundant since they're all supposed to be performing the
20992
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
801 same flush task to the same backend.
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
802
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
803 Flushing is also not triggered if we're moving a user that we just
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
804 created due to the user move. This means that the user doesn't have
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
805 an old host, so we couldn't really even perform any flushing on the
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
806 backend. */
20982
d9d2da1b7ecb director: Execute director_flush_socket only from one director.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
807 if (*dir->set->director_flush_socket == '\0' ||
20992
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
808 ctx->old_host_ip.family == 0 ||
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
809 !ctx->kill_is_self_initiated) {
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
810 director_user_kill_finish_delayed(dir, user, FALSE);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
811 return;
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
812 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
813
20941
868cf176e7ff director: Fix crash handling director_flush_socket when user is freed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20940
diff changeset
814 ctx->host_ip = user->host->ip;
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
815
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
816 string_t *s_sock = str_new(default_pool, 32);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
817 var_expand(s_sock, dir->set->director_flush_socket, tab);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
818 ctx->socket_path = str_free_without_data(&s_sock);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
819
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
820 const char *error;
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
821 struct program_client_settings set = {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
822 .client_connect_timeout_msecs = 10000,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
823 };
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
824
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
825 restrict_access_init(&set.restrict_set);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
826
20992
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
827 const char *const args[] = {
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
828 "FLUSH",
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
829 t_strdup_printf("%u", user->username_hash),
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
830 net_ip2addr(&ctx->old_host_ip),
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
831 net_ip2addr(&user->host->ip),
22044
c73b9f07b067 director: Add old host's up/down and vhost count parameters to director_flush_socket
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21434
diff changeset
832 ctx->old_host_down ? "down" : "up",
c73b9f07b067 director: Add old host's up/down and vhost count parameters to director_flush_socket
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21434
diff changeset
833 dec2str(ctx->old_host_vhost_count),
20992
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
834 NULL
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
835 };
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
836
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
837 ctx->kill_state = USER_KILL_STATE_FLUSHING;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
838 dir_debug("Flushing user %u via %s", user->username_hash,
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
839 ctx->socket_path);
20979
652b5d0a0365 director: Prevent race conditions by adding USER_KILL_STATE_FLUSHING
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20975
diff changeset
840
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
841 if ((program_client_create(ctx->socket_path, args, &set, FALSE,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
842 &ctx->pclient, &error)) != 0) {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
843 i_error("%s: Failed to flush user hash %u in host %s: %s",
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
844 ctx->socket_path,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
845 user->username_hash,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
846 net_ip2addr(&user->host->ip),
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
847 error);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
848 director_flush_user_continue(0, ctx);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
849 return;
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
850 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
851
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
852 ctx->reply =
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
853 iostream_temp_create_named("/tmp", 0,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
854 t_strdup_printf("flush response from %s",
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
855 net_ip2addr(&user->host->ip)));
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
856 o_stream_set_no_error_handling(ctx->reply, TRUE);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
857 program_client_set_output(ctx->pclient, ctx->reply);
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
858 ctx->callback_pending = TRUE;
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
859 program_client_run_async(ctx->pclient, director_flush_user_continue, ctx);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
860 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
861
22551
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
862 static void director_user_move_finished(struct director *dir)
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
863 {
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
864 i_assert(dir->users_moving_count > 0);
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
865 dir->users_moving_count--;
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
866
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
867 director_set_state_changed(dir);
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
868 }
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
869
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
870 static void director_user_move_free(struct user *user)
20965
eff5fc952993 director: Code cleanup - Finish user move always in the same function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20964
diff changeset
871 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
872 struct director *dir = user->kill_ctx->dir;
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
873 struct director_kill_context *kill_ctx = user->kill_ctx;
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
874
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
875 i_assert(kill_ctx != NULL);
20965
eff5fc952993 director: Code cleanup - Finish user move always in the same function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20964
diff changeset
876
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
877 dir_debug("User %u move finished at state=%s", user->username_hash,
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
878 user_kill_state_names[kill_ctx->kill_state]);
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
879
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
880 if (kill_ctx->to_move != NULL)
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
881 timeout_remove(&kill_ctx->to_move);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
882 i_free(kill_ctx->socket_path);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
883 i_free(kill_ctx);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
884 user->kill_ctx = NULL;
20965
eff5fc952993 director: Code cleanup - Finish user move always in the same function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20964
diff changeset
885
22551
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
886 director_user_move_finished(dir);
20965
eff5fc952993 director: Code cleanup - Finish user move always in the same function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20964
diff changeset
887 }
eff5fc952993 director: Code cleanup - Finish user move always in the same function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20964
diff changeset
888
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
889 static void
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
890 director_user_kill_finish_delayed_to(struct user *user)
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
891 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
892 i_assert(user->kill_ctx != NULL);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
893 i_assert(user->kill_ctx->kill_state == USER_KILL_STATE_DELAY);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
894
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
895 director_user_move_free(user);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
896 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
897
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
898 static void
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
899 director_user_kill_finish_delayed(struct director *dir, struct user *user,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
900 bool skip_delay)
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
901 {
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
902 if (skip_delay) {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
903 user->kill_ctx->kill_state = USER_KILL_STATE_NONE;
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
904 director_user_move_free(user);
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
905 return;
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
906 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
907
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
908 user->kill_ctx->kill_state = USER_KILL_STATE_DELAY;
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
909
19108
3ebba506c2c7 director: Added director_user_kick_delay setting.
Timo Sirainen <tss@iki.fi>
parents: 19035
diff changeset
910 /* wait for a while for the kills to finish in the backend server,
3ebba506c2c7 director: Added director_user_kick_delay setting.
Timo Sirainen <tss@iki.fi>
parents: 19035
diff changeset
911 so there are no longer any processes running for the user before we
3ebba506c2c7 director: Added director_user_kick_delay setting.
Timo Sirainen <tss@iki.fi>
parents: 19035
diff changeset
912 start letting new in connections to the new server. */
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
913 timeout_remove(&user->kill_ctx->to_move);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
914 user->kill_ctx->to_move =
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
915 timeout_add(dir->set->director_user_kick_delay * 1000,
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
916 director_user_kill_finish_delayed_to, user);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
917 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
918
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
919 static void
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
920 director_finish_user_kill(struct director *dir, struct user *user, bool self)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
921 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
922 struct director_kill_context *kill_ctx = user->kill_ctx;
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
923
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
924 i_assert(kill_ctx != NULL);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
925 i_assert(kill_ctx->kill_state != USER_KILL_STATE_FLUSHING);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
926 i_assert(kill_ctx->kill_state != USER_KILL_STATE_DELAY);
19956
e038f95fdccd director: Make sure a long-delayed kill reply for user doesn't mess up the state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
927
21434
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
928 dir_debug("User %u kill finished - %sstate=%s", user->username_hash,
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
929 self ? "we started it " : "",
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
930 user_kill_state_names[kill_ctx->kill_state]);
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
931
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
932 if (dir->right == NULL) {
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
933 /* we're alone */
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
934 director_flush_user(dir, user);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
935 } else if (self ||
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
936 kill_ctx->kill_state == USER_KILL_STATE_KILLING_NOTIFY_RECEIVED) {
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
937 director_connection_send(dir->right, t_strdup_printf(
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
938 "USER-KILLED\t%u\n", user->username_hash));
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
939 kill_ctx->kill_state = USER_KILL_STATE_KILLED_WAITING_FOR_EVERYONE;
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
940 } else {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
941 i_assert(kill_ctx->kill_state == USER_KILL_STATE_KILLING);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
942 kill_ctx->kill_state = USER_KILL_STATE_KILLED_WAITING_FOR_NOTIFY;
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
943 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
944 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
945
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
946 static void director_user_kill_fail_throttled(unsigned int new_events_count,
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
947 void *context ATTR_UNUSED)
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
948 {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
949 i_error("Failed to kill %u users' connections", new_events_count);
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
950 }
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
951
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
952 static void director_kill_user_callback(enum ipc_client_cmd_state state,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
953 const char *data, void *context)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
954 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
955 struct director_kill_context *ctx = context;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
956 struct user *user;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
957
19956
e038f95fdccd director: Make sure a long-delayed kill reply for user doesn't mess up the state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
958 /* this is an asynchronous notification about user being killed.
e038f95fdccd director: Make sure a long-delayed kill reply for user doesn't mess up the state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
959 there are no guarantees about what might have happened to the user
e038f95fdccd director: Make sure a long-delayed kill reply for user doesn't mess up the state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
960 in the mean time. */
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
961 switch (state) {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
962 case IPC_CLIENT_CMD_STATE_REPLY:
19956
e038f95fdccd director: Make sure a long-delayed kill reply for user doesn't mess up the state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
963 /* shouldn't get here. the command reply isn't finished yet. */
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
964 return;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
965 case IPC_CLIENT_CMD_STATE_OK:
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
966 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
967 case IPC_CLIENT_CMD_STATE_ERROR:
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
968 if (log_throttle_accept(user_kill_fail_throttle)) {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
969 i_error("Failed to kill user %u connections: %s",
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
970 ctx->username_hash, data);
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
971 }
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
972 /* we can't really do anything but continue anyway */
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
973 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
974 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
975
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
976 ctx->callback_pending = FALSE;
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
977
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
978 user = user_directory_lookup(ctx->tag->users, ctx->username_hash);
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
979 if (!DIRECTOR_KILL_CONTEXT_IS_VALID(user, ctx)) {
19956
e038f95fdccd director: Make sure a long-delayed kill reply for user doesn't mess up the state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
980 /* user was already freed - ignore */
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
981 i_assert(ctx->to_move == NULL);
22551
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
982 director_user_move_finished(ctx->dir);
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
983 i_free(ctx);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
984 } else {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
985 i_assert(ctx->kill_state == USER_KILL_STATE_KILLING ||
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
986 ctx->kill_state == USER_KILL_STATE_KILLING_NOTIFY_RECEIVED);
19956
e038f95fdccd director: Make sure a long-delayed kill reply for user doesn't mess up the state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
987 /* we were still waiting for the kill notification */
20987
06131e8a7334 director: Code cleanup - rename director_kill_context.self to kill_is_self_initiated
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20986
diff changeset
988 director_finish_user_kill(ctx->dir, user, ctx->kill_is_self_initiated);
19956
e038f95fdccd director: Make sure a long-delayed kill reply for user doesn't mess up the state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
989 }
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
990 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
991
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
992 static void director_user_move_throttled(unsigned int new_events_count,
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
993 void *context ATTR_UNUSED)
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
994 {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
995 i_error("%u users' move timed out, their state may now be inconsistent",
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
996 new_events_count);
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
997 }
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
998
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
999 static void director_user_move_timeout(struct user *user)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1000 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1001 i_assert(user->kill_ctx != NULL);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1002 i_assert(user->kill_ctx->kill_state != USER_KILL_STATE_DELAY);
19956
e038f95fdccd director: Make sure a long-delayed kill reply for user doesn't mess up the state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
1003
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1004 if (log_throttle_accept(user_move_throttle)) {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1005 i_error("Finishing user %u move timed out, "
20975
5a0c765bc608 director: If user move times out, log the state it was in at the time.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20966
diff changeset
1006 "its state may now be inconsistent (state=%s)",
5a0c765bc608 director: If user move times out, log the state it was in at the time.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20966
diff changeset
1007 user->username_hash,
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1008 user_kill_state_names[user->kill_ctx->kill_state]);
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1009 }
21370
6cda62d7de0e director: Fix assert-crash when flush script takes too long
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21314
diff changeset
1010 if (user->kill_ctx->kill_state == USER_KILL_STATE_FLUSHING) {
6cda62d7de0e director: Fix assert-crash when flush script takes too long
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21314
diff changeset
1011 o_stream_unref(&user->kill_ctx->reply);
6cda62d7de0e director: Fix assert-crash when flush script takes too long
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21314
diff changeset
1012 program_client_destroy(&user->kill_ctx->pclient);
6cda62d7de0e director: Fix assert-crash when flush script takes too long
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21314
diff changeset
1013 }
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1014 director_user_move_free(user);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1015 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1016
22506
3afbfedcdd31 director: Fix crash when flush is run and all backends are down.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22044
diff changeset
1017 void director_kill_user(struct director *dir, struct director_host *src,
3afbfedcdd31 director: Fix crash when flush is run and all backends are down.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22044
diff changeset
1018 struct user *user, struct mail_tag *tag,
22510
3c4348ffe0d6 director: Fix flush to kick the user also when all backends are down
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22508
diff changeset
1019 struct mail_host *old_host, bool forced_kick)
20990
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1020 {
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1021 struct director_kill_context *ctx;
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1022 const char *cmd;
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1023
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1024 if (USER_IS_BEING_KILLED(user)) {
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1025 /* User is being moved again before the previous move
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1026 finished. We'll just continue wherever we left off
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1027 earlier. */
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1028 dir_debug("User %u move restarted - previous kill_state=%s",
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1029 user->username_hash,
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1030 user_kill_state_names[user->kill_ctx->kill_state]);
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1031 return;
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1032 }
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1033
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1034 user->kill_ctx = ctx = i_new(struct director_kill_context, 1);
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1035 ctx->dir = dir;
21081
b67815b341b9 director: Fix crash when receiving USER-MOVE for nonexistent user.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21079
diff changeset
1036 ctx->tag = tag;
20990
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1037 ctx->username_hash = user->username_hash;
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1038 ctx->kill_is_self_initiated = src->self;
22044
c73b9f07b067 director: Add old host's up/down and vhost count parameters to director_flush_socket
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21434
diff changeset
1039 if (old_host != NULL) {
20992
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
1040 ctx->old_host_ip = old_host->ip;
22044
c73b9f07b067 director: Add old host's up/down and vhost count parameters to director_flush_socket
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21434
diff changeset
1041 ctx->old_host_down = old_host->down;
c73b9f07b067 director: Add old host's up/down and vhost count parameters to director_flush_socket
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21434
diff changeset
1042 ctx->old_host_vhost_count = old_host->vhost_count;
c73b9f07b067 director: Add old host's up/down and vhost count parameters to director_flush_socket
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21434
diff changeset
1043 }
20990
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1044
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1045 dir->users_moving_count++;
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1046 ctx->to_move = timeout_add(DIRECTOR_USER_MOVE_TIMEOUT_MSECS,
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1047 director_user_move_timeout, user);
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1048 ctx->kill_state = USER_KILL_STATE_KILLING;
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1049
22510
3c4348ffe0d6 director: Fix flush to kick the user also when all backends are down
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22508
diff changeset
1050 if ((old_host != NULL && old_host != user->host) || forced_kick) {
20991
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1051 cmd = t_strdup_printf("proxy\t*\tKICK-DIRECTOR-HASH\t%u",
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1052 user->username_hash);
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1053 ctx->callback_pending = TRUE;
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1054 ipc_client_cmd(dir->ipc_proxy, cmd,
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1055 director_kill_user_callback, ctx);
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1056 } else {
21433
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1057 /* a) we didn't even know about the user before now.
20991
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1058 don't bother performing a local kick, since it wouldn't
21433
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1059 kick anything.
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1060 b) our host was already correct. notify others that we have
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1061 killed the user, but don't really do it. */
20991
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1062 director_finish_user_kill(ctx->dir, user,
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1063 ctx->kill_is_self_initiated);
9fb54c8827fb director: User move - Don't try to kick user's connections if user wasn't even known.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20990
diff changeset
1064 }
20990
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1065 }
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1066
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1067 void director_move_user(struct director *dir, struct director_host *src,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1068 struct director_host *orig_src,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1069 unsigned int username_hash, struct mail_host *host)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1070 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1071 struct user_directory *users = host->tag->users;
21431
784f3ca6ebfb director: Make sure USER-KILLED isn't sent before USER-MOVE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21430
diff changeset
1072 struct mail_host *old_host = NULL;
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1073 struct user *user;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1074
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1075 /* 1. move this user's host, and set its "killing" flag to delay all of
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1076 its future connections until all directors have killed the
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1077 connections and notified us about it.
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1078
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1079 2. tell the other directors about the move
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1080
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1081 3. once user kill callback is called, tell the other directors
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1082 with USER-KILLED that we're done killing the user.
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1083
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1084 4. when some director gets a duplicate USER-KILLED, it's
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1085 responsible for notifying all directors that user is completely
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1086 killed.
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1087
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1088 5. after receiving USER-KILLED-EVERYWHERE notification,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1089 new connections are again allowed for the user.
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1090 */
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
1091 user = user_directory_lookup(users, username_hash);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1092 if (user == NULL) {
21434
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
1093 dir_debug("User %u move started: User was nonexistent",
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
1094 username_hash);
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
1095 user = user_directory_add(users, username_hash,
14487
45be27ff3414 director: Removed special (time_t)-1 code, it's not actually needed.
Timo Sirainen <tss@iki.fi>
parents: 14472
diff changeset
1096 host, ioloop_time);
21433
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1097 } else if (user->host == host) {
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1098 /* User is already in the wanted host, but another director
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1099 didn't think so. We'll need to finish the move without
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1100 killing any of our connections. */
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1101 old_host = user->host;
90978a28d9d5 director: Fix USER-MOVE getting stuck if a director already uses the correct host
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21431
diff changeset
1102 user->timestamp = ioloop_time;
21434
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
1103 dir_debug("User %u move forwarded: host is already %s",
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
1104 username_hash, net_ip2addr(&host->ip));
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1105 } else {
21430
1ce6c0be2213 director: Add assert to make sure USER-MOVE doesn't change tag
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
1106 /* user is looked up via the new host's tag, so if it's found
1ce6c0be2213 director: Add assert to make sure USER-MOVE doesn't change tag
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
1107 the old tag has to be the same. */
1ce6c0be2213 director: Add assert to make sure USER-MOVE doesn't change tag
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
1108 i_assert(user->host->tag == host->tag);
1ce6c0be2213 director: Add assert to make sure USER-MOVE doesn't change tag
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
1109
21431
784f3ca6ebfb director: Make sure USER-KILLED isn't sent before USER-MOVE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21430
diff changeset
1110 old_host = user->host;
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1111 user->host->user_count--;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1112 user->host = host;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1113 user->host->user_count++;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1114 user->timestamp = ioloop_time;
21434
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
1115 dir_debug("User %u move started: host %s -> %s",
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
1116 username_hash, net_ip2addr(&old_host->ip),
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
1117 net_ip2addr(&host->ip));
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1118 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1119
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1120 if (orig_src == NULL) {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1121 orig_src = dir->self_host;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1122 orig_src->last_seq++;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1123 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1124 director_update_send(dir, src, t_strdup_printf(
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1125 "USER-MOVE\t%s\t%u\t%u\t%u\t%s\n",
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1126 net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1127 user->username_hash, net_ip2addr(&user->host->ip)));
21431
784f3ca6ebfb director: Make sure USER-KILLED isn't sent before USER-MOVE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21430
diff changeset
1128 /* kill the user only after sending the USER-MOVE, because the kill
784f3ca6ebfb director: Make sure USER-KILLED isn't sent before USER-MOVE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21430
diff changeset
1129 may finish instantly. */
22510
3c4348ffe0d6 director: Fix flush to kick the user also when all backends are down
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22508
diff changeset
1130 director_kill_user(dir, src, user, host->tag, old_host, FALSE);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1131 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1132
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1133 static void
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1134 director_kick_user_callback(enum ipc_client_cmd_state state ATTR_UNUSED,
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1135 const char *data ATTR_UNUSED,
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1136 void *context ATTR_UNUSED)
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1137 {
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1138 }
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1139
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1140 void director_kick_user(struct director *dir, struct director_host *src,
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1141 struct director_host *orig_src, const char *username)
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1142 {
20844
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1143 string_t *cmd = t_str_new(64);
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1144
20844
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1145 str_append(cmd, "proxy\t*\tKICK\t");
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1146 str_append_tabescaped(cmd, username);
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1147 ipc_client_cmd(dir->ipc_proxy, str_c(cmd),
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1148 director_kick_user_callback, (void *)NULL);
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1149
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1150 if (orig_src == NULL) {
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1151 orig_src = dir->self_host;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1152 orig_src->last_seq++;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1153 }
21313
a309b9ab46e6 director: Fix USER-KICK and USER-KICK-ALT forwarding
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21081
diff changeset
1154 str_truncate(cmd, 0);
20844
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1155 str_printfa(cmd, "USER-KICK\t%s\t%u\t%u\t",
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1156 net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq);
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1157 str_append_tabescaped(cmd, username);
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1158 str_append_c(cmd, '\n');
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1159 director_update_send_version(dir, src, DIRECTOR_VERSION_USER_KICK, str_c(cmd));
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1160 }
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1161
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1162 void director_kick_user_alt(struct director *dir, struct director_host *src,
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1163 struct director_host *orig_src,
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1164 const char *field, const char *value)
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1165 {
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1166 string_t *cmd = t_str_new(64);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1167
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1168 str_append(cmd, "proxy\t*\tKICK-ALT\t");
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1169 str_append_tabescaped(cmd, field);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1170 str_append_c(cmd, '\t');
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1171 str_append_tabescaped(cmd, value);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1172 ipc_client_cmd(dir->ipc_proxy, str_c(cmd),
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1173 director_kick_user_callback, (void *)NULL);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1174
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1175 if (orig_src == NULL) {
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1176 orig_src = dir->self_host;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1177 orig_src->last_seq++;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1178 }
21313
a309b9ab46e6 director: Fix USER-KICK and USER-KICK-ALT forwarding
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21081
diff changeset
1179 str_truncate(cmd, 0);
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1180 str_printfa(cmd, "USER-KICK-ALT\t%s\t%u\t%u\t",
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1181 net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1182 str_append_tabescaped(cmd, field);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1183 str_append_c(cmd, '\t');
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1184 str_append_tabescaped(cmd, value);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1185 str_append_c(cmd, '\n');
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1186 director_update_send_version(dir, src, DIRECTOR_VERSION_USER_KICK_ALT, str_c(cmd));
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1187 }
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1188
17419
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1189 void director_kick_user_hash(struct director *dir, struct director_host *src,
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1190 struct director_host *orig_src,
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1191 unsigned int username_hash,
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1192 const struct ip_addr *except_ip)
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1193 {
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1194 const char *cmd;
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1195
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1196 cmd = t_strdup_printf("proxy\t*\tKICK-DIRECTOR-HASH\t%u\t%s",
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1197 username_hash, net_ip2addr(except_ip));
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1198 ipc_client_cmd(dir->ipc_proxy, cmd,
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1199 director_kick_user_callback, (void *)NULL);
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1200
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1201 if (orig_src == NULL) {
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1202 orig_src = dir->self_host;
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1203 orig_src->last_seq++;
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1204 }
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1205 cmd = t_strdup_printf("USER-KICK-HASH\t%s\t%u\t%u\t%u\t%s\n",
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1206 net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq,
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1207 username_hash, net_ip2addr(except_ip));
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1208 director_update_send_version(dir, src, DIRECTOR_VERSION_USER_KICK, cmd);
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1209 }
8aa0cd95d6a8 director: If we detect that a user is being proxied to multiple backends, disconnect wrong connections.
Timo Sirainen <tss@iki.fi>
parents: 17418
diff changeset
1210
20980
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1211 static void
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1212 director_send_user_killed_everywhere(struct director *dir,
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1213 struct director_host *src,
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1214 struct director_host *orig_src,
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1215 unsigned int username_hash)
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1216 {
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1217 if (orig_src == NULL) {
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1218 orig_src = dir->self_host;
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1219 orig_src->last_seq++;
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1220 }
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1221 director_update_send(dir, src, t_strdup_printf(
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1222 "USER-KILLED-EVERYWHERE\t%s\t%u\t%u\t%u\n",
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1223 net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq,
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1224 username_hash));
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1225 }
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1226
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1227 static void
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1228 director_user_tag_killed(struct director *dir, struct mail_tag *tag,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1229 unsigned int username_hash)
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1230 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1231 struct user *user;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1232
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1233 user = user_directory_lookup(tag->users, username_hash);
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1234 if (user == NULL || !USER_IS_BEING_KILLED(user))
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1235 return;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1236
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1237 switch (user->kill_ctx->kill_state) {
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1238 case USER_KILL_STATE_KILLING:
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1239 user->kill_ctx->kill_state = USER_KILL_STATE_KILLING_NOTIFY_RECEIVED;
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1240 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1241 case USER_KILL_STATE_KILLED_WAITING_FOR_NOTIFY:
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1242 director_finish_user_kill(dir, user, TRUE);
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1243 break;
20980
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1244 case USER_KILL_STATE_KILLING_NOTIFY_RECEIVED:
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1245 dir_debug("User %u kill_state=%s - ignoring USER-KILLED",
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1246 username_hash, user_kill_state_names[user->kill_ctx->kill_state]);
20980
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1247 break;
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1248 case USER_KILL_STATE_NONE:
20979
652b5d0a0365 director: Prevent race conditions by adding USER_KILL_STATE_FLUSHING
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20975
diff changeset
1249 case USER_KILL_STATE_FLUSHING:
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1250 case USER_KILL_STATE_DELAY:
20980
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1251 /* move restarted. state=none can also happen if USER-MOVE was
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1252 sent while we were still moving. send back
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1253 USER-KILLED-EVERYWHERE to avoid hangs. */
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1254 director_send_user_killed_everywhere(dir, dir->self_host, NULL,
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1255 username_hash);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1256 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1257 case USER_KILL_STATE_KILLED_WAITING_FOR_EVERYONE:
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1258 director_user_killed_everywhere(dir, dir->self_host,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1259 NULL, username_hash);
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1260 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1261 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1262 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1263
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1264 void director_user_killed(struct director *dir, unsigned int username_hash)
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1265 {
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1266 struct mail_tag *const *tagp;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1267
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1268 array_foreach(mail_hosts_get_tags(dir->mail_hosts), tagp)
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1269 director_user_tag_killed(dir, *tagp, username_hash);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1270 }
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1271
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1272 static void
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1273 director_user_tag_killed_everywhere(struct director *dir,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1274 struct mail_tag *tag,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1275 struct director_host *src,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1276 struct director_host *orig_src,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1277 unsigned int username_hash)
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1278 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1279 struct user *user;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1280
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1281 user = user_directory_lookup(tag->users, username_hash);
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1282 if (user == NULL) {
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1283 dir_debug("User %u no longer exists - ignoring USER-KILLED-EVERYWHERE",
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1284 username_hash);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1285 return;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1286 }
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1287 if (!USER_IS_BEING_KILLED(user)) {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1288 dir_debug("User %u is no longer being killed - ignoring USER-KILLED-EVERYWHERE",
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1289 username_hash);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1290 return;
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1291 }
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1292 if (user->kill_ctx->kill_state != USER_KILL_STATE_KILLED_WAITING_FOR_EVERYONE) {
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1293 dir_debug("User %u kill_state=%s - ignoring USER-KILLED-EVERYWHERE",
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1294 username_hash, user_kill_state_names[user->kill_ctx->kill_state]);
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1295 return;
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1296 }
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1297
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
1298 director_flush_user(dir, user);
20980
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1299 director_send_user_killed_everywhere(dir, src, orig_src, username_hash);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1300 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1301
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1302 void director_user_killed_everywhere(struct director *dir,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1303 struct director_host *src,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1304 struct director_host *orig_src,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1305 unsigned int username_hash)
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1306 {
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1307 struct mail_tag *const *tagp;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1308
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1309 array_foreach(mail_hosts_get_tags(dir->mail_hosts), tagp) {
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1310 director_user_tag_killed_everywhere(dir, *tagp, src, orig_src,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1311 username_hash);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1312 }
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1313 }
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1314
15321
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1315 static void director_state_callback_timeout(struct director *dir)
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1316 {
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1317 timeout_remove(&dir->to_callback);
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1318 dir->state_change_callback(dir);
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1319 }
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1320
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1321 void director_set_state_changed(struct director *dir)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1322 {
15321
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1323 /* we may get called to here from various places. use a timeout to
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1324 make sure the state callback is called with a clean state. */
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1325 if (dir->to_callback == NULL) {
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1326 dir->to_callback =
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1327 timeout_add(0, director_state_callback_timeout, dir);
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1328 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1329 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1330
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1331 void director_update_send(struct director *dir, struct director_host *src,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1332 const char *cmd)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1333 {
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1334 director_update_send_version(dir, src, 0, cmd);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1335 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1336
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1337 void director_update_send_version(struct director *dir,
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1338 struct director_host *src,
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1339 unsigned int min_version, const char *cmd)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1340 {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1341 struct director_connection *const *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1342
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1343 i_assert(src != NULL);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1344
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1345 array_foreach(&dir->connections, connp) {
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1346 if (director_connection_get_host(*connp) != src &&
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1347 director_connection_get_minor_version(*connp) >= min_version)
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1348 director_connection_send(*connp, cmd);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1349 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1350 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1351
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1352 static void director_user_freed(struct user *user)
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1353 {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1354 if (user->kill_ctx != NULL) {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1355 /* director_user_expire is very short. user expired before
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1356 moving the user finished or timed out. */
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1357 if (user->kill_ctx->callback_pending) {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1358 /* kill_ctx is used as a callback parameter.
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1359 only remove the timeout and finish the free later. */
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1360 if (user->kill_ctx->to_move != NULL)
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1361 timeout_remove(&user->kill_ctx->to_move);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1362 } else {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1363 director_user_move_free(user);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1364 }
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1365 }
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1366 }
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1367
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1368 struct director *
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1369 director_init(const struct director_settings *set,
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18729
diff changeset
1370 const struct ip_addr *listen_ip, in_port_t listen_port,
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1371 director_state_change_callback_t *callback)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1372 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1373 struct director *dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1374
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1375 dir = i_new(struct director, 1);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1376 dir->set = set;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1377 dir->self_port = listen_port;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1378 dir->self_ip = *listen_ip;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1379 dir->state_change_callback = callback;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1380 i_array_init(&dir->dir_hosts, 16);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1381 i_array_init(&dir->pending_requests, 16);
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1382 i_array_init(&dir->connections, 8);
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1383 dir->mail_hosts = mail_hosts_init(set->director_user_expire,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1384 set->director_consistent_hashing,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1385 director_user_freed);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1386
13809
ddf28d10ff0f director: Don't explicitly use base_dir. We're already chdired there, use relative paths.
Timo Sirainen <tss@iki.fi>
parents: 13049
diff changeset
1387 dir->ipc_proxy = ipc_client_init(DIRECTOR_IPC_PROXY_PATH);
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1388 dir->ring_min_version = DIRECTOR_VERSION_MINOR;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1389 return dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1390 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1391
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1392 void director_deinit(struct director **_dir)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1393 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1394 struct director *dir = *_dir;
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1395 struct director_host *const *hostp, *host;
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1396 struct director_connection *conn, *const *connp;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1397
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1398 *_dir = NULL;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1399
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1400 while (array_count(&dir->connections) > 0) {
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1401 connp = array_idx(&dir->connections, 0);
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1402 conn = *connp;
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
1403 director_connection_deinit(&conn, "Shutting down");
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1404 }
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1405
11352
19336bddada2 director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1406 mail_hosts_deinit(&dir->mail_hosts);
11353
1bc3d5589c5a doveadm director status user: Show more ways of what user's potential hosts are.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1407 mail_hosts_deinit(&dir->orig_config_hosts);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1408
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1409 ipc_client_deinit(&dir->ipc_proxy);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
1410 if (dir->to_reconnect != NULL)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
1411 timeout_remove(&dir->to_reconnect);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
1412 if (dir->to_handshake_warning != NULL)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
1413 timeout_remove(&dir->to_handshake_warning);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1414 if (dir->to_request != NULL)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1415 timeout_remove(&dir->to_request);
13941
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
1416 if (dir->to_sync != NULL)
493ebb2cfc73 director: Added timeout to syncing to make sure we don't hang if it somehow gets lost.
Timo Sirainen <tss@iki.fi>
parents: 13935
diff changeset
1417 timeout_remove(&dir->to_sync);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1418 if (dir->to_remove_dirs != NULL)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1419 timeout_remove(&dir->to_remove_dirs);
15321
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1420 if (dir->to_callback != NULL)
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1421 timeout_remove(&dir->to_callback);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1422 while (array_count(&dir->dir_hosts) > 0) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1423 hostp = array_idx(&dir->dir_hosts, 0);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1424 host = *hostp;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1425 director_host_free(&host);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1426 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1427 array_free(&dir->pending_requests);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1428 array_free(&dir->dir_hosts);
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1429 array_free(&dir->connections);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1430 i_free(dir);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1431 }
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1432
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1433 void dir_debug(const char *fmt, ...)
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1434 {
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1435 va_list args;
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1436
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1437 if (!director_debug)
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1438 return;
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1439
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1440 va_start(args, fmt);
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1441 T_BEGIN {
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1442 i_debug("%s", t_strdup_vprintf(fmt, args));
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1443 } T_END;
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1444 va_end(args);
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1445 }
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1446
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1447 struct director_user_iter {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1448 struct director *dir;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1449 unsigned int tag_idx;
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1450 struct user_directory_iter *user_iter;
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1451 };
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1452
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1453 struct director_user_iter *director_iterate_users_init(struct director *dir)
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1454 {
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1455 struct director_user_iter *iter = i_new(struct director_user_iter, 1);
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1456 iter->dir = dir;
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1457 return iter;
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1458 }
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1459
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1460 struct user *director_iterate_users_next(struct director_user_iter *iter)
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1461 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1462 const ARRAY_TYPE(mail_tag) *tags;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1463 struct user *user;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1464
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1465 i_assert(iter != NULL);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1466
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1467 if (iter->user_iter == NULL) {
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1468 tags = mail_hosts_get_tags(iter->dir->mail_hosts);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1469 if (iter->tag_idx >= array_count(tags))
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1470 return NULL;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1471 struct mail_tag *const *tagp = array_idx(tags, iter->tag_idx);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1472 iter->user_iter = user_directory_iter_init((*tagp)->users);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1473 }
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1474 user = user_directory_iter_next(iter->user_iter);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1475 if (user == NULL) {
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1476 user_directory_iter_deinit(&iter->user_iter);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1477 iter->tag_idx++;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1478 return director_iterate_users_next(iter);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1479 } else
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1480 return user;
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1481 }
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1482
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1483 void director_iterate_users_deinit(struct director_user_iter **_iter)
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1484 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1485 i_assert(_iter != NULL && *_iter != NULL);
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1486 struct director_user_iter *iter = *_iter;
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1487 *_iter = NULL;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1488 if (iter->user_iter != NULL)
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1489 user_directory_iter_deinit(&iter->user_iter);
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1490 i_free(iter);
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1491 }
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1492
21076
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1493 unsigned int
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1494 director_get_username_hash(struct director *dir, const char *username)
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1495 {
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1496 return mail_user_hash(username, dir->set->director_username_hash);
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1497 }
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1498
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1499 void directors_init(void)
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1500 {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1501 user_move_throttle =
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1502 log_throttle_init(&director_log_throttle_settings,
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1503 director_user_move_throttled, NULL);
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1504 user_kill_fail_throttle =
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1505 log_throttle_init(&director_log_throttle_settings,
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1506 director_user_kill_fail_throttled, NULL);
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1507 }
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1508
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1509 void directors_deinit(void)
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1510 {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1511 log_throttle_deinit(&user_move_throttle);
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1512 log_throttle_deinit(&user_kill_fail_throttle);
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1513 }