annotate src/director/director.c @ 23017:c1d36f2575c7 default tip

lib-imap: Fix "Don't accept strings with NULs" cherry-pick
author Timo Sirainen <timo.sirainen@open-xchange.com>
date Thu, 29 Aug 2019 09:55:25 +0300
parents 75d7b38afb60
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 22676
diff changeset
1 /* Copyright (c) 2010-2018 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
22575
33ced9ab0572 director: When ring is synced, purge any pending "removed" directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22574
diff changeset
46 static void director_hosts_purge_removed(struct director *dir);
33ced9ab0572 director: When ring is synced, purge any pending "removed" directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22574
diff changeset
47
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
48 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
49 .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
50 .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
51 };
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
52
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
53 static void
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
54 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
55 bool skip_delay);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
56
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 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
58 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 struct ip_addr ip;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 net_get_ip_any4(&ip);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 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
63 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 net_get_ip_any6(&ip);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 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
67 return FALSE;
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 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 }
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 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
73 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 struct director_host *const *hosts;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 unsigned int i, count;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 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
78 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
79 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
80 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
81 return;
7d3d6ee01bfc director: Use net_try_bind() to try to find our own IP.
Timo Sirainen <tss@iki.fi>
parents: 11339
diff changeset
82 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 }
11341
7d3d6ee01bfc director: Use net_try_bind() to try to find our own IP.
Timo Sirainen <tss@iki.fi>
parents: 11339
diff changeset
84 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
85 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86
13935
b8fa70a81c8c director: Find director's own IP earlier in init.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
87 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
88 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 if (dir->self_host != NULL)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91
11339
ed633bfb8c59 director: Fixed finding the director's own IP in case system has multiple.
Timo Sirainen <tss@iki.fi>
parents: 11338
diff changeset
92 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
93 director_find_self_ip(dir);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 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
96 dir->self_port);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 if (dir->self_host == NULL) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 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
99 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
100 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 dir->self_host->self = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 }
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 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
105 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 struct director_host *const *hosts;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 unsigned int i, count;
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 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
110
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 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
112 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
113 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
114 return i;
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 i_unreached();
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
119 static bool
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
120 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
121 struct director_host *host)
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 struct director_connection *const *connp;
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
124
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
125 array_foreach(&dir->connections, connp) {
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
126 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
127 !director_connection_is_incoming(*connp))
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
128 return TRUE;
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 return FALSE;
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
131 }
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
132
22563
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
133 static void
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
134 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
135 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
136 {
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
137 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
138
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
139 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
140 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
141 (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
142 }
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
143 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
144 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
145 (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
146 }
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
147 i_info("Connecting to %s:%u (as %s%s): %s",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
148 host->ip_str, host->port,
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
149 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
150 }
ef58e0487991 director: Cleanup - move code to a new director_log_connect()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
151
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
152 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
153 const char *reason)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 {
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18729
diff changeset
155 in_port_t port;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 int fd;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
158 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
159 return 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
161 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
162 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
163 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
164 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
165 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
166 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
167 return -1;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 }
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
169 /* 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
170 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
171 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
172
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
173 (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
174 return 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
177 static struct director_host *
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
178 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
179 {
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
180 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
181 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
182
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
183 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
184 if (count == 1) {
a71bc8dbe53d director: Avoid crashing if all directors are removed when reconnecting.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
185 /* self */
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
186 return NULL;
14388
a71bc8dbe53d director: Avoid crashing if all directors are removed when reconnecting.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
187 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
188
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
189 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
190 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
191 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
192 if (!host->removed)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
193 return host;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
194 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
195 /* 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
196 return NULL;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
197 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
198
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
199 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
200 {
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
201 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
202 }
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
203
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
204 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
205 {
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
206 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
207
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
208 /* 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
209 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
210 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
211 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
212 return FALSE;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
213
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
214 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
215 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
216 /* 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
217 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
218 (*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
219 (*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
220 }
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
221 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
222 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
223 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
224 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
225 return TRUE;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
226 }
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
227
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
228 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
229 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 struct director_host *const *hosts;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
231 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
232
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 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
234
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
235 /* 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
236 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
237 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
238 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
239 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
240
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
241 if (hosts[idx]->removed)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
242 continue;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
243
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
244 if (hosts[idx]->last_network_failure +
11349
350208d17fcd director: Fixes to connecting to remote director.
Timo Sirainen <tss@iki.fi>
parents: 11343
diff changeset
245 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
246 /* 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
247 continue;
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
248 }
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
249 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
250 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
251 /* 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
252 don't try retrying yet */
11349
350208d17fcd director: Fixes to connecting to remote director.
Timo Sirainen <tss@iki.fi>
parents: 11343
diff changeset
253 continue;
350208d17fcd director: Fixes to connecting to remote director.
Timo Sirainen <tss@iki.fi>
parents: 11343
diff changeset
254 }
350208d17fcd director: Fixes to connecting to remote director.
Timo Sirainen <tss@iki.fi>
parents: 11343
diff changeset
255
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22563
diff changeset
256 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
257 /* success */
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
258 return;
12935
e9139f74c451 director: Improved debug/error logging.
Timo Sirainen <tss@iki.fi>
parents: 12934
diff changeset
259 }
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
260 }
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
261
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
262 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
263 return;
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
264
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
265 /* 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
266 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
267 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
268 "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
269 }
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
270 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
271 /* 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
272 it must have failed recently */
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
273 i_warning("director: Assuming %s is dead, disconnecting",
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
274 director_connection_get_name(dir->left));
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
275 director_connection_deinit(&dir->left,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
276 "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
277 }
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
278 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
279 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
280 director_set_ring_handshaked(dir);
22573
0813fee4d105 director: Fix potential panic when director is alone
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22572
diff changeset
281 else if (!dir->ring_synced)
14492
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
282 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
283 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
284
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
285 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
286 {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
287 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
288
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
289 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
290 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
291 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
292 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
293 "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
294 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
295 }
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
296 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
297
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
298 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
299 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
300 }
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 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
303 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
304 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
305 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
306
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
307 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
308 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
309
14388
a71bc8dbe53d director: Avoid crashing if all directors are removed when reconnecting.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
310 if (preferred_host == NULL) {
a71bc8dbe53d director: Avoid crashing if all directors are removed when reconnecting.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
311 /* 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
312 } 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
313 (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
314 "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
315 } else {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
316 /* 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
317 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
318 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
319 }
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 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
322 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
323 struct director_host *host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
324
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
325 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
326 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
327 (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
328
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
329 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
330 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
331 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
332 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
333 "(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
334 (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
335 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
336 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
337 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
338
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
339 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
340 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
341
f880cf0efa0a director: Try harder to connect to ring before thinking we're alone.
Timo Sirainen <tss@iki.fi>
parents: 14491
diff changeset
342 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
343 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
344 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
345 /* 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
346 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
347 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
348 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
349 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
350
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
351 if (dir->left != NULL)
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
352 director_connection_set_synced(dir->left, TRUE);
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
353 if (dir->right != NULL)
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
354 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
355 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
356 timeout_remove(&dir->to_sync);
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
357 dir->ring_synced = TRUE;
13921
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
358 dir->ring_last_sync_time = ioloop_time;
22575
33ced9ab0572 director: When ring is synced, purge any pending "removed" directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22574
diff changeset
359 /* If there are any director hosts still marked as "removed", we can
33ced9ab0572 director: When ring is synced, purge any pending "removed" directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22574
diff changeset
360 safely remove those now. The entire director cluster knows about the
33ced9ab0572 director: When ring is synced, purge any pending "removed" directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22574
diff changeset
361 removal now. */
33ced9ab0572 director: When ring is synced, purge any pending "removed" directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22574
diff changeset
362 director_hosts_purge_removed(dir);
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
363 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
364 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
365 }
d1012db03a1c director: If we logged that we're delaying connections, also log when we continue.
Timo Sirainen <tss@iki.fi>
parents: 11341
diff changeset
366
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
367 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
368 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
369 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
370 {
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
371 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
372
22629
0281041d5067 director: Track show long the last ring sync took.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22575
diff changeset
373 if (host == dir->self_host) {
19954
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
374 dir->last_sync_sent_ring_change_counter = dir->ring_change_counter;
22629
0281041d5067 director: Track show long the last ring sync took.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22575
diff changeset
375 dir->last_sync_start_time = ioloop_timeval;
0281041d5067 director: Track show long the last ring sync took.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22575
diff changeset
376 }
19954
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
377
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
378 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
379 str_printfa(str, "SYNC\t%s\t%u\t%u",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
380 host->ip_str, 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
381 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
382 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
383 /* 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
384 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
385 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
386 }
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
387 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
388 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
389
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
390 /* 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
391 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
392 if (dir->left != NULL)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
393 director_connection_ping(dir->left);
17464
203b3a6f508f Removed pointless NULL checks.
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
394 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
395 }
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14292
diff changeset
396
22667
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
397 static bool
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
398 director_has_any_outgoing_connections(struct director *dir)
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
399 {
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
400 struct director_connection *const *connp;
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
401
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
402 array_foreach(&dir->connections, connp) {
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
403 if (!director_connection_is_incoming(*connp))
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
404 return TRUE;
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
405 }
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
406 return FALSE;
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
407 }
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
408
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
409 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
410 {
22667
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
411 if (dir->ring_synced) {
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
412 /* everything ok, no need to do anything */
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
413 return FALSE;
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
414 }
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
415
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
416 if (dir->right == NULL) {
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
417 /* right side connection is missing. make sure we're not
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
418 hanging due to some bug. */
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
419 if (dir->to_reconnect == NULL &&
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
420 !director_has_any_outgoing_connections(dir)) {
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
421 i_warning("Right side connection is unexpectedly lost, reconnecting");
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
422 director_connect(dir, "Right side connection lost");
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
423 }
6b14fe31f657 director: Make sure a missing right-side connection is always reconnected
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22660
diff changeset
424 } else if (dir->left != NULL) {
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
425 /* 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
426 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
427 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
428 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
429 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
430 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
431 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
432 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
433 }
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
434 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
435 }
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
436
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
437 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
438 {
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
439 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
440
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
441 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
442 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
443 }
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
444
13921
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
445 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
446 {
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
447 if (dir->ring_synced) {
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
448 dir->ring_synced = FALSE;
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
449 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
450 }
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
451
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
452 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
453 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
454 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
455 } 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
456 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
457 }
13921
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
458 }
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13809
diff changeset
459
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
460 static void director_sync(struct director *dir)
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
461 {
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
462 /* 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
463 dir->sync_seq++;
14652
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
464 if (dir->right == NULL && dir->left == NULL) {
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
465 /* we're alone. if we're already synced,
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
466 don't become unsynced. */
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
467 return;
46d01b728647 director: Fixed working as standalone.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
468 }
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
469 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
470
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
471 if (dir->sync_frozen) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
472 dir->sync_pending = TRUE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
473 return;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
474 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
475 if (dir->right == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
476 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
477 (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
478 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
479 dir->sync_seq);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
480 return;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
481 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
482
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
483 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
484 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
485 director_connection_get_name(dir->right));
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
486
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
487 /* 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
488 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
489 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
490 if (dir->left != NULL)
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
491 director_connection_set_synced(dir->left, FALSE);
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14388
diff changeset
492 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
493 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
494 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
495 mail_hosts_hash(dir->mail_hosts));
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
496 }
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
497
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
498 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
499 {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
500 struct director_connection *const *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
501
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
502 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
503 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
504
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
505 array_foreach(&dir->connections, connp)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
506 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
507 dir->sync_frozen = TRUE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
508 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
509
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
510 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
511 {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
512 struct director_connection *const *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
513
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
514 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
515
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
516 dir->sync_frozen = FALSE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
517 if (dir->sync_pending) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
518 dir->sync_pending = FALSE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
519 director_sync(dir);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
520 }
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
521 array_foreach(&dir->connections, connp)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
522 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
523 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
524
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
525 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
526 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
527 {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
528 const char *cmd;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
529
22562
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
530 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
531 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
532 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
533 }
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
534
19954
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
535 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
536 cmd = t_strdup_printf("DIRECTOR\t%s\t%u\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
537 added_host->ip_str, added_host->port);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
538 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
539 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
540
22574
7829235b8ac6 director: Rename director_delayed_dir_remove_timeout() to director_hosts_purge_removed()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22573
diff changeset
541 static void director_hosts_purge_removed(struct director *dir)
14571
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 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
544 unsigned int i, count;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
545
22575
33ced9ab0572 director: When ring is synced, purge any pending "removed" directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22574
diff changeset
546 if (dir->to_remove_dirs != NULL)
33ced9ab0572 director: When ring is synced, purge any pending "removed" directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22574
diff changeset
547 timeout_remove(&dir->to_remove_dirs);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
548
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
549 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
550 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
551 if (hosts[i]->removed) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
552 host = hosts[i];
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
553 director_host_free(&host);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
554 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
555 } else {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
556 i++;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
557 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
558 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
559 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
560
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
561 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
562 struct director_host *src)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
563 {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
564 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
565 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
566 unsigned int i, count;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
567 const char *cmd;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
568
22562
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22561
diff changeset
569 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
570 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
571
22572
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
572 if (removed_host->self && !src->self) {
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
573 /* 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
574 return;
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
22572
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
577 if (!removed_host->self) {
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
578 /* mark the host as removed and fully remove it later. this
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
579 delay is needed, because the removal may trigger director
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
580 reconnections, which may send the director back and we don't
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
581 want to re-add it */
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
582 removed_host->removed = TRUE;
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
583 if (dir->to_remove_dirs == NULL) {
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
584 dir->to_remove_dirs =
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
585 timeout_add(DIRECTOR_DELAYED_DIR_REMOVE_MSECS,
22574
7829235b8ac6 director: Rename director_delayed_dir_remove_timeout() to director_hosts_purge_removed()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22573
diff changeset
586 director_hosts_purge_removed, dir);
22572
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
587 }
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
588 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
589
22566
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
590 /* 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
591 before disconnecting. */
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
592 cmd = t_strdup_printf("DIRECTOR-REMOVE\t%s\t%u\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
593 removed_host->ip_str, removed_host->port);
22566
98b21e27d66c director: When director is removed, notify it before disconnecting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
594 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
595 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
596
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
597 /* 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
598 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
599 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
600 conn = conns[i];
22572
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
601 if (director_connection_get_host(conn) != removed_host ||
4a0792a03f5a director: Allow doveadm director ring remove for the same director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22566
diff changeset
602 removed_host->self)
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
603 i++;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
604 else {
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
605 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
606 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
607 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
608 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
609 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
610 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
611 director_sync(dir);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
612 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
613
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
614 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
615 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
616 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
617 struct mail_host *host)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
618 {
19408
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
619 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
620 string_t *str;
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
621
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
622 if (orig_src == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
623 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
624 orig_src->last_seq++;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
625 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
626
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
627 str = t_str_new(128);
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
628 str_printfa(str, "HOST\t%s\t%u\t%u\t%s\t%u",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
629 orig_src->ip_str, orig_src->port, orig_src->last_seq,
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
630 host->ip_str, host->vhost_count);
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
631 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
632 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
633 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
634 } 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
635 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
636 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
637 i_error("Ring has directors that don't support tags - removing host %s with tag '%s'",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
638 host->ip_str, host_tag);
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
639 } else {
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
640 i_error("Ring has directors that support mixed versions of tags - removing host %s with tag '%s'",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
641 host->ip_str, host_tag);
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
642 }
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
643 director_remove_host(dir, NULL, NULL, host);
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
644 return;
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18661
diff changeset
645 }
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18661
diff changeset
646 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
647 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
648 (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
649 /* 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
650 any extra unknown arguments */
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
651 if (host->hostname != NULL)
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
652 str_append_tabescaped(str, host->hostname);
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
653 }
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
654 str_append_c(str, '\n');
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
655 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
656 }
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
657
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
658 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
659 {
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
660 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
661
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
662 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
663 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
664 }
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
665
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
666 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
667 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
668 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
669 {
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
670 /* 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
671 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
672
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
673 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
674 "down=%d last_updown_change=%ld (hosts_hash=%u)",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
675 host->ip_str, host->vhost_count, host->down,
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
676 (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
677 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
678
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
679 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
680
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
681 /* 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
682 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
683 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
684 host->desynced = TRUE;
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
685 director_sync(dir);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
686 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
687
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
688 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
689 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
690 struct mail_host *host)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
691 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
692 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
693
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
694 if (src != NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
695 if (orig_src == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
696 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
697 orig_src->last_seq++;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
698 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
699
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
700 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
701 "HOST-REMOVE\t%s\t%u\t%u\t%s\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
702 orig_src->ip_str, orig_src->port,
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
703 orig_src->last_seq, host->ip_str));
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
704 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
705
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
706 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
707 mail_host_remove(host);
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
708 director_sync(dir);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
709 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
710
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11353
diff changeset
711 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
712 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
713 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
714 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
715 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
716
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
717 if (orig_src == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
718 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
719 orig_src->last_seq++;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
720 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11587
diff changeset
721
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11353
diff changeset
722 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
723 "HOST-FLUSH\t%s\t%u\t%u\t%s\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
724 orig_src->ip_str, orig_src->port, orig_src->last_seq,
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
725 host->ip_str));
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
726 user_directory_remove_host(users, host);
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
727 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
728 }
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11353
diff changeset
729
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
730 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
731 struct user *user)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
732 {
22673
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
733 struct director_connection *const *connp;
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
734
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
735 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
736 i_assert(!user->weak);
22673
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
737
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
738 array_foreach(&dir->connections, connp) {
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
739 if (director_connection_get_host(*connp) == src)
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
740 continue;
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
741
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
742 if (director_connection_get_minor_version(*connp) >= DIRECTOR_VERSION_USER_TIMESTAMP) {
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
743 director_connection_send(*connp, t_strdup_printf(
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
744 "USER\t%u\t%s\t%u\n", user->username_hash, user->host->ip_str,
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
745 user->timestamp));
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
746 } else {
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
747 director_connection_send(*connp, t_strdup_printf(
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
748 "USER\t%u\t%s\n", user->username_hash, user->host->ip_str));
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
749 }
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22667
diff changeset
750 }
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
751 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
752
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
753 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
754 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
755 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
756 struct user *user)
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
757 {
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
758 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
759
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
760 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
761 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
762
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
763 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
764 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
765 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
766 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
767
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
768 cmd = t_strdup_printf("USER-WEAK\t%s\t%u\t%u\t%u\t%s\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
769 orig_src->ip_str, orig_src->port, orig_src->last_seq,
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
770 user->username_hash, user->host->ip_str);
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
771
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
772 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
773 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
774 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
775 /* 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
776 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
777 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
778 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
779 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
780 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
781 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
782 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
783 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
784 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
785 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
786 } 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
787 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
788 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
789 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
790
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
791 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
792 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
793 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
794 struct director *dir = ctx->dir;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
795 ctx->callback_pending = FALSE;
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
796
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
797 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
798 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
799
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
800 if (result == 0) {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
801 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
802 char *data;
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
803 i_stream_set_return_partial_line(is, TRUE);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
804 data = i_stream_read_next_line(is);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
805 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
806 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
807 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
808 net_ip2addr(&ctx->host_ip),
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
809 data == NULL ? "(no output to stdout)" : data);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
810 while((data = i_stream_read_next_line(is)) != NULL) {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
811 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
812 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
813 ctx->username_hash,
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
814 net_ip2addr(&ctx->host_ip), data);
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 i_stream_unref(&is);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
817 } else {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
818 o_stream_unref(&ctx->reply);
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 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
821
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
822 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
823 /* 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
824 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
825 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
826 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
827 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
828 } else {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
829 /* 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
830 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
831 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
832 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
833 }
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
834 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
835
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
836 static void
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
837 director_flush_user(struct director *dir, struct user *user)
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
838 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
839 struct director_kill_context *ctx = user->kill_ctx;
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
840 struct var_expand_table tab[] = {
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
841 { 'i', user->host->ip_str, "ip" },
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
842 { 'h', user->host->hostname, "host" },
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
843 { '\0', NULL, NULL }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
844 };
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
845
20982
d9d2da1b7ecb director: Execute director_flush_socket only from one director.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
846 /* 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
847 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
848 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
849 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
850
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
851 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
852 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
853 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
854 backend. */
20982
d9d2da1b7ecb director: Execute director_flush_socket only from one director.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
855 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
856 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
857 !ctx->kill_is_self_initiated) {
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
858 director_user_kill_finish_delayed(dir, user, FALSE);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
859 return;
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
20941
868cf176e7ff director: Fix crash handling director_flush_socket when user is freed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20940
diff changeset
862 ctx->host_ip = user->host->ip;
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
863
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
864 string_t *s_sock = str_new(default_pool, 32);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
865 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
866 ctx->socket_path = str_free_without_data(&s_sock);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
867
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
868 const char *error;
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
869 struct program_client_settings set = {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
870 .client_connect_timeout_msecs = 10000,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
871 };
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
872
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
873 restrict_access_init(&set.restrict_set);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
874
20992
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
875 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
876 "FLUSH",
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
877 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
878 net_ip2addr(&ctx->old_host_ip),
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
879 user->host->ip_str,
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
880 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
881 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
882 NULL
5b6eaea4c59b director: Send user's old and new backend IPs to flush script.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20991
diff changeset
883 };
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
884
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
885 ctx->kill_state = USER_KILL_STATE_FLUSHING;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
886 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
887 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
888
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
889 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
890 &ctx->pclient, &error)) != 0) {
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
891 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
892 ctx->socket_path,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
893 user->username_hash,
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
894 user->host->ip_str,
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
895 error);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
896 director_flush_user_continue(0, ctx);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
897 return;
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
898 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
899
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
900 ctx->reply =
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
901 iostream_temp_create_named("/tmp", 0,
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
902 t_strdup_printf("flush response from %s",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
903 user->host->ip_str));
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
904 o_stream_set_no_error_handling(ctx->reply, TRUE);
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
905 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
906 ctx->callback_pending = TRUE;
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
907 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
908 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
909
22551
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
910 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
911 {
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
912 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
913 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
914
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
915 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
916 }
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
917
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
918 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
919 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
920 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
921 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
922
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
923 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
924
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
925 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
926 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
927
22997
0a2614a38fc6 director: Fix crash when user kill times out before IPC finishes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22713
diff changeset
928 if (kill_ctx->ipc_cmd != NULL)
0a2614a38fc6 director: Fix crash when user kill times out before IPC finishes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22713
diff changeset
929 ipc_client_cmd_abort(dir->ipc_proxy, &kill_ctx->ipc_cmd);
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
930 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
931 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
932 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
933 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
934 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
935
22551
a89fc39f2135 director: Fix tracking user move count when user is freed early
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22510
diff changeset
936 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
937 }
eff5fc952993 director: Code cleanup - Finish user move always in the same function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20964
diff changeset
938
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
939 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
940 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
941 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
942 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
943 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
944
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
945 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
946 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
947
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
948 static void
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
949 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
950 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
951 {
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
952 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
953 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
954 director_user_move_free(user);
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
955 return;
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
956 }
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
957
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
958 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
959
19108
3ebba506c2c7 director: Added director_user_kick_delay setting.
Timo Sirainen <tss@iki.fi>
parents: 19035
diff changeset
960 /* 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
961 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
962 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
963 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
964 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
965 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
966 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
967 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
968
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
969 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
970 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
971 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
972 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
973
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
974 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
975 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
976 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
977
21434
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
978 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
979 self ? "we started it " : "",
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
980 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
981
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
982 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
983 /* we're alone */
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
984 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
985 } 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
986 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
987 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
988 "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
989 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
990 } else {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
991 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
992 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
993 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
994 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
995
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
996 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
997 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
998 {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
999 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
1000 }
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1001
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1002 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
1003 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
1004 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1005 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
1006 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
1007
22997
0a2614a38fc6 director: Fix crash when user kill times out before IPC finishes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22713
diff changeset
1008 /* don't try to abort the IPC command anymore */
0a2614a38fc6 director: Fix crash when user kill times out before IPC finishes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22713
diff changeset
1009 ctx->ipc_cmd = NULL;
0a2614a38fc6 director: Fix crash when user kill times out before IPC finishes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22713
diff changeset
1010
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
1011 /* 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
1012 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
1013 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
1014 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
1015 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
1016 /* shouldn't get here. the command reply isn't finished yet. */
22653
3ada7f87de9f director: Log an error if login process sends unexpected reply to KICK* commands
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
1017 i_error("login process sent unexpected reply to kick: %s", data);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1018 return;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1019 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
1020 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1021 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
1022 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
1023 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
1024 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
1025 }
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1026 /* 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
1027 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1028 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1029
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1030 i_assert(ctx->dir->users_kicking_count > 0);
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1031 ctx->dir->users_kicking_count--;
22660
2668f5707dbd director: Add kick_callback to director
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22655
diff changeset
1032 if (ctx->dir->kick_callback != NULL)
2668f5707dbd director: Add kick_callback to director
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22655
diff changeset
1033 ctx->dir->kick_callback(ctx->dir);
2668f5707dbd director: Add kick_callback to director
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22655
diff changeset
1034
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1035 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
1036 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
1037 /* 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
1038 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
1039 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
1040 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
1041 } else {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1042 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
1043 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
1044 /* 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
1045 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
1046 }
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1047 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1048
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1049 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
1050 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
1051 {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1052 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
1053 new_events_count);
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1054 }
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1055
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1056 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
1057 {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1058 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
1059 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
1060
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1061 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
1062 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
1063 "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
1064 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
1065 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
1066 }
21370
6cda62d7de0e director: Fix assert-crash when flush script takes too long
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21314
diff changeset
1067 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
1068 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
1069 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
1070 }
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1071 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
1072 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1073
22506
3afbfedcdd31 director: Fix crash when flush is run and all backends are down.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22044
diff changeset
1074 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
1075 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
1076 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
1077 {
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1078 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
1079 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
1080
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1081 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
1082 /* 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
1083 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
1084 earlier. */
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1085 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
1086 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
1087 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
1088 return;
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1089 }
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1090
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1091 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
1092 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
1093 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
1094 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
1095 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
1096 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
1097 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
1098 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
1099 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
1100 }
20990
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1101
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1102 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
1103 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
1104 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
1105 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
1106
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
1107 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
1108 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
1109 user->username_hash);
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1110 dir->users_kicking_count++;
22997
0a2614a38fc6 director: Fix crash when user kill times out before IPC finishes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22713
diff changeset
1111 ctx->ipc_cmd = ipc_client_cmd(dir->ipc_proxy, cmd,
0a2614a38fc6 director: Fix crash when user kill times out before IPC finishes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22713
diff changeset
1112 director_kill_user_callback, ctx);
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
1113 } 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
1114 /* 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
1115 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
1116 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
1117 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
1118 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
1119 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
1120 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
1121 }
20990
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1122 }
99845237c3c5 director: Code cleanup - moved user kill startup to its own function.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
1123
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1124 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
1125 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
1126 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
1127 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1128 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
1129 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
1130 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
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 /* 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
1133 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
1134 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
1135
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1136 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
1137
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1138 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
1139 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
1140
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1141 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
1142 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
1143 killed.
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1144
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1145 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
1146 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
1147 */
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
1148 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
1149 if (user == NULL) {
21434
1cc2946b801c director: Add more debug logging for moving & killing users
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21433
diff changeset
1150 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
1151 username_hash);
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20992
diff changeset
1152 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
1153 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
1154 } 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
1155 /* 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
1156 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
1157 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
1158 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
1159 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
1160 dir_debug("User %u move forwarded: host is already %s",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1161 username_hash, host->ip_str);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1162 } 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
1163 /* 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
1164 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
1165 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
1166
21431
784f3ca6ebfb director: Make sure USER-KILLED isn't sent before USER-MOVE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21430
diff changeset
1167 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
1168 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
1169 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
1170 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
1171 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
1172 dir_debug("User %u move started: host %s -> %s",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1173 username_hash, old_host->ip_str,
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1174 host->ip_str);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1175 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1176
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1177 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
1178 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
1179 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
1180 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1181 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
1182 "USER-MOVE\t%s\t%u\t%u\t%u\t%s\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1183 orig_src->ip_str, orig_src->port, orig_src->last_seq,
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1184 user->username_hash, user->host->ip_str));
21431
784f3ca6ebfb director: Make sure USER-KILLED isn't sent before USER-MOVE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21430
diff changeset
1185 /* 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
1186 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
1187 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
1188 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1189
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1190 static void
22653
3ada7f87de9f director: Log an error if login process sends unexpected reply to KICK* commands
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
1191 director_kick_user_callback(enum ipc_client_cmd_state state,
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1192 const char *data, void *context)
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1193 {
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1194 struct director *dir = context;
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1195
22653
3ada7f87de9f director: Log an error if login process sends unexpected reply to KICK* commands
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
1196 if (state == IPC_CLIENT_CMD_STATE_REPLY) {
3ada7f87de9f director: Log an error if login process sends unexpected reply to KICK* commands
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
1197 /* shouldn't get here. the command reply isn't finished yet. */
3ada7f87de9f director: Log an error if login process sends unexpected reply to KICK* commands
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
1198 i_error("login process sent unexpected reply to kick: %s", data);
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1199 return;
22653
3ada7f87de9f director: Log an error if login process sends unexpected reply to KICK* commands
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
1200 }
3ada7f87de9f director: Log an error if login process sends unexpected reply to KICK* commands
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
1201
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1202 i_assert(dir->users_kicking_count > 0);
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1203 dir->users_kicking_count--;
22660
2668f5707dbd director: Add kick_callback to director
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22655
diff changeset
1204 if (dir->kick_callback != NULL)
2668f5707dbd director: Add kick_callback to director
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22655
diff changeset
1205 dir->kick_callback(dir);
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1206 }
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1207
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1208 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
1209 struct director_host *orig_src, const char *username)
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1210 {
20844
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1211 string_t *cmd = t_str_new(64);
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1212
20844
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1213 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
1214 str_append_tabescaped(cmd, username);
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1215 dir->users_kicking_count++;
20844
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1216 ipc_client_cmd(dir->ipc_proxy, str_c(cmd),
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1217 director_kick_user_callback, dir);
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1218
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1219 if (orig_src == NULL) {
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1220 orig_src = dir->self_host;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1221 orig_src->last_seq++;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1222 }
21313
a309b9ab46e6 director: Fix USER-KICK and USER-KICK-ALT forwarding
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21081
diff changeset
1223 str_truncate(cmd, 0);
20844
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1224 str_printfa(cmd, "USER-KICK\t%s\t%u\t%u\t",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1225 orig_src->ip_str, orig_src->port, orig_src->last_seq);
20844
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1226 str_append_tabescaped(cmd, username);
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1227 str_append_c(cmd, '\n');
90fad61ff8ae director: Escape username when handling USER-KICK.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20583
diff changeset
1228 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
1229 }
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1230
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1231 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
1232 struct director_host *orig_src,
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1233 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
1234 {
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1235 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
1236
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1237 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
1238 str_append_tabescaped(cmd, field);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1239 str_append_c(cmd, '\t');
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1240 str_append_tabescaped(cmd, value);
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1241 dir->users_kicking_count++;
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1242 ipc_client_cmd(dir->ipc_proxy, str_c(cmd),
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1243 director_kick_user_callback, dir);
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1244
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1245 if (orig_src == NULL) {
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1246 orig_src = dir->self_host;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1247 orig_src->last_seq++;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1248 }
21313
a309b9ab46e6 director: Fix USER-KICK and USER-KICK-ALT forwarding
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21081
diff changeset
1249 str_truncate(cmd, 0);
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1250 str_printfa(cmd, "USER-KICK-ALT\t%s\t%u\t%u\t",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1251 orig_src->ip_str, orig_src->port, orig_src->last_seq);
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1252 str_append_tabescaped(cmd, field);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1253 str_append_c(cmd, '\t');
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1254 str_append_tabescaped(cmd, value);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1255 str_append_c(cmd, '\n');
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1256 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
1257 }
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20844
diff changeset
1258
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
1259 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
1260 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
1261 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
1262 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
1263 {
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
1264 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
1265
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
1266 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
1267 username_hash, net_ip2addr(except_ip));
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1268 dir->users_kicking_count++;
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
1269 ipc_client_cmd(dir->ipc_proxy, cmd,
22655
c98a2d05c702 director: Show in process title how many users are being kicked.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22653
diff changeset
1270 director_kick_user_callback, dir);
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
1271
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
1272 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
1273 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
1274 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
1275 }
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
1276 cmd = t_strdup_printf("USER-KICK-HASH\t%s\t%u\t%u\t%u\t%s\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1277 orig_src->ip_str, orig_src->port, orig_src->last_seq,
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
1278 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
1279 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
1280 }
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
1281
20980
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1282 static void
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1283 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
1284 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
1285 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
1286 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
1287 {
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1288 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
1289 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
1290 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
1291 }
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1292 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
1293 "USER-KILLED-EVERYWHERE\t%s\t%u\t%u\t%u\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1294 orig_src->ip_str, orig_src->port, orig_src->last_seq,
20980
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1295 username_hash));
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1296 }
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1297
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1298 static void
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1299 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
1300 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
1301 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1302 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
1303
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1304 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
1305 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
1306 return;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1307
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1308 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
1309 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
1310 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
1311 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1312 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
1313 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
1314 break;
20980
481b70689214 director: Fix user move hangs when another move is triggered early.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20979
diff changeset
1315 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
1316 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
1317 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
1318 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
1319 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
1320 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
1321 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
1322 /* 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
1323 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
1324 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
1325 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
1326 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
1327 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1328 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
1329 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
1330 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
1331 break;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1332 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1333 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1334
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1335 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
1336 {
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1337 struct mail_tag *const *tagp;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1338
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1339 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
1340 director_user_tag_killed(dir, *tagp, username_hash);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1341 }
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1342
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1343 static void
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1344 director_user_tag_killed_everywhere(struct director *dir,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1345 struct mail_tag *tag,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1346 struct director_host *src,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1347 struct director_host *orig_src,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1348 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
1349 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1350 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
1351
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1352 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
1353 if (user == NULL) {
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1354 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
1355 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
1356 return;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1357 }
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1358 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
1359 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
1360 username_hash);
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1361 return;
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1362 }
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1363 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
1364 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
1365 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
1366 return;
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1367 }
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1368
20940
8de947fa3b4d director: Support flush socket
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20846
diff changeset
1369 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
1370 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
1371 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1372
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1373 void director_user_killed_everywhere(struct director *dir,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1374 struct director_host *src,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1375 struct director_host *orig_src,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1376 unsigned int username_hash)
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1377 {
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1378 struct mail_tag *const *tagp;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1379
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1380 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
1381 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
1382 username_hash);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1383 }
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1384 }
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1385
15321
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1386 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
1387 {
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1388 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
1389 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
1390 }
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1391
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1392 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
1393 {
15321
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1394 /* 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
1395 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
1396 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
1397 dir->to_callback =
cd646623a1a8 director: Don't handle pending requests from all around the code.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1398 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
1399 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1400 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1401
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1402 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
1403 const char *cmd)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1404 {
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1405 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
1406 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1407
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1408 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
1409 struct director_host *src,
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1410 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
1411 {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1412 struct director_connection *const *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1413
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1414 i_assert(src != NULL);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1415
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1416 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
1417 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
1418 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
1419 director_connection_send(*connp, cmd);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1420 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1421 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1422
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1423 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
1424 {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1425 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
1426 /* 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
1427 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
1428 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
1429 /* 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
1430 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
1431 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
1432 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
1433 } else {
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1434 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
1435 }
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1436 }
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1437 }
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20987
diff changeset
1438
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1439 struct director *
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1440 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
1441 const struct ip_addr *listen_ip, in_port_t listen_port,
22660
2668f5707dbd director: Add kick_callback to director
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22655
diff changeset
1442 director_state_change_callback_t *callback,
2668f5707dbd director: Add kick_callback to director
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22655
diff changeset
1443 director_kick_callback_t *kick_callback)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1444 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1445 struct director *dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1446
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1447 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
1448 dir->set = set;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1449 dir->self_port = listen_port;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1450 dir->self_ip = *listen_ip;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1451 dir->state_change_callback = callback;
22660
2668f5707dbd director: Add kick_callback to director
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 22655
diff changeset
1452 dir->kick_callback = kick_callback;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1453 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
1454 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
1455 i_array_init(&dir->connections, 8);
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1456 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
1457 set->director_consistent_hashing,
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1458 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
1459
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
1460 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
1461 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
1462 return dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1463 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1464
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1465 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
1466 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1467 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
1468 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
1469 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
1470
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1471 *_dir = NULL;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1472
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1473 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
1474 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
1475 conn = *connp;
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 14652
diff changeset
1476 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
1477 }
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
1478
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
1479 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
1480 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
1481
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1482 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
1483 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
1484 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
1485 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
1486 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
1487 if (dir->to_request != NULL)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1488 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
1489 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
1490 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
1491 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
1492 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
1493 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
1494 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
1495 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
1496 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
1497 host = *hostp;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1498 director_host_free(&host);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14492
diff changeset
1499 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1500 array_free(&dir->pending_requests);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1501 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
1502 array_free(&dir->connections);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1503 i_free(dir);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1504 }
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1505
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1506 void dir_debug(const char *fmt, ...)
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1507 {
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1508 va_list args;
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1509
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1510 if (!director_debug)
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1511 return;
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1512
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1513 va_start(args, fmt);
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1514 T_BEGIN {
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1515 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
1516 } T_END;
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1517 va_end(args);
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15321
diff changeset
1518 }
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1519
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1520 struct director_user_iter {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1521 struct director *dir;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1522 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
1523 struct user_directory_iter *user_iter;
22676
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
1524 bool iter_until_current_tail;
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1525 };
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1526
22676
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
1527 struct director_user_iter *
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
1528 director_iterate_users_init(struct director *dir, bool iter_until_current_tail)
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1529 {
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1530 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
1531 iter->dir = dir;
22676
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
1532 iter->iter_until_current_tail = iter_until_current_tail;
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1533 return iter;
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1534 }
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1535
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1536 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
1537 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1538 const ARRAY_TYPE(mail_tag) *tags;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1539 struct user *user;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1540
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1541 i_assert(iter != NULL);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1542
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1543 if (iter->user_iter == NULL) {
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1544 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
1545 if (iter->tag_idx >= array_count(tags))
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1546 return NULL;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1547 struct mail_tag *const *tagp = array_idx(tags, iter->tag_idx);
22676
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
1548 iter->user_iter = user_directory_iter_init((*tagp)->users,
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
1549 iter->iter_until_current_tail);
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1550 }
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1551 user = user_directory_iter_next(iter->user_iter);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1552 if (user == NULL) {
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1553 user_directory_iter_deinit(&iter->user_iter);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1554 iter->tag_idx++;
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1555 return director_iterate_users_next(iter);
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1556 } else
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1557 return user;
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1558 }
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1559
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1560 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
1561 {
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1562 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
1563 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
1564 *_iter = NULL;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1565 if (iter->user_iter != NULL)
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21076
diff changeset
1566 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
1567 i_free(iter);
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1568 }
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
1569
21076
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1570 unsigned int
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1571 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
1572 {
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1573 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
1574 }
ef9d8f4c6c67 director: Code cleanup - moved username_hash generation to director.h
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21075
diff changeset
1575
20583
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1576 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
1577 {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1578 user_move_throttle =
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1579 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
1580 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
1581 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
1582 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
1583 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
1584 }
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1585
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1586 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
1587 {
c4cc24c77ad8 director: Throttle user move/kill failure errors after 100/sec.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19957
diff changeset
1588 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
1589 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
1590 }