annotate src/director/director-connection.c @ 22670:a96fa917ced1

director: Keep users unsorted during handshake and sort them at the end This is simpler and sometimes more efficient than the current way of immediately inserting the users to the correct place in the linked list. This is especially useful if handshaking is mixed with regular USER updates, because each switch between them required walking the linked list backwards to find the proper insert position. It's not a big problem if the users list is temporarily unordered. It mainly means that some of the users won't be expired as early as they should have.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 17 Nov 2017 13:24:59 +0200
parents 4c0e2030200a
children ad943b175750
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21390
2e2563132d5f Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21322
diff changeset
1 /* Copyright (c) 2010-2017 Dovecot authors, see the included COPYING file */
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
3 /*
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
4 Handshaking:
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
5
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
6 Incoming director connections send:
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
7
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
8 VERSION
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
9 ME
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
10 <wait for DONE from remote handshake>
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
11 DONE
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
12 <make this connection our "left" connection, potentially disconnecting
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
13 another one>
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
14
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
15 Outgoing director connections send:
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
16
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
17 VERSION
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
18 ME
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
19 [0..n] DIRECTOR
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
20 HOST-HAND-START
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
21 [0..n] HOST
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
22 HOST-HAND-END
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
23 [0..n] USER
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
24 <possibly other non-handshake commands between USERs>
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
25 DONE
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
26 <wait for DONE from remote>
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
27 <make this connection our "right" connection, potentially disconnecting
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
28 another one>
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
29 */
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
30
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 #include "lib.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 #include "ioloop.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 #include "array.h"
15187
02451e967a06 Renamed network.[ch] to net.[ch].
Timo Sirainen <tss@iki.fi>
parents: 15162
diff changeset
34 #include "net.h"
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 #include "istream.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 #include "ostream.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 #include "str.h"
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
38 #include "strescape.h"
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
39 #include "time-util.h"
11373
26cfc1c3a4b1 director: Update connection count when client disconnects.
Timo Sirainen <tss@iki.fi>
parents: 11355
diff changeset
40 #include "master-service.h"
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 #include "mail-host.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 #include "director.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 #include "director-host.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 #include "director-request.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 #include "director-connection.h"
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 #include <unistd.h>
22651
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
48 #include <sys/time.h>
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
49 #include <sys/resource.h>
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 #define MAX_INBUF_SIZE 1024
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 #define OUTBUF_FLUSH_THRESHOLD (1024*128)
22250
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
53 /* Max time to wait for connect() to finish before aborting */
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
54 #define DIRECTOR_CONNECTION_CONNECT_TIMEOUT_MSECS (10*1000)
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
55 /* Max idling time before "ME" command must have been received,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
56 or we'll disconnect. */
14467
110673e82868 director: Increased timeouts.
Timo Sirainen <tss@iki.fi>
parents: 14437
diff changeset
57 #define DIRECTOR_CONNECTION_ME_TIMEOUT_MSECS (10*1000)
14477
ea5b949a623b director: Increased timeout for sending USER data in handshake.
Timo Sirainen <tss@iki.fi>
parents: 14476
diff changeset
58 /* Max time to wait for USERs in handshake to be sent. With a lot of users the
ea5b949a623b director: Increased timeout for sending USER data in handshake.
Timo Sirainen <tss@iki.fi>
parents: 14476
diff changeset
59 kernel may quickly eat up everything we send, while the receiver is busy
ea5b949a623b director: Increased timeout for sending USER data in handshake.
Timo Sirainen <tss@iki.fi>
parents: 14476
diff changeset
60 parsing the data. */
14483
10f5456704a7 director: USER sending timeout was higher than it needed to be.
Timo Sirainen <tss@iki.fi>
parents: 14482
diff changeset
61 #define DIRECTOR_CONNECTION_SEND_USERS_TIMEOUT_MSECS (30*1000)
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
62 /* Max idling time before "DONE" command must have been received,
22254
58ffaff6f714 director: Use longer timeout for receiving user list in handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22253
diff changeset
63 or we'll disconnect. Use a slightly larger value than for _SEND_USERS_ so
58ffaff6f714 director: Use longer timeout for receiving user list in handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22253
diff changeset
64 that we'll get a better error if the sender decides to disconnect. */
58ffaff6f714 director: Use longer timeout for receiving user list in handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22253
diff changeset
65 #define DIRECTOR_CONNECTION_DONE_TIMEOUT_MSECS (40*1000)
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
66 /* How long to wait for PONG for an idling connection */
14467
110673e82868 director: Increased timeouts.
Timo Sirainen <tss@iki.fi>
parents: 14437
diff changeset
67 #define DIRECTOR_CONNECTION_PING_IDLE_TIMEOUT_MSECS (10*1000)
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
68 /* Maximum time to wait for PONG reply */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
69 #define DIRECTOR_CONNECTION_PONG_TIMEOUT_MSECS (60*1000)
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
70 /* How long to wait to send PING when connection is idle */
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
71 #define DIRECTOR_CONNECTION_PING_INTERVAL_MSECS (15*1000)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
72 /* How long to wait before sending PING while waiting for SYNC reply */
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
73 #define DIRECTOR_CONNECTION_PING_SYNC_INTERVAL_MSECS 1000
12065
ff5a47012287 director: If outgoing connection dies soon, mark the host as failed to avoid immediate reconnect.
Timo Sirainen <tss@iki.fi>
parents: 11816
diff changeset
74 /* If outgoing director connection exists for less than this many seconds,
ff5a47012287 director: If outgoing connection dies soon, mark the host as failed to avoid immediate reconnect.
Timo Sirainen <tss@iki.fi>
parents: 11816
diff changeset
75 mark the host as failed so we won't try to reconnect to it immediately */
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
76 #define DIRECTOR_SUCCESS_MIN_CONNECT_SECS 40
22567
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
77 #define DIRECTOR_RECONNECT_AFTER_WRONG_CONNECT_MSECS 1000
14575
dbe6d05fd595 director: When we find unwanted connection, wait for 10s for it to disconnect us, not 10ms.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
78 #define DIRECTOR_WAIT_DISCONNECT_SECS 10
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
79 #define DIRECTOR_HANDSHAKE_WARN_SECS 29
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
80 #define DIRECTOR_HANDSHAKE_BYTES_LOG_MIN_SECS (60*30)
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
81 #define DIRECTOR_MAX_SYNC_SEQ_DUPLICATES 4
16790
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
82 /* If we receive SYNCs with a timestamp this many seconds higher than the last
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
83 valid received SYNC timestamp, assume that we lost the director's restart
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
84 notification and reset the last_sync_seq */
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
85 #define DIRECTOR_SYNC_STALE_TIMESTAMP_RESET_SECS (60*2)
19294
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
86 #define DIRECTOR_MAX_CLOCK_DIFF_WARN_SECS 1
22648
6bd018a94a57 director: Don't block too long when sending users during director handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22646
diff changeset
87 /* How many USER entries to send during handshake before going back to ioloop
6bd018a94a57 director: Don't block too long when sending users during director handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22646
diff changeset
88 to see if there's other work to be done as well. */
6bd018a94a57 director: Don't block too long when sending users during director handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22646
diff changeset
89 #define DIRECTOR_HANDSHAKE_MAX_USERS_SENT_PER_FLUSH 10000
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
91 #if DIRECTOR_CONNECTION_DONE_TIMEOUT_MSECS <= DIRECTOR_CONNECTION_PING_TIMEOUT_MSECS
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
92 # error DIRECTOR_CONNECTION_DONE_TIMEOUT_MSECS is too low
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
93 #endif
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
94
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
95 #if DIRECTOR_CONNECTION_PONG_TIMEOUT_MSECS <= DIRECTOR_CONNECTION_PING_IDLE_TIMEOUT_MSECS
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
96 # error DIRECTOR_CONNECTION_PONG_TIMEOUT_MSECS is too low
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
97 #endif
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
98
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
99 #define CMD_IS_USER_HANDHAKE(args) \
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
100 (str_array_length(args) > 2)
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
101
18065
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
102 #define DIRECTOR_OPT_CONSISTENT_HASHING "consistent-hashing"
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
103
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 struct director_connection {
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
105 int refcount;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 struct director *dir;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
107 char *name;
22252
8882a5cbe76d director: Use more accurate timestamps for handshake timeout logging
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22251
diff changeset
108 struct timeval created, connected_time, me_received_time;
22651
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
109 struct timeval connected_user_cpu;
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
110 unsigned int minor_version;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
112 struct timeval last_input, last_output;
22627
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
113 size_t peak_bytes_buffered;
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
114
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
115 struct timeval ping_sent_time;
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
116 unsigned int last_ping_msecs;
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
117
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 /* for incoming connections the director host isn't known until
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 ME-line is received */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 struct director_host *host;
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
121 /* this is set only for wrong connections: */
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
122 struct director_host *connect_request_to;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 int fd;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 struct io *io;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 struct istream *input;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 struct ostream *output;
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
128 struct timeout *to_disconnect, *to_ping, *to_pong;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
130 struct director_user_iter *user_iter;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
132 /* set during command execution */
22640
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
133 const char *cur_cmd, *const *cur_args;
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
134
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 unsigned int in:1;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136 unsigned int connected:1;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 unsigned int version_received:1;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 unsigned int me_received:1;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 unsigned int handshake_received:1;
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
140 unsigned int ignore_host_events:1;
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
141 unsigned int handshake_sending_hosts:1;
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
142 unsigned int ping_waiting:1;
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
143 unsigned int synced:1;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
144 unsigned int wrong_host:1;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
145 unsigned int verifying_left:1;
16621
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
146 unsigned int users_unsorted:1;
22651
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
147 unsigned int connected_user_cpu_set:1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 };
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
150 static bool director_connection_unref(struct director_connection *conn);
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
151 static void director_finish_sending_handshake(struct director_connection *conn);
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
152 static void director_connection_disconnected(struct director_connection **conn,
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
153 const char *reason);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
154 static void director_connection_reconnect(struct director_connection **conn,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
155 const char *reason);
16618
0ad8da149774 director: Log director disconnection errno correctly.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
156 static void
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
157 director_connection_log_disconnect(struct director_connection *conn, int err,
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
158 const char *errstr);
18065
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
159 static int director_connection_send_done(struct director_connection *conn);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
161 static void ATTR_FORMAT(2, 3)
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
162 director_cmd_error(struct director_connection *conn, const char *fmt, ...)
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
163 {
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
164 va_list args;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
165
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
166 va_start(args, fmt);
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
167 i_error("director(%s): Command %s: %s (input: %s)", conn->name,
22640
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
168 conn->cur_cmd, t_strdup_vprintf(fmt, args),
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
169 t_strarray_join(conn->cur_args, "\t"));
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
170 va_end(args);
14479
293ada796ae6 director: Fixed protocol error detection/handling.
Timo Sirainen <tss@iki.fi>
parents: 14478
diff changeset
171
18663
1c268a7cc74a director: Fixed crash if director sent invalid data too early.
Timo Sirainen <tss@iki.fi>
parents: 18662
diff changeset
172 if (conn->host != NULL)
1c268a7cc74a director: Fixed crash if director sent invalid data too early.
Timo Sirainen <tss@iki.fi>
parents: 18662
diff changeset
173 conn->host->last_protocol_failure = ioloop_time;
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
174 }
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
175
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
176 static void
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
177 director_connection_append_stats(struct director_connection *conn, string_t *str)
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
178 {
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
179 int input_msecs = timeval_diff_msecs(&ioloop_timeval, &conn->last_input);
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
180 int output_msecs = timeval_diff_msecs(&ioloop_timeval, &conn->last_output);
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
181 int connected_msecs = timeval_diff_msecs(&ioloop_timeval, &conn->connected_time);
22651
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
182 struct rusage usage;
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
183
22256
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
184 str_printfa(str, "bytes in=%"PRIuUOFF_T", bytes out=%"PRIuUOFF_T,
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
185 conn->input->v_offset, conn->output->offset);
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
186 if (conn->last_input.tv_sec > 0) {
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
187 str_printfa(str, ", last input %u.%03u s ago",
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
188 input_msecs/1000, input_msecs%1000);
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
189 }
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
190 if (conn->last_output.tv_sec > 0) {
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
191 str_printfa(str, ", last output %u.%03u s ago",
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
192 output_msecs/1000, output_msecs%1000);
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
193 }
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
194 if (conn->connected) {
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
195 str_printfa(str, ", connected %u.%03u s ago",
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
196 connected_msecs/1000, connected_msecs%1000);
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
197 }
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
198 if (o_stream_get_buffer_used_size(conn->output) > 0) {
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
199 str_printfa(str, ", %"PRIuSIZE_T" bytes in output buffer",
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
200 o_stream_get_buffer_used_size(conn->output));
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
201 }
22649
bb7c452e3662 director: Include peak output buffer size in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22648
diff changeset
202 str_printfa(str, ", %zu peak output buffer size",
bb7c452e3662 director: Include peak output buffer size in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22648
diff changeset
203 conn->peak_bytes_buffered);
22651
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
204 if (conn->connected_user_cpu_set &&
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
205 getrusage(RUSAGE_SELF, &usage) == 0) {
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
206 /* this isn't measuring the CPU usage used by the connection
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
207 itself, but it can still be a useful measurement */
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
208 int diff = timeval_diff_msecs(&usage.ru_utime,
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
209 &conn->connected_user_cpu);
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
210 str_printfa(str, ", %d.%03d CPU secs since connected",
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
211 diff / 1000, diff % 1000);
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
212 }
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
213 }
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
214
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
215 static void
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
216 director_connection_init_timeout(struct director_connection *conn)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
217 {
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
218 struct timeval start_time;
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
219 string_t *reason = t_str_new(128);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
220
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
221 if (!conn->connected) {
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
222 start_time = conn->created;
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
223 str_append(reason, "Connect timed out");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
224 } else if (!conn->me_received) {
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
225 start_time = conn->connected_time;
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
226 str_append(reason, "Handshaking ME timed out");
22251
dce18ed41532 director: Fix "sending handshake timed out" error to be actually logged
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22250
diff changeset
227 } else if (!conn->in) {
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
228 start_time = conn->me_received_time;
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
229 str_append(reason, "Sending handshake timed out");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
230 } else {
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
231 start_time = conn->me_received_time;
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
232 str_append(reason, "Handshaking DONE timed out");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
233 }
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
234 int msecs = timeval_diff_msecs(&ioloop_timeval, &start_time);
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
235 str_printfa(reason, " (%u.%03u secs, ", msecs/1000, msecs%1000);
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
236 director_connection_append_stats(conn, reason);
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
237 str_append_c(reason, ')');
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
238
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
239 i_error("director(%s): %s", conn->name, str_c(reason));
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
240 director_connection_disconnected(&conn, "Handshake timeout");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
241 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
242
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
243 static void
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
244 director_connection_set_ping_timeout(struct director_connection *conn)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
245 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
246 unsigned int msecs;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
247
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
248 msecs = conn->synced || !conn->handshake_received ?
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
249 DIRECTOR_CONNECTION_PING_INTERVAL_MSECS :
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
250 DIRECTOR_CONNECTION_PING_SYNC_INTERVAL_MSECS;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
251
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
252 timeout_remove(&conn->to_ping);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
253 conn->to_ping = timeout_add(msecs, director_connection_ping, conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
254 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
255
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
256 static void director_connection_wait_timeout(struct director_connection *conn)
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
257 {
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
258 director_connection_log_disconnect(conn, ETIMEDOUT, "");
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
259 director_connection_deinit(&conn,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
260 "Timeout waiting for disconnect after CONNECT");
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
261 }
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
262
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
263 static void director_connection_send_connect(struct director_connection *conn,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
264 struct director_host *host)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
265 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
266 const char *connect_str;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
267
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
268 if (conn->to_disconnect != NULL)
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
269 return;
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
270
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
271 connect_str = t_strdup_printf("CONNECT\t%s\t%u\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
272 host->ip_str, host->port);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
273 director_connection_send(conn, connect_str);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
274 o_stream_uncork(conn->output);
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
275
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
276 /* wait for a while for the remote to disconnect, so it will hopefully
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
277 see our CONNECT command. we'll also log the warning later to avoid
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
278 multiple log lines about it. */
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
279 conn->connect_request_to = host;
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
280 director_host_ref(conn->connect_request_to);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
281
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
282 conn->to_disconnect =
14575
dbe6d05fd595 director: When we find unwanted connection, wait for 10s for it to disconnect us, not 10ms.
Timo Sirainen <tss@iki.fi>
parents: 14571
diff changeset
283 timeout_add(DIRECTOR_WAIT_DISCONNECT_SECS*1000,
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
284 director_connection_wait_timeout, conn);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
285 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
286
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
287 static void director_connection_assigned(struct director_connection *conn)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
288 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
289 struct director *dir = conn->dir;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
290
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
291 if (dir->left != NULL && dir->right != NULL) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
292 /* we're connected to both directors. see if the ring is
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
293 finished by sending a SYNC. if we get it back, it's done. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
294 dir->sync_seq++;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
295 director_set_ring_unsynced(dir);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
296 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
297 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
298 mail_hosts_hash(dir->mail_hosts));
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
299 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
300 director_connection_set_ping_timeout(conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
301 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
302
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
303 static bool director_connection_assign_left(struct director_connection *conn)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
304 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
305 struct director *dir = conn->dir;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
306
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
307 i_assert(conn->in);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
308 i_assert(dir->left != conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
309
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
310 /* make sure this is the correct incoming connection */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
311 if (conn->host->self) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
312 i_error("Connection from self, dropping");
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
313 return FALSE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
314 } else if (dir->left == NULL) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
315 /* no conflicts yet */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
316 } else if (dir->left->host == conn->host) {
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
317 i_warning("Replacing left director connection %s with %s",
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
318 dir->left->host->name, conn->host->name);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
319 director_connection_deinit(&dir->left, t_strdup_printf(
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
320 "Replacing with %s", conn->host->name));
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
321 } else if (dir->left->verifying_left) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
322 /* we're waiting to verify if our current left is still
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
323 working. if we don't receive a PONG, the current left
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
324 gets disconnected and a new left gets assigned. if we do
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
325 receive a PONG, we'll wait until the current left
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
326 disconnects us and then reassign the new left. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
327 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
328 } else if (director_host_cmp_to_self(dir->left->host, conn->host,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
329 dir->self_host) < 0) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
330 /* the old connection is the correct one.
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
331 refer the client there (FIXME: do we ever get here?) */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
332 director_connection_send_connect(conn, dir->left->host);
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
333 return TRUE;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
334 } else {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
335 /* this new connection is the correct one, but wait until the
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
336 old connection gets disconnected before using this one.
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
337 that guarantees that the director inserting itself into
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
338 the ring has finished handshaking its left side, so the
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
339 switch will be fast. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
340 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
341 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
342 dir->left = conn;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
343 i_free(conn->name);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
344 conn->name = i_strdup_printf("%s/left", conn->host->name);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
345 director_connection_assigned(conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
346 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
347 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
348
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
349 static void director_assign_left(struct director *dir)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
350 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
351 struct director_connection *conn, *const *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
352
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
353 array_foreach(&dir->connections, connp) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
354 conn = *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
355
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
356 if (conn->in && conn->handshake_received &&
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
357 conn->to_disconnect == NULL && conn != dir->left) {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
358 /* either use this or disconnect it */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
359 if (!director_connection_assign_left(conn)) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
360 /* we don't want this */
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
361 director_connection_deinit(&conn,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
362 "Unwanted incoming connection");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
363 director_assign_left(dir);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
364 break;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
365 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
366 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
367 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
368 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
369
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
370 static bool director_has_outgoing_connections(struct director *dir)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
371 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
372 struct director_connection *const *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
373
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
374 array_foreach(&dir->connections, connp) {
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
375 if (!(*connp)->in && (*connp)->to_disconnect == NULL)
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
376 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
377 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
378 return FALSE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
379 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
380
20971
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
381 static void director_send_delayed_syncs(struct director *dir)
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
382 {
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
383 struct director_host *const *hostp;
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
384
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
385 i_assert(dir->right != NULL);
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
386
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
387 dir_debug("director(%s): Sending delayed SYNCs", dir->right->name);
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
388 array_foreach(&dir->dir_hosts, hostp) {
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
389 if ((*hostp)->delayed_sync_seq == 0)
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
390 continue;
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
391
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
392 director_sync_send(dir, *hostp, (*hostp)->delayed_sync_seq,
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
393 (*hostp)->delayed_sync_minor_version,
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
394 (*hostp)->delayed_sync_timestamp,
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
395 (*hostp)->delayed_sync_hosts_hash);
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
396 (*hostp)->delayed_sync_seq = 0;
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
397 }
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
398 }
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
399
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
400 static bool director_connection_assign_right(struct director_connection *conn)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
401 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
402 struct director *dir = conn->dir;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
403
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
404 i_assert(!conn->in);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
405
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
406 if (dir->right != NULL) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
407 /* see if we should disconnect or keep the existing
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
408 connection. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
409 if (director_host_cmp_to_self(conn->host, dir->right->host,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
410 dir->self_host) <= 0) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
411 /* the old connection is the correct one */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
412 i_warning("Aborting incorrect outgoing connection to %s "
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
413 "(already connected to correct one: %s)",
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
414 conn->host->name, dir->right->host->name);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
415 conn->wrong_host = TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
416 return FALSE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
417 }
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
418 i_warning("Replacing right director connection %s with %s",
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
419 dir->right->host->name, conn->host->name);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
420 director_connection_deinit(&dir->right, t_strdup_printf(
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
421 "Replacing with %s", conn->host->name));
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
422 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
423 dir->right = conn;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
424 i_free(conn->name);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
425 conn->name = i_strdup_printf("%s/right", conn->host->name);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
426 director_connection_assigned(conn);
20971
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
427 director_send_delayed_syncs(dir);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
428 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
429 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
430
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 static bool
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 director_args_parse_ip_port(struct director_connection *conn,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 const char *const *args,
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
434 struct ip_addr *ip_r, in_port_t *port_r)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
436 if (args[0] == NULL || args[1] == NULL) {
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
437 director_cmd_error(conn, "Missing IP+port parameters");
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
438 return FALSE;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
439 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440 if (net_addr2ip(args[0], ip_r) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
441 director_cmd_error(conn, "Invalid IP address: %s", args[0]);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
442 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443 }
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
444 if (net_str2port(args[1], port_r) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
445 director_cmd_error(conn, "Invalid port: %s", args[1]);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451 static bool director_cmd_me(struct director_connection *conn,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 const char *const *args)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454 struct director *dir = conn->dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 const char *connect_str;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456 struct ip_addr ip;
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
457 in_port_t port;
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
458 time_t next_comm_attempt;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
460 if (!director_args_parse_ip_port(conn, args, &ip, &port))
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
461 return FALSE;
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
462 if (conn->me_received) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
463 director_cmd_error(conn, "Duplicate ME");
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
464 return FALSE;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
465 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467 if (!conn->in && (!net_ip_compare(&conn->host->ip, &ip) ||
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 conn->host->port != port)) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469 i_error("Remote director thinks it's someone else "
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470 "(connected to %s:%u, remote says it's %s:%u)",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
471 conn->host->ip_str, conn->host->port,
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472 net_ip2addr(&ip), port);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 conn->me_received = TRUE;
22252
8882a5cbe76d director: Use more accurate timestamps for handshake timeout logging
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22251
diff changeset
476 conn->me_received_time = ioloop_timeval;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477
19294
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
478 if (args[2] != NULL) {
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
479 time_t remote_time;
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
480 int diff;
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
481
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
482 if (str_to_time(args[2], &remote_time) < 0) {
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
483 director_cmd_error(conn, "Invalid ME timestamp");
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
484 return FALSE;
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
485 }
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
486 diff = ioloop_time - remote_time;
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
487 if (diff > DIRECTOR_MAX_CLOCK_DIFF_WARN_SECS ||
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
488 (diff < 0 && -diff > DIRECTOR_MAX_CLOCK_DIFF_WARN_SECS)) {
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
489 i_warning("Director %s clock differs from ours by %d secs",
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
490 conn->name, diff);
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
491 }
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
492 }
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
493
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
494 timeout_remove(&conn->to_ping);
22250
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
495 if (conn->in) {
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
496 conn->to_ping = timeout_add(DIRECTOR_CONNECTION_DONE_TIMEOUT_MSECS,
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
497 director_connection_init_timeout, conn);
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
498 } else {
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
499 conn->to_ping = timeout_add(DIRECTOR_CONNECTION_SEND_USERS_TIMEOUT_MSECS,
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
500 director_connection_init_timeout, conn);
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
501 }
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
502
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503 if (!conn->in)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
504 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
505
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
506 /* Incoming connection:
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
507
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
508 a) we don't have an established ring yet. make sure we're connecting
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
509 to our right side (which might become our left side).
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
510
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
511 b) it's our current "left" connection. the previous connection
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
512 is most likely dead.
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
513
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
514 c) we have an existing ring. tell our current "left" to connect to
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
515 it with CONNECT command.
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
516
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
517 d) the incoming connection doesn't belong to us at all, refer it
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
518 elsewhere with CONNECT. however, before disconnecting it verify
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
519 first that our left side is actually still functional.
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
520 */
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
521 i_assert(conn->host == NULL);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
522 conn->host = director_host_get(dir, &ip, port);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
523 /* the host shouldn't be removed at this point, but if for some
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
524 reason it is we don't want to crash */
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
525 conn->host->removed = FALSE;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
526 director_host_ref(conn->host);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
527 /* make sure we don't keep old sequence values across restarts */
16699
9531ec8afe8b director: Reset last-seen-sync-sequence after remote director restarts.
Timo Sirainen <tss@iki.fi>
parents: 16695
diff changeset
528 director_host_restarted(conn->host);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
529
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
530 next_comm_attempt = conn->host->last_protocol_failure +
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
531 DIRECTOR_PROTOCOL_FAILURE_RETRY_SECS;
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
532 if (next_comm_attempt > ioloop_time) {
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
533 /* 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
534 don't try retrying yet */
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
535 i_error("director(%s): Remote sent invalid protocol data recently, "
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
536 "waiting %u secs before allowing further communication",
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
537 conn->name, (unsigned int)(next_comm_attempt-ioloop_time));
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
538 return FALSE;
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
539 } else if (dir->left == NULL) {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
540 /* a) - just in case the left is also our right side reset
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
541 its failed state, so we can 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
542 conn->host->last_network_failure = 0;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
543 if (!director_has_outgoing_connections(dir))
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
544 director_connect(dir, "Connecting to left");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
545 } else if (dir->left->host == conn->host) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
546 /* b) */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
547 i_assert(dir->left != conn);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
548 director_connection_deinit(&dir->left,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
549 "Replacing with new incoming connection");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
550 } else if (director_host_cmp_to_self(conn->host, dir->left->host,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
551 dir->self_host) < 0) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
552 /* c) */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
553 connect_str = t_strdup_printf("CONNECT\t%s\t%u\n",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
554 conn->host->ip_str,
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
555 conn->host->port);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
556 director_connection_send(dir->left, connect_str);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
557 } else {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
558 /* d) */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
559 dir->left->verifying_left = TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
560 director_connection_ping(dir->left);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
561 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
562 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
563 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
564
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
565 static bool
14303
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
566 director_user_refresh(struct director_connection *conn,
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
567 unsigned int username_hash, struct mail_host *host,
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
568 time_t timestamp, bool weak, bool *forced_r,
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
569 struct user **user_r)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
570 {
14303
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
571 struct director *dir = conn->dir;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
572 struct user *user;
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
573 bool ret = FALSE, unset_weak_user = FALSE;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21077
diff changeset
574 struct user_directory *users = host->tag->users;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
575
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
576 *forced_r = FALSE;
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
577
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
578 user = user_directory_lookup(users, username_hash);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
579 if (user == NULL) {
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
580 *user_r = user_directory_add(users, username_hash,
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
581 host, timestamp);
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
582 (*user_r)->weak = weak;
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
583 dir_debug("user refresh: %u added", username_hash);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
584 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
585 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
586
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
587 if (user->weak) {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
588 if (!weak) {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
589 /* removing user's weakness */
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
590 dir_debug("user refresh: %u weakness removed",
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
591 username_hash);
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
592 unset_weak_user = TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
593 user->weak = FALSE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
594 ret = TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
595 } else {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
596 /* weak user marked again as weak */
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
597 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
598 } else if (weak &&
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
599 !user_directory_user_is_recently_updated(users, user)) {
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
600 /* mark the user as weak */
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
601 dir_debug("user refresh: %u set weak", username_hash);
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
602 user->weak = TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
603 ret = TRUE;
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
604 } else if (weak) {
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
605 dir_debug("user refresh: %u weak update to %s ignored, "
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
606 "we recently changed it to %s",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
607 username_hash, host->ip_str,
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
608 user->host->ip_str);
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
609 host = user->host;
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
610 ret = TRUE;
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
611 } else if (user->host == host) {
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
612 /* update to the same host */
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
613 } else if (user_directory_user_is_near_expiring(users, user)) {
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
614 /* host conflict for a user that is already near expiring. we can
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
615 assume that the other director had already dropped this user
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
616 and we should have as well. use the new host. */
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
617 dir_debug("user refresh: %u is nearly expired, "
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
618 "replacing host %s with %s", username_hash,
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
619 user->host->ip_str, host->ip_str);
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
620 ret = TRUE;
20986
410eacd7ad40 director: Code cleanup - added USER_IS_BEING_KILLED() macro
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
621 } else if (USER_IS_BEING_KILLED(user)) {
18708
51ee438392c7 director: Moving a user to another host sometimes caused the move to fail.
Timo Sirainen <tss@iki.fi>
parents: 18665
diff changeset
622 /* user is still being moved - ignore conflicting host updates
51ee438392c7 director: Moving a user to another host sometimes caused the move to fail.
Timo Sirainen <tss@iki.fi>
parents: 18665
diff changeset
623 from other directors who don't yet know about the move. */
51ee438392c7 director: Moving a user to another host sometimes caused the move to fail.
Timo Sirainen <tss@iki.fi>
parents: 18665
diff changeset
624 dir_debug("user refresh: %u is being moved, "
51ee438392c7 director: Moving a user to another host sometimes caused the move to fail.
Timo Sirainen <tss@iki.fi>
parents: 18665
diff changeset
625 "preserve its host %s instead of replacing with %s",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
626 username_hash, user->host->ip_str, host->ip_str);
18708
51ee438392c7 director: Moving a user to another host sometimes caused the move to fail.
Timo Sirainen <tss@iki.fi>
parents: 18665
diff changeset
627 host = user->host;
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
628 } else {
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
629 /* non-weak user received a non-weak update with
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
630 conflicting host. this shouldn't happen. */
14303
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
631 string_t *str = t_str_new(128);
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
632
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
633 str_printfa(str, "User hash %u "
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
634 "is being redirected to two hosts: %s and %s",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
635 username_hash, user->host->ip_str, host->ip_str);
14303
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
636 str_printfa(str, " (old_ts=%ld", (long)user->timestamp);
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
637
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
638 if (!conn->handshake_received) {
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
639 str_printfa(str, ",handshaking,recv_ts=%ld",
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
640 (long)timestamp);
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
641 }
20986
410eacd7ad40 director: Code cleanup - added USER_IS_BEING_KILLED() macro
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
642 if (USER_IS_BEING_KILLED(user)) {
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20986
diff changeset
643 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: 20986
diff changeset
644 str_append(str, ",moving");
20974
7ea3a96eea43 director: Log user's kill_state with a human-readable string.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20972
diff changeset
645 str_printfa(str, ",kill_state=%s",
20988
9d4039e2ae25 director: Moved all user killing state to struct director_kill_context
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20986
diff changeset
646 user_kill_state_names[user->kill_ctx->kill_state]);
20974
7ea3a96eea43 director: Log user's kill_state with a human-readable string.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20972
diff changeset
647 }
14303
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
648 str_append_c(str, ')');
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
649 i_error("%s", str_c(str));
11581
ecf195115922 director: If same user gets redirected to two hosts, don't crash later.
Timo Sirainen <tss@iki.fi>
parents: 11579
diff changeset
650
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
651 /* we want all the directors to redirect the user to same
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
652 server, but we don't want two directors fighting over which
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
653 server it belongs to, so always use the lower IP address */
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
654 if (net_ip_cmp(&user->host->ip, &host->ip) > 0) {
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
655 /* change the host. we'll also need to remove the user
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
656 from the old host's user_count, because we can't
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
657 keep track of the user for more than one host.
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
658
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
659 send the updated USER back to the sender as well. */
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
660 *forced_r = TRUE;
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
661 } else {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
662 /* keep the host */
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
663 host = user->host;
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
664 }
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
665 /* especially IMAP connections can take a long time to die.
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
666 make sure we kill off the connections in the wrong
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
667 backends. */
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
668 director_kick_user_hash(dir, dir->self_host, 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
669 username_hash, &host->ip);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
670 ret = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
671 }
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
672 if (user->host != host) {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
673 user->host->user_count--;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
674 user->host = host;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
675 user->host->user_count++;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
676 ret = TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
677 }
14303
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
678 if (timestamp == ioloop_time && (time_t)user->timestamp != timestamp) {
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
679 user_directory_refresh(users, user);
14303
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
680 ret = TRUE;
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
681 }
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
682 dir_debug("user refresh: %u refreshed timeout to %ld",
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
683 username_hash, (long)user->timestamp);
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
684
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
685 if (unset_weak_user) {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
686 /* user is no longer weak. handle pending requests for
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
687 this user if there are any */
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
688 director_set_state_changed(conn->dir);
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
689 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
690
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
691 *user_r = user;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
692 return ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
693 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
694
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
695 static bool
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
696 director_handshake_cmd_user(struct director_connection *conn,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
697 const char *const *args)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
698 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
699 unsigned int username_hash, timestamp;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
700 struct ip_addr ip;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
701 struct mail_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
702 struct user *user;
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
703 bool weak, forced;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
704
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
705 if (str_array_length(args) < 3 ||
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
706 str_to_uint(args[0], &username_hash) < 0 ||
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
707 net_addr2ip(args[1], &ip) < 0 ||
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
708 str_to_uint(args[2], &timestamp) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
709 director_cmd_error(conn, "Invalid parameters");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
710 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
711 }
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
712 weak = args[3] != NULL && args[3][0] == 'w';
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
713
11352
19336bddada2 director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents: 11350
diff changeset
714 host = mail_host_lookup(conn->dir->mail_hosts, &ip);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
715 if (host == NULL) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
716 i_error("director(%s): USER used unknown host %s in handshake",
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
717 conn->name, args[1]);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
718 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
719 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
720
22668
3d99067fb0b9 director: Make sure user's timestamp isn't set to future
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22666
diff changeset
721 if (timestamp > ioloop_time) {
22670
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
722 /* The other director's clock seems to be into the future
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
723 compared to us. Don't set any of our users' timestamps into
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
724 future though. It's most likely only 1 second difference. */
22668
3d99067fb0b9 director: Make sure user's timestamp isn't set to future
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22666
diff changeset
725 timestamp = ioloop_time;
3d99067fb0b9 director: Make sure user's timestamp isn't set to future
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22666
diff changeset
726 }
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14681
diff changeset
727 (void)director_user_refresh(conn, username_hash, host,
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
728 timestamp, weak, &forced, &user);
22670
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
729 /* Possibilities:
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
730
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
731 a) The user didn't exist yet, and it was added with the given
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
732 timestamp.
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
733
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
734 b) The user existed, but with an older timestamp. The timestamp
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
735 wasn't yet updated, so do it here below.
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
736
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
737 c) The user existed with a newer timestamp. This is either because
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
738 we already received a non-handshake USER update for this user, or
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
739 our director saw a login for this user. Ignore this update.
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
740
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
741 (We never want to change the user's timestamp to be older, because
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
742 that could result in directors going to a loop fighting each others
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
743 over a flipping timestamp.) */
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
744 if (user->timestamp < timestamp)
16621
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
745 user->timestamp = timestamp;
22670
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
746 /* always sort users after handshaking to make sure the order
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
747 is correct */
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
748 conn->users_unsorted = TRUE;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
749 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
750 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
751
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
752 static bool
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
753 director_cmd_user(struct director_connection *conn,
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
754 const char *const *args)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
755 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
756 unsigned int username_hash;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
757 struct ip_addr ip;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
758 struct mail_host *host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
759 struct user *user;
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
760 bool forced;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
761
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
762 /* NOTE: if more parameters are added, update also
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
763 CMD_IS_USER_HANDHAKE() macro */
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
764 if (str_array_length(args) != 2 ||
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
765 str_to_uint(args[0], &username_hash) < 0 ||
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
766 net_addr2ip(args[1], &ip) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
767 director_cmd_error(conn, "Invalid parameters");
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
768 return FALSE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
769 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
770
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
771 host = mail_host_lookup(conn->dir->mail_hosts, &ip);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
772 if (host == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
773 /* we probably just removed this host. */
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
774 return TRUE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
775 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
776
14303
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
777 if (director_user_refresh(conn, username_hash,
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
778 host, ioloop_time, FALSE, &forced, &user)) {
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
779 struct director_host *src_host =
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
780 forced ? conn->dir->self_host : conn->host;
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
781 i_assert(!user->weak);
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
782 director_update_user(conn->dir, src_host, user);
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
783 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
784 return TRUE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
785 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
786
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
787 static bool director_cmd_director(struct director_connection *conn,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
788 const char *const *args)
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 struct director_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
791 struct ip_addr ip;
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
792 in_port_t port;
22562
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22446
diff changeset
793 bool log_add = FALSE;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
794
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
795 if (!director_args_parse_ip_port(conn, args, &ip, &port))
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
796 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
797
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
798 host = director_host_lookup(conn->dir, &ip, port);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
799 if (host != NULL) {
14493
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
800 if (host == conn->dir->self_host) {
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
801 /* ignore updates to ourself */
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
802 return TRUE;
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
803 }
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
804 if (host->removed) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
805 /* ignore re-adds of removed directors */
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
806 return TRUE;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
807 }
14493
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
808
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
809 /* already have this. just reset its last_network_failure
22565
ad4d877d655b director: Don't reset directors' last_network_failure while handshaking
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
810 timestamp, since it might be up now, but only if this
ad4d877d655b director: Don't reset directors' last_network_failure while handshaking
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
811 isn't part of the handshake. (if it was, reseting the
ad4d877d655b director: Don't reset directors' last_network_failure while handshaking
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
812 timestamp could cause us to rapidly keep trying to connect
ad4d877d655b director: Don't reset directors' last_network_failure while handshaking
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
813 to it) */
ad4d877d655b director: Don't reset directors' last_network_failure while handshaking
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
814 if (conn->handshake_received)
ad4d877d655b director: Don't reset directors' last_network_failure while handshaking
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
815 host->last_network_failure = 0;
16789
5d43c926eb97 director: Make sure director restart notifications go to everyone in the ring.
Timo Sirainen <tss@iki.fi>
parents: 16788
diff changeset
816 /* it also may have been restarted, reset its state */
5d43c926eb97 director: Make sure director restart notifications go to everyone in the ring.
Timo Sirainen <tss@iki.fi>
parents: 16788
diff changeset
817 director_host_restarted(host);
14493
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
818 } else {
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
819 /* save the director and forward it */
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
820 host = director_host_add(conn->dir, &ip, port);
22562
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22446
diff changeset
821 log_add = TRUE;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
822 }
16789
5d43c926eb97 director: Make sure director restart notifications go to everyone in the ring.
Timo Sirainen <tss@iki.fi>
parents: 16788
diff changeset
823 /* just forward this to the entire ring until it reaches back to
5d43c926eb97 director: Make sure director restart notifications go to everyone in the ring.
Timo Sirainen <tss@iki.fi>
parents: 16788
diff changeset
824 itself. some hosts may see this twice, but that's the only way to
5d43c926eb97 director: Make sure director restart notifications go to everyone in the ring.
Timo Sirainen <tss@iki.fi>
parents: 16788
diff changeset
825 guarantee that it gets seen by everyone. reseting the host multiple
5d43c926eb97 director: Make sure director restart notifications go to everyone in the ring.
Timo Sirainen <tss@iki.fi>
parents: 16788
diff changeset
826 times may cause us to handle its commands multiple times, but the
18665
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
827 commands can handle that. however, we need to also handle a
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
828 situation where the added director never comes back - we don't want
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
829 to send the director information in a loop forever. */
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
830 if (conn->dir->right != NULL &&
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
831 director_host_cmp_to_self(host, conn->dir->right->host,
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
832 conn->dir->self_host) > 0) {
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
833 dir_debug("Received DIRECTOR update for a host where we should be connected to. "
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
834 "Not forwarding it since it's probably crashed.");
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
835 } else {
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
836 director_notify_ring_added(host,
22562
3af1ba6b5248 director: Log info line whenever a director is added/removed from ring
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22446
diff changeset
837 director_connection_get_host(conn), log_add);
18665
b7aed6290e7e director: Don't send DIRECTOR command infinitely in loop if that director got disconnected.
Timo Sirainen <tss@iki.fi>
parents: 18664
diff changeset
838 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
839 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
840 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
841
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
842 static bool director_cmd_director_remove(struct director_connection *conn,
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
843 const char *const *args)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
844 {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
845 struct director_host *host;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
846 struct ip_addr ip;
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
847 in_port_t port;
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
848
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
849 if (!director_args_parse_ip_port(conn, args, &ip, &port))
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
850 return FALSE;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
851
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
852 host = director_host_lookup(conn->dir, &ip, port);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
853 if (host != NULL && !host->removed)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
854 director_ring_remove(host, director_connection_get_host(conn));
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
855 return TRUE;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
856 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
857
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
858 static bool
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
859 director_cmd_host_hand_start(struct director_connection *conn,
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
860 const char *const *args)
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
861 {
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
862 const ARRAY_TYPE(mail_host) *hosts;
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
863 struct mail_host *const *hostp;
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
864 unsigned int remote_ring_completed;
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
865
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
866 if (args[0] == NULL ||
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
867 str_to_uint(args[0], &remote_ring_completed) < 0) {
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
868 director_cmd_error(conn, "Invalid parameters");
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
869 return FALSE;
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
870 }
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
871
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
872 if (remote_ring_completed && !conn->dir->ring_handshaked) {
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
873 /* clear everything we have and use only what remote sends us */
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
874 dir_debug("%s: We're joining a ring - replace all hosts",
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
875 conn->name);
11352
19336bddada2 director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents: 11350
diff changeset
876 hosts = mail_hosts_get(conn->dir->mail_hosts);
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
877 while (array_count(hosts) > 0) {
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
878 hostp = array_idx(hosts, 0);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
879 director_remove_host(conn->dir, NULL, NULL, *hostp);
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
880 }
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
881 } else if (!remote_ring_completed && conn->dir->ring_handshaked) {
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
882 /* ignore whatever remote sends */
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
883 dir_debug("%s: Remote is joining our ring - "
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
884 "ignore all remote HOSTs", conn->name);
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
885 conn->ignore_host_events = TRUE;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
886 } else {
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
887 dir_debug("%s: Merge rings' hosts", conn->name);
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
888 }
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
889 conn->handshake_sending_hosts = TRUE;
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
890 return TRUE;
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
891 }
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
892
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
893 static int
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
894 director_cmd_is_seen_full(struct director_connection *conn,
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
895 const char *const **_args, unsigned int *seq_r,
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
896 struct director_host **host_r)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
897 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
898 const char *const *args = *_args;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
899 struct ip_addr ip;
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
900 in_port_t port;
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
901 unsigned int seq;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
902 struct director_host *host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
903
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
904 if (str_array_length(args) < 3 ||
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
905 net_addr2ip(args[0], &ip) < 0 ||
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
906 net_str2port(args[1], &port) < 0 ||
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
907 str_to_uint(args[2], &seq) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
908 director_cmd_error(conn, "Invalid parameters");
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
909 return -1;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
910 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
911 *_args = args + 3;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
912 *seq_r = seq;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
913
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
914 host = director_host_lookup(conn->dir, &ip, port);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
915 if (host == NULL || host->removed) {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
916 /* director is already gone, but we can't be sure if this
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
917 command was sent everywhere. re-send it as if it was from
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
918 ourself. */
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
919 *host_r = NULL;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
920 } else {
15350
bb095315d025 Make static analyzer happier.
Timo Sirainen <tss@iki.fi>
parents: 15337
diff changeset
921 *host_r = host;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
922 if (seq <= host->last_seq) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
923 /* already seen this */
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
924 return 1;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
925 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
926 host->last_seq = seq;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
927 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
928 return 0;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
929 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
930
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
931 static int
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
932 director_cmd_is_seen(struct director_connection *conn,
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
933 const char *const **_args,
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
934 struct director_host **host_r)
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
935 {
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
936 unsigned int seq;
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
937
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
938 return director_cmd_is_seen_full(conn, _args, &seq, host_r);
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
939 }
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
940
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
941 static bool
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
942 director_cmd_user_weak(struct director_connection *conn,
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
943 const char *const *args)
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
944 {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
945 struct director_host *dir_host;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
946 struct ip_addr ip;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
947 unsigned int username_hash;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
948 struct mail_host *host;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
949 struct user *user;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
950 struct director_host *src_host = conn->host;
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
951 bool weak = TRUE, weak_forward = FALSE, forced;
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
952 int ret;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
953
15320
e4c337f38ed6 director: Fixed previous broken change for handling USER-WEAK commands.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
954 /* note that unlike other commands we don't want to just ignore
e4c337f38ed6 director: Fixed previous broken change for handling USER-WEAK commands.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
955 duplicate commands */
e4c337f38ed6 director: Fixed previous broken change for handling USER-WEAK commands.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
956 if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) < 0)
15324
1dcf0090648e director: Minor code cleanup
Timo Sirainen <tss@iki.fi>
parents: 15320
diff changeset
957 return FALSE;
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
958
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
959 if (str_array_length(args) != 2 ||
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
960 str_to_uint(args[0], &username_hash) < 0 ||
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
961 net_addr2ip(args[1], &ip) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
962 director_cmd_error(conn, "Invalid parameters");
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
963 return FALSE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
964 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
965
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
966 host = mail_host_lookup(conn->dir->mail_hosts, &ip);
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
967 if (host == NULL) {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
968 /* we probably just removed this host. */
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
969 return TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
970 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
971
19953
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
972 if (ret == 0) {
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
973 /* First time we're seeing this - forward it to others also.
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
974 We'll want to do it even if the user was already marked as
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
975 weak, because otherwise if two directors mark the user weak
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
976 at the same time both the USER-WEAK notifications reach
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
977 only half the directors until they collide and neither one
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
978 finishes going through the whole ring marking the user
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
979 non-weak. */
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
980 weak_forward = TRUE;
a502d38e7b70 director: Fixed user weakness getting stuck if multiple directors set user weak simultaneously
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19608
diff changeset
981 } else if (dir_host == conn->dir->self_host) {
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
982 /* We originated this USER-WEAK request. The entire ring has seen
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
983 it and there weren't any conflicts. Make the user non-weak. */
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
984 dir_debug("user refresh: %u Our USER-WEAK seen by the entire ring",
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
985 username_hash);
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
986 src_host = conn->dir->self_host;
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
987 weak = FALSE;
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
988 } else {
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
989 /* The original USER-WEAK sender will send a new non-weak USER
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
990 update saying what really happened. We'll still need to forward
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
991 this around the ring to the origin so it also knows it has
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
992 travelled through the ring. */
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
993 dir_debug("user refresh: %u Remote USER-WEAK from %s seen by the entire ring, ignoring",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
994 username_hash, dir_host->ip_str);
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
995 weak_forward = TRUE;
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
996 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
997
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
998 if (director_user_refresh(conn, username_hash,
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
999 host, ioloop_time, weak, &forced, &user) ||
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
1000 weak_forward) {
20978
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
1001 if (forced)
7a4fb29a4e52 director: If user host conflict is detected, make sure new host is sent back.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20974
diff changeset
1002 src_host = conn->dir->self_host;
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1003 if (!user->weak)
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1004 director_update_user(conn->dir, src_host, user);
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1005 else {
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
1006 director_update_user_weak(conn->dir, src_host, conn,
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1007 dir_host, user);
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1008 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1009 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1010 return TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1011 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1012
14629
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 14575
diff changeset
1013 static bool ATTR_NULL(3)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1014 director_cmd_host_int(struct director_connection *conn, const char *const *args,
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1015 struct director_host *dir_host)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1016 {
19287
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1017 struct director_host *src_host = conn->host;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1018 struct mail_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1019 struct ip_addr ip;
19408
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
1020 const char *tag = "", *host_tag, *hostname = NULL;
19309
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1021 unsigned int arg_count, vhost_count;
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1022 bool update, down = FALSE;
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1023 time_t last_updown_change = 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1024
19309
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1025 arg_count = str_array_length(args);
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1026 if (arg_count < 2 ||
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1027 net_addr2ip(args[0], &ip) < 0 ||
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1028 str_to_uint(args[1], &vhost_count) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1029 director_cmd_error(conn, "Invalid parameters");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1030 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1031 }
19309
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1032 if (arg_count >= 3)
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1033 tag = args[2];
19309
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1034 if (arg_count >= 4) {
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1035 if ((args[3][0] != 'D' && args[3][0] != 'U') ||
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1036 str_to_time(args[3]+1, &last_updown_change) < 0) {
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1037 director_cmd_error(conn, "Invalid updown parameters");
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1038 return FALSE;
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1039 }
19309
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1040 down = args[3][0] == 'D';
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1041 }
19310
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1042 if (arg_count >= 5)
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1043 hostname = args[4];
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1044 if (conn->ignore_host_events) {
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1045 /* remote is sending hosts in a handshake, but it doesn't have
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1046 a completed ring and we do. */
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
1047 i_assert(conn->handshake_sending_hosts);
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1048 return TRUE;
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1049 }
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1050 if (tag[0] != '\0' && conn->minor_version < DIRECTOR_VERSION_TAGS_V2) {
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1051 director_cmd_error(conn, "Received a host tag from older director version with incompatible tagging support");
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1052 return FALSE;
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1053 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1054
11352
19336bddada2 director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents: 11350
diff changeset
1055 host = mail_host_lookup(conn->dir->mail_hosts, &ip);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1056 if (host == NULL) {
19310
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1057 host = mail_host_add_hostname(conn->dir->mail_hosts,
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1058 hostname, &ip, tag);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1059 update = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1060 } else {
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1061 update = host->vhost_count != vhost_count ||
19506
e6aa0aa3d599 director: Don't trigger a ring resync if only last_updown_change has changed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19411
diff changeset
1062 host->down != down;
19292
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1063
19408
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
1064 host_tag = mail_host_get_tag(host);
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
1065 if (strcmp(tag, host_tag) != 0) {
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1066 i_error("director(%s): Host %s changed tag from '%s' to '%s'",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
1067 conn->name, host->ip_str,
19408
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
1068 host_tag, tag);
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1069 mail_host_set_tag(host, tag);
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1070 update = TRUE;
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1071 }
19287
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1072 if (update && host->desynced) {
19608
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1073 string_t *str = t_str_new(128);
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1074
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1075 str_printfa(str, "director(%s): Host %s is being updated before previous update had finished (",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
1076 conn->name, host->ip_str);
20286
4d926d1e9164 director: Fixed ignoring an obsolete up/down change while host is desynced.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20264
diff changeset
1077 if (host->down != down &&
4d926d1e9164 director: Fixed ignoring an obsolete up/down change while host is desynced.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20264
diff changeset
1078 host->last_updown_change > last_updown_change) {
4d926d1e9164 director: Fixed ignoring an obsolete up/down change while host is desynced.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20264
diff changeset
1079 /* our host has a newer change. preserve it. */
4d926d1e9164 director: Fixed ignoring an obsolete up/down change while host is desynced.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20264
diff changeset
1080 down = host->down;
4d926d1e9164 director: Fixed ignoring an obsolete up/down change while host is desynced.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20264
diff changeset
1081 }
19608
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1082 if (host->down != down) {
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1083 if (host->down)
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1084 str_append(str, "down -> up");
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1085 else
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1086 str_append(str, "up -> down");
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1087 }
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1088 if (host->vhost_count != vhost_count) {
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1089 if (host->down != down)
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1090 str_append(str, ", ");
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1091 str_printfa(str, "vhosts %u -> %u",
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1092 host->vhost_count, vhost_count);
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1093 }
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1094 str_append(str, ") - ");
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1095
19287
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1096 vhost_count = I_MIN(vhost_count, host->vhost_count);
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1097 last_updown_change = I_MAX(last_updown_change,
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1098 host->last_updown_change);
19608
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1099 str_printfa(str, "setting to state=%s vhosts=%u",
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1100 down ? "down" : "up", vhost_count);
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1101 i_warning("%s", str_c(str));
19287
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1102 /* make the change appear to come from us, so it
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1103 reaches the full ring */
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1104 dir_host = NULL;
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1105 src_host = conn->dir->self_host;
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1106 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1107 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1108
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1109 if (update) {
21842
86e52ff70044 director: Log vhost count changes and HOST-UP/DOWN
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21390
diff changeset
1110 const char *log_prefix = t_strdup_printf("director(%s): ",
86e52ff70044 director: Log vhost count changes and HOST-UP/DOWN
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21390
diff changeset
1111 conn->name);
86e52ff70044 director: Log vhost count changes and HOST-UP/DOWN
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21390
diff changeset
1112 mail_host_set_down(host, down, last_updown_change, log_prefix);
86e52ff70044 director: Log vhost count changes and HOST-UP/DOWN
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21390
diff changeset
1113 mail_host_set_vhost_count(host, vhost_count, log_prefix);
19287
0f9d4f1a083d director: Don't become desynced if two directors change the same backend in incompatible ways.
Timo Sirainen <tss@iki.fi>
parents: 19036
diff changeset
1114 director_update_host(conn->dir, src_host, dir_host, host);
19292
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1115 } else {
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1116 dir_debug("Ignoring host %s update vhost_count=%u "
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1117 "down=%d last_updown_change=%ld (hosts_hash=%u)",
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1118 net_ip2addr(&ip), vhost_count, down,
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1119 (long)last_updown_change,
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1120 mail_hosts_hash(conn->dir->mail_hosts));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1121 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1122 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1123 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1124
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1125 static bool
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1126 director_cmd_host_handshake(struct director_connection *conn,
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1127 const char *const *args)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1128 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1129 return director_cmd_host_int(conn, args, NULL);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1130 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1131
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1132 static bool
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1133 director_cmd_host(struct director_connection *conn, const char *const *args)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1134 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1135 struct director_host *dir_host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1136 int ret;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1137
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1138 if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1139 return ret > 0;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1140 return director_cmd_host_int(conn, args, dir_host);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1141 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1142
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1143 static bool
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1144 director_cmd_host_remove(struct director_connection *conn,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1145 const char *const *args)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1146 {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1147 struct director_host *dir_host;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1148 struct mail_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1149 struct ip_addr ip;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1150 int ret;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1151
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1152 if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1153 return ret > 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1154
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1155 if (str_array_length(args) != 1 ||
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1156 net_addr2ip(args[0], &ip) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1157 director_cmd_error(conn, "Invalid parameters");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1158 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1159 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1160
11352
19336bddada2 director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents: 11350
diff changeset
1161 host = mail_host_lookup(conn->dir->mail_hosts, &ip);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1162 if (host != NULL)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1163 director_remove_host(conn->dir, conn->host, dir_host, host);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1164 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1165 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1166
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1167 static bool
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1168 director_cmd_host_flush(struct director_connection *conn,
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1169 const char *const *args)
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1170 {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1171 struct director_host *dir_host;
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1172 struct mail_host *host;
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1173 struct ip_addr ip;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1174 int ret;
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1175
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1176 if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1177 return ret > 0;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1178
11816
9e41df232dd6 director: Fixed handling HOST-FLUSH commands.
Timo Sirainen <tss@iki.fi>
parents: 11758
diff changeset
1179 if (str_array_length(args) != 1 ||
9e41df232dd6 director: Fixed handling HOST-FLUSH commands.
Timo Sirainen <tss@iki.fi>
parents: 11758
diff changeset
1180 net_addr2ip(args[0], &ip) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1181 director_cmd_error(conn, "Invalid parameters");
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1182 return FALSE;
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1183 }
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1184
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1185 host = mail_host_lookup(conn->dir->mail_hosts, &ip);
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1186 if (host != NULL)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1187 director_flush_host(conn->dir, conn->host, dir_host, host);
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1188 return TRUE;
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1189 }
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1190
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1191 static bool
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1192 director_cmd_user_move(struct director_connection *conn,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1193 const char *const *args)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1194 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1195 struct director_host *dir_host;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1196 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
1197 struct ip_addr ip;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1198 unsigned int 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
1199 int ret;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1200
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1201 if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1202 return ret > 0;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1203
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1204 if (str_array_length(args) != 2 ||
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1205 str_to_uint(args[0], &username_hash) < 0 ||
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1206 net_addr2ip(args[1], &ip) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1207 director_cmd_error(conn, "Invalid parameters");
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1208 return FALSE;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1209 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1210
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1211 host = mail_host_lookup(conn->dir->mail_hosts, &ip);
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1212 if (host != NULL) {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1213 director_move_user(conn->dir, conn->host, dir_host,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1214 username_hash, host);
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1215 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1216 return TRUE;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1217 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1218
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1219 static bool
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1220 director_cmd_user_kick(struct director_connection *conn,
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1221 const char *const *args)
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1222 {
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1223 struct director_host *dir_host;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1224 int ret;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1225
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1226 if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0)
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1227 return ret > 0;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1228
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1229 if (str_array_length(args) != 1) {
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1230 director_cmd_error(conn, "Invalid parameters");
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1231 return FALSE;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1232 }
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1233
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1234 director_kick_user(conn->dir, conn->host, dir_host, args[0]);
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1235 return TRUE;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1236 }
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1237
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1238 static bool
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1239 director_cmd_user_kick_alt(struct director_connection *conn,
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1240 const char *const *args)
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1241 {
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1242 struct director_host *dir_host;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1243 int ret;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1244
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1245 if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0)
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1246 return ret > 0;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1247
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1248 if (str_array_length(args) != 2) {
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1249 director_cmd_error(conn, "Invalid parameters");
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1250 return FALSE;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1251 }
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1252
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1253 director_kick_user_alt(conn->dir, conn->host, dir_host, args[0], args[1]);
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1254 return TRUE;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1255 }
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1256
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1257 static bool
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
1258 director_cmd_user_kick_hash(struct director_connection *conn,
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 const char *const *args)
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 {
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 struct director_host *dir_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
1262 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
1263 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
1264 int ret;
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 if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0)
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 return ret > 0;
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
1268
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 if (str_array_length(args) != 2 ||
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
1270 str_to_uint(args[0], &username_hash) < 0 ||
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 net_addr2ip(args[1], &except_ip) < 0) {
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 director_cmd_error(conn, "Invalid parameters");
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 return FALSE;
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 }
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 director_kick_user_hash(conn->dir, conn->host, dir_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
1277 username_hash, &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
1278 return TRUE;
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 }
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 static bool
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1282 director_cmd_user_killed(struct director_connection *conn,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1283 const char *const *args)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1284 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1285 unsigned int 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
1286
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1287 if (str_array_length(args) != 1 ||
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1288 str_to_uint(args[0], &username_hash) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1289 director_cmd_error(conn, "Invalid parameters");
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1290 return FALSE;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1291 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1292
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1293 director_user_killed(conn->dir, 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
1294 return TRUE;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1295 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1296
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1297 static bool
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1298 director_cmd_user_killed_everywhere(struct director_connection *conn,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1299 const char *const *args)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1300 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1301 struct director_host *dir_host;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1302 unsigned int seq, 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
1303 int ret;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1304
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1305 if ((ret = director_cmd_is_seen_full(conn, &args, &seq, &dir_host)) < 0)
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1306 return 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
1307
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1308 if (str_array_length(args) != 1 ||
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1309 str_to_uint(args[0], &username_hash) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1310 director_cmd_error(conn, "Invalid parameters");
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 return FALSE;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1312 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1313
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1314 if (ret > 0) {
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1315 i_assert(dir_host != NULL);
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1316 dir_debug("User %u - ignoring already seen USER-KILLED-EVERYWHERE "
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1317 "with seq=%u <= %s.last_seq=%u", username_hash,
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1318 seq, dir_host->name, dir_host->last_seq);
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1319 return TRUE;
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1320 }
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1321
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1322 director_user_killed_everywhere(conn->dir, conn->host,
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1323 dir_host, 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
1324 return TRUE;
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1325 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1326
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1327 static bool director_handshake_cmd_done(struct director_connection *conn)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1328 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1329 struct director *dir = conn->dir;
22252
8882a5cbe76d director: Use more accurate timestamps for handshake timeout logging
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22251
diff changeset
1330 int handshake_msecs = timeval_diff_msecs(&ioloop_timeval, &conn->connected_time);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1331 string_t *str;
14478
ee169584bc44 director: Improved debug handshake message.
Timo Sirainen <tss@iki.fi>
parents: 14477
diff changeset
1332
16621
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
1333 if (conn->users_unsorted && conn->user_iter == NULL) {
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
1334 /* we sent our user list before receiving remote's */
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
1335 conn->users_unsorted = FALSE;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21077
diff changeset
1336 mail_hosts_sort_users(conn->dir->mail_hosts);
16621
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
1337 }
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
1338
18063
91c525000811 director: Always log a message when director handshake finishes.
Timo Sirainen <tss@iki.fi>
parents: 18062
diff changeset
1339 str = t_str_new(128);
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
1340 str_printfa(str, "director(%s): Handshake finished in %u.%03u secs (",
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
1341 conn->name, handshake_msecs/1000, handshake_msecs%1000);
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
1342 director_connection_append_stats(conn, str);
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
1343 str_append_c(str, ')');
22252
8882a5cbe76d director: Use more accurate timestamps for handshake timeout logging
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22251
diff changeset
1344 if (handshake_msecs >= DIRECTOR_HANDSHAKE_WARN_SECS*1000)
18063
91c525000811 director: Always log a message when director handshake finishes.
Timo Sirainen <tss@iki.fi>
parents: 18062
diff changeset
1345 i_warning("%s", str_c(str));
91c525000811 director: Always log a message when director handshake finishes.
Timo Sirainen <tss@iki.fi>
parents: 18062
diff changeset
1346 else
91c525000811 director: Always log a message when director handshake finishes.
Timo Sirainen <tss@iki.fi>
parents: 18062
diff changeset
1347 i_info("%s", str_c(str));
11579
61708c33154d director: Debug message improvements.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
1348
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1349 /* the host is up now, make sure we can connect to it immediately
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1350 if needed */
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
1351 conn->host->last_network_failure = 0;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1352
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1353 conn->handshake_received = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1354 if (conn->in) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1355 /* handshaked to left side. tell it we've received the
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1356 whole handshake. */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1357 director_connection_send(conn, "DONE\n");
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1358
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1359 /* tell the "right" director about the "left" one */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1360 director_update_send(dir, director_connection_get_host(conn),
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1361 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: 22640
diff changeset
1362 conn->host->ip_str,
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1363 conn->host->port));
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1364 /* this is our "left" side. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1365 return director_connection_assign_left(conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1366 } else {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1367 /* handshaked to "right" side. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1368 return director_connection_assign_right(conn);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1369 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1370 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1371
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1372 static int
18065
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1373 director_handshake_cmd_options(struct director_connection *conn,
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1374 const char *const *args)
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1375 {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1376 bool consistent_hashing = FALSE;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1377 unsigned int i;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1378
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1379 for (i = 0; args[i] != NULL; i++) {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1380 if (strcmp(args[i], DIRECTOR_OPT_CONSISTENT_HASHING) == 0)
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1381 consistent_hashing = TRUE;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1382 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1383 if (consistent_hashing != conn->dir->set->director_consistent_hashing) {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1384 i_error("director(%s): director_consistent_hashing settings differ between directors",
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1385 conn->name);
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1386 return -1;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1387 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1388 return 1;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1389 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1390
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1391 static int
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1392 director_connection_handle_handshake(struct director_connection *conn,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1393 const char *cmd, const char *const *args)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1394 {
19036
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1395 unsigned int major_version;
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1396
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1397 /* both incoming and outgoing connections get VERSION and ME */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1398 if (strcmp(cmd, "VERSION") == 0 && str_array_length(args) >= 3) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1399 if (strcmp(args[0], DIRECTOR_VERSION_NAME) != 0) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1400 i_error("director(%s): Wrong protocol in socket "
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1401 "(%s vs %s)",
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1402 conn->name, args[0], DIRECTOR_VERSION_NAME);
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1403 return -1;
19036
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1404 } else if (str_to_uint(args[1], &major_version) < 0 ||
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1405 str_to_uint(args[2], &conn->minor_version) < 0) {
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1406 i_error("director(%s): Invalid protocol version: "
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1407 "%s.%s", conn->name, args[1], args[2]);
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1408 return -1;
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1409 } else if (major_version != DIRECTOR_VERSION_MAJOR) {
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1410 i_error("director(%s): Incompatible protocol version: "
19036
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1411 "%u vs %u", conn->name, major_version,
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1412 DIRECTOR_VERSION_MAJOR);
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1413 return -1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1414 }
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1415 if (conn->minor_version < DIRECTOR_VERSION_TAGS_V2 &&
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1416 mail_hosts_have_tags(conn->dir->mail_hosts)) {
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1417 i_error("director(%s): Director version supports incompatible tags", conn->name);
20295
4f4e9b238ddc director: Fixed error handling when directors support incompatible tags
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20286
diff changeset
1418 return -1;
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1419 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1420 conn->version_received = TRUE;
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1421 director_finish_sending_handshake(conn);
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1422 return 1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1423 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1424 if (!conn->version_received) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1425 director_cmd_error(conn, "Incompatible protocol");
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1426 return -1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1427 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1428
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1429 if (strcmp(cmd, "ME") == 0)
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1430 return director_cmd_me(conn, args) ? 1 : -1;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1431 if (!conn->me_received) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1432 director_cmd_error(conn, "Expecting ME command first");
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1433 return -1;
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
1434 }
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1435
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1436 /* incoming connections get a HOST list */
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1437 if (conn->handshake_sending_hosts) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1438 if (strcmp(cmd, "HOST") == 0)
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1439 return director_cmd_host_handshake(conn, args) ? 1 : -1;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1440 if (strcmp(cmd, "HOST-HAND-END") == 0) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1441 conn->ignore_host_events = FALSE;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1442 conn->handshake_sending_hosts = FALSE;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1443 return 1;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1444 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1445 director_cmd_error(conn, "Unexpected command during host list");
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1446 return -1;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1447 }
18065
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1448 if (strcmp(cmd, "OPTIONS") == 0)
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1449 return director_handshake_cmd_options(conn, args);
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1450 if (strcmp(cmd, "HOST-HAND-START") == 0) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1451 if (!conn->in) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1452 director_cmd_error(conn,
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1453 "Host list is only for incoming connections");
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1454 return -1;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1455 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1456 return director_cmd_host_hand_start(conn, args) ? 1 : -1;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1457 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1458
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1459 if (conn->in && strcmp(cmd, "USER") == 0 && CMD_IS_USER_HANDHAKE(args))
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1460 return director_handshake_cmd_user(conn, args) ? 1 : -1;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1461
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1462 /* both get DONE */
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1463 if (strcmp(cmd, "DONE") == 0)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1464 return director_handshake_cmd_done(conn) ? 1 : -1;
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1465 return 0;
11321
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
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1468 static bool
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1469 director_connection_sync_host(struct director_connection *conn,
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1470 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: 16621
diff changeset
1471 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
1472 unsigned int timestamp, unsigned int hosts_hash)
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1473 {
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1474 struct director *dir = conn->dir;
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1475
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1476 if (minor_version > DIRECTOR_VERSION_MINOR) {
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1477 /* we're not up to date */
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1478 minor_version = DIRECTOR_VERSION_MINOR;
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1479 }
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1480
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1481 if (host->self) {
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1482 if (dir->sync_seq != seq) {
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1483 /* stale SYNC event */
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1484 return FALSE;
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1485 }
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1486 /* sync_seq increases when we get disconnected, so we must be
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1487 successfully connected to both directions */
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1488 i_assert(dir->left != NULL && dir->right != NULL);
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1489
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
1490 if (hosts_hash != 0 &&
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
1491 hosts_hash != mail_hosts_hash(conn->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
1492 i_error("director(%s): Hosts unexpectedly changed during SYNC reply - resending"
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
1493 "(seq=%u, old hosts_hash=%u, new hosts_hash=%u)",
8f225e43e6e3 director: Detect if directors' hosts have become desynced by sending hosts_hash in SYNC parameter.
Timo Sirainen <tss@iki.fi>
parents: 19292
diff changeset
1494 conn->name, seq, hosts_hash,
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
1495 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
1496 (void)director_resend_sync(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
1497 return FALSE;
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
1498 }
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
1499
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1500 dir->ring_min_version = minor_version;
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1501 if (!dir->ring_handshaked) {
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1502 /* the ring is handshaked */
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1503 director_set_ring_handshaked(dir);
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1504 } else if (dir->ring_synced) {
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1505 /* duplicate SYNC (which was sent just in case the
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1506 previous one got lost) */
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1507 } else {
19292
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1508 dir_debug("Ring is synced (%s sent seq=%u, hosts_hash=%u)",
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1509 conn->name, seq,
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1510 mail_hosts_hash(dir->mail_hosts));
22629
0281041d5067 director: Track show long the last ring sync took.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22628
diff changeset
1511 int sync_msecs =
0281041d5067 director: Track show long the last ring sync took.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22628
diff changeset
1512 timeval_diff_msecs(&ioloop_timeval, &dir->last_sync_start_time);
0281041d5067 director: Track show long the last ring sync took.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22628
diff changeset
1513 if (sync_msecs >= 0)
0281041d5067 director: Track show long the last ring sync took.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22628
diff changeset
1514 dir->last_sync_msecs = sync_msecs;
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1515 director_set_ring_synced(dir);
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1516 }
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1517 } else {
16790
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1518 if (seq < host->last_sync_seq &&
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1519 timestamp < host->last_sync_timestamp +
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1520 DIRECTOR_SYNC_STALE_TIMESTAMP_RESET_SECS) {
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1521 /* stale SYNC event */
16787
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1522 dir_debug("Ignore stale SYNC event for %s "
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1523 "(seq %u < %u, timestamp=%u)",
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1524 host->name, seq, host->last_sync_seq,
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1525 timestamp);
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1526 return FALSE;
16790
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1527 } else if (seq < host->last_sync_seq) {
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1528 i_warning("Last SYNC seq for %s appears to be stale, reseting "
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1529 "(seq=%u, timestamp=%u -> seq=%u, timestamp=%u)",
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1530 host->name, host->last_sync_seq,
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1531 host->last_sync_timestamp, seq, timestamp);
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1532 host->last_sync_seq = seq;
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1533 host->last_sync_timestamp = timestamp;
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1534 host->last_sync_seq_counter = 1;
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1535 } else if (seq > host->last_sync_seq ||
16695
f7a37b169f4a director: Previous change caused legitimate SYNC resends to be ignored.
Timo Sirainen <tss@iki.fi>
parents: 16678
diff changeset
1536 timestamp > host->last_sync_timestamp) {
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1537 host->last_sync_seq = seq;
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1538 host->last_sync_timestamp = timestamp;
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1539 host->last_sync_seq_counter = 1;
16790
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1540 dir_debug("Update SYNC for %s "
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1541 "(seq=%u, timestamp=%u -> seq=%u, timestamp=%u)",
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1542 host->name, host->last_sync_seq,
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1543 host->last_sync_timestamp, seq, timestamp);
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1544 } else if (++host->last_sync_seq_counter >
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1545 DIRECTOR_MAX_SYNC_SEQ_DUPLICATES) {
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1546 /* we've received this too many times already */
16786
17389ac3cb66 director: Added more debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16699
diff changeset
1547 dir_debug("Ignore duplicate #%u SYNC event for %s "
17389ac3cb66 director: Added more debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16699
diff changeset
1548 "(seq=%u, timestamp %u <= %u)",
16787
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1549 host->last_sync_seq_counter, host->name, seq,
16786
17389ac3cb66 director: Added more debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16699
diff changeset
1550 timestamp, host->last_sync_timestamp);
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1551 return FALSE;
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1552 }
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1553
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
1554 if (hosts_hash != 0 &&
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
1555 hosts_hash != mail_hosts_hash(conn->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
1556 if (host->desynced_hosts_hash != hosts_hash) {
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
1557 dir_debug("Ignore director %s stale SYNC request whose hosts don't match us "
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
1558 "(seq=%u, remote hosts_hash=%u, my hosts_hash=%u)",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
1559 host->ip_str, seq, hosts_hash,
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
1560 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
1561 host->desynced_hosts_hash = hosts_hash;
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
1562 return FALSE;
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
1563 }
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
1564 /* we'll get here only if we received a SYNC twice
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
1565 with the same wrong hosts_hash. FIXME: this gets
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
1566 triggered unnecessarily sometimes if hosts are
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
1567 changing rapidly. */
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
1568 i_error("director(%s): Director %s SYNC request hosts don't match us - resending 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
1569 "(seq=%u, remote hosts_hash=%u, my hosts_hash=%u)",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
1570 conn->name, host->ip_str, 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
1571 hosts_hash, 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
1572 director_resend_hosts(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
1573 return FALSE;
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
1574 }
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
1575 host->desynced_hosts_hash = 0;
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1576 if (dir->right != NULL) {
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1577 /* forward it to the connection on right */
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1578 director_sync_send(dir, host, seq, 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
1579 timestamp, hosts_hash);
20971
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
1580 } else {
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
1581 dir_debug("director(%s): We have no right connection - "
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
1582 "delay replying to SYNC until finished", conn->name);
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
1583 host->delayed_sync_seq = seq;
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
1584 host->delayed_sync_minor_version = minor_version;
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
1585 host->delayed_sync_timestamp = timestamp;
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
1586 host->delayed_sync_hosts_hash = hosts_hash;
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1587 }
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1588 }
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1589 return TRUE;
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1590 }
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1591
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1592 static bool director_connection_sync(struct director_connection *conn,
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1593 const char *const *args)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1594 {
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
1595 struct director *dir = conn->dir;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1596 struct director_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1597 struct ip_addr ip;
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
1598 in_port_t port;
19289
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1599 unsigned int arg_count, seq, minor_version = 0, timestamp = ioloop_time;
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
1600 unsigned int hosts_hash = 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1601
19289
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1602 arg_count = str_array_length(args);
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1603 if (arg_count < 3 ||
12208
a224997afefd director: Properly detect invalid command parameters in director<->director connections.
Timo Sirainen <tss@iki.fi>
parents: 12065
diff changeset
1604 !director_args_parse_ip_port(conn, args, &ip, &port) ||
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1605 str_to_uint(args[2], &seq) < 0) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1606 director_cmd_error(conn, "Invalid parameters");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1607 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1608 }
19289
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1609 if (arg_count >= 4 && str_to_uint(args[3], &minor_version) < 0) {
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1610 director_cmd_error(conn, "Invalid parameters");
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1611 return FALSE;
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1612 }
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1613 if (arg_count >= 5 && str_to_uint(args[4], &timestamp) < 0) {
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1614 director_cmd_error(conn, "Invalid parameters");
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1615 return FALSE;
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1616 }
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
1617 if (arg_count >= 6 && str_to_uint(args[5], &hosts_hash) < 0) {
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
1618 director_cmd_error(conn, "Invalid parameters");
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
1619 return FALSE;
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
1620 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1621
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1622 /* find the originating director. if we don't see it, it was already
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1623 removed and we can ignore this sync. */
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
1624 host = director_host_lookup(dir, &ip, port);
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1625 if (host != NULL) {
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1626 if (!director_connection_sync_host(conn, host, 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
1627 minor_version, timestamp,
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
1628 hosts_hash))
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1629 return TRUE;
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1630 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1631
19954
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19953
diff changeset
1632 /* If directors got disconnected while we were waiting a SYNC reply,
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19953
diff changeset
1633 it might have gotten lost. If we've received a DIRECTOR update since
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19953
diff changeset
1634 the last time we sent a SYNC, retry sending it here to make sure
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19953
diff changeset
1635 it doesn't get stuck. We don't want to do this too eagerly because
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19953
diff changeset
1636 it may trigger desynced_hosts_hash != hosts_hash mismatch, which
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19953
diff changeset
1637 causes unnecessary error logging and hosts-resending. */
16622
a6736e42301e director: Avoid infinite SYNC loops if the originating director goes away for a long time.
Timo Sirainen <tss@iki.fi>
parents: 16621
diff changeset
1638 if ((host == NULL || !host->self) &&
19954
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19953
diff changeset
1639 dir->last_sync_sent_ring_change_counter != dir->ring_change_counter &&
16678
17e43eda8f22 Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 16622
diff changeset
1640 (time_t)dir->self_host->last_sync_timestamp != ioloop_time)
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14681
diff changeset
1641 (void)director_resend_sync(dir);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1642 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1643 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1644
22567
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1645 static void director_disconnect_timeout(struct director_connection *conn)
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1646 {
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1647 director_connection_deinit(&conn, "CONNECT requested");
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1648 }
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1649
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1650 static void
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1651 director_reconnect_after_wrong_connect_timeout(struct director_connection *conn)
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1652 {
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1653 struct director *dir = conn->dir;
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1654
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1655 director_connection_deinit(&conn, "Wrong CONNECT requested");
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1656 if (dir->right == NULL)
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1657 director_connect(dir, "Reconnecting after wrong CONNECT request");
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1658 }
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1659
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1660 static void
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1661 director_reconnect_after_wrong_connect(struct director_connection *conn)
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1662 {
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1663 if (conn->to_disconnect != NULL)
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1664 return;
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1665 conn->to_disconnect =
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1666 timeout_add_short(DIRECTOR_RECONNECT_AFTER_WRONG_CONNECT_MSECS,
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1667 director_reconnect_after_wrong_connect_timeout, conn);
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1668 }
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1669
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1670 static bool director_cmd_connect(struct director_connection *conn,
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1671 const char *const *args)
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1672 {
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1673 struct director *dir = conn->dir;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1674 struct director_host *host;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1675 struct ip_addr ip;
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
1676 in_port_t port;
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
1677 const char *right_state;
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1678
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1679 if (str_array_length(args) != 2 ||
12208
a224997afefd director: Properly detect invalid command parameters in director<->director connections.
Timo Sirainen <tss@iki.fi>
parents: 12065
diff changeset
1680 !director_args_parse_ip_port(conn, args, &ip, &port)) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1681 director_cmd_error(conn, "Invalid parameters");
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1682 return FALSE;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1683 }
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1684
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1685 host = director_host_get(conn->dir, &ip, port);
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1686
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1687 /* remote suggests us to connect elsewhere */
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1688 if (dir->right != NULL &&
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1689 director_host_cmp_to_self(host, dir->right->host,
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1690 dir->self_host) <= 0) {
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1691 /* the old connection is the correct one */
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
1692 dir_debug("Ignoring CONNECT request to %s (current right is %s)",
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
1693 host->name, dir->right->name);
22567
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1694 director_reconnect_after_wrong_connect(conn);
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1695 return TRUE;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1696 }
22568
c50f46578b86 director: Ignore CONNECT requests to hosts that have been removed already
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22567
diff changeset
1697 if (host->removed) {
c50f46578b86 director: Ignore CONNECT requests to hosts that have been removed already
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22567
diff changeset
1698 dir_debug("Ignoring CONNECT request to %s (director is removed)",
c50f46578b86 director: Ignore CONNECT requests to hosts that have been removed already
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22567
diff changeset
1699 host->name);
c50f46578b86 director: Ignore CONNECT requests to hosts that have been removed already
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22567
diff changeset
1700 director_reconnect_after_wrong_connect(conn);
c50f46578b86 director: Ignore CONNECT requests to hosts that have been removed already
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22567
diff changeset
1701 return TRUE;
c50f46578b86 director: Ignore CONNECT requests to hosts that have been removed already
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22567
diff changeset
1702 }
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1703
19973
0b5aeb95924a director: Avoid a potential assert-crash after removing a director from ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
1704 /* reset failure timestamp so we'll actually try to connect there. */
0b5aeb95924a director: Avoid a potential assert-crash after removing a director from ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
1705 host->last_network_failure = 0;
0b5aeb95924a director: Avoid a potential assert-crash after removing a director from ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
1706 /* reset removed-flag, so we don't crash */
0b5aeb95924a director: Avoid a potential assert-crash after removing a director from ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
1707 host->removed = FALSE;
0b5aeb95924a director: Avoid a potential assert-crash after removing a director from ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
1708
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
1709 if (dir->right == NULL) {
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
1710 right_state = "initializing right";
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
1711 } else {
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
1712 right_state = t_strdup_printf("replacing current right %s",
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
1713 dir->right->name);
22567
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1714 /* disconnect from right side immediately - it's not accepting
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1715 any further commands from us. */
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1716 if (conn->dir->right != conn)
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1717 director_connection_deinit(&conn->dir->right, "CONNECT requested");
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1718 else if (conn->to_disconnect == NULL) {
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1719 conn->to_disconnect =
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1720 timeout_add_short(0, director_disconnect_timeout, conn);
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1721 }
11579
61708c33154d director: Debug message improvements.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
1722 }
61708c33154d director: Debug message improvements.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
1723
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1724 /* connect here */
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
1725 (void)director_connect_host(dir, host, t_strdup_printf(
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
1726 "Received CONNECT request from %s - %s",
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
1727 conn->name, right_state));
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1728 return TRUE;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1729 }
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1730
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1731 static void director_disconnect_wrong_lefts(struct director *dir)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1732 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1733 struct director_connection *const *connp, *conn;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1734
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1735 array_foreach(&dir->connections, connp) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1736 conn = *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1737
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1738 if (conn->in && conn != dir->left && conn->me_received &&
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
1739 conn->to_disconnect == NULL &&
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1740 director_host_cmp_to_self(dir->left->host, conn->host,
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1741 dir->self_host) < 0)
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1742 director_connection_send_connect(conn, dir->left->host);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1743 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1744 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1745
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1746 static bool director_cmd_pong(struct director_connection *conn)
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1747 {
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1748 if (!conn->ping_waiting)
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1749 return TRUE;
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
1750 conn->ping_waiting = FALSE;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1751 timeout_remove(&conn->to_pong);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1752
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
1753 int ping_msecs = timeval_diff_msecs(&ioloop_timeval, &conn->ping_sent_time);
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
1754 if (ping_msecs >= 0)
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
1755 conn->last_ping_msecs = ping_msecs;
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
1756
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1757 if (conn->verifying_left) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1758 conn->verifying_left = FALSE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1759 if (conn == conn->dir->left) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1760 /* our left side is functional. tell all the wrong
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1761 incoming connections to connect to it instead. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1762 director_disconnect_wrong_lefts(conn->dir);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1763 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1764 }
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1765
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
1766 director_connection_set_ping_timeout(conn);
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1767 return TRUE;
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1768 }
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1769
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1770 static bool
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1771 director_connection_handle_cmd(struct director_connection *conn,
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1772 const char *cmd, const char *const *args)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1773 {
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1774 int ret;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1775
11327
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
1776 if (!conn->handshake_received) {
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1777 ret = director_connection_handle_handshake(conn, cmd, args);
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1778 if (ret > 0)
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1779 return TRUE;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1780 if (ret < 0) {
11327
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
1781 /* invalid commands during handshake,
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
1782 we probably don't want to reconnect here */
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
1783 return FALSE;
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
1784 }
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1785 /* allow also other commands during handshake */
11327
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
1786 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1787
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1788 if (strcmp(cmd, "PING") == 0) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1789 director_connection_send(conn, "PONG\n");
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1790 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1791 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1792 if (strcmp(cmd, "PONG") == 0)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1793 return director_cmd_pong(conn);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1794 if (strcmp(cmd, "USER") == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1795 return director_cmd_user(conn, args);
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1796 if (strcmp(cmd, "USER-WEAK") == 0)
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1797 return director_cmd_user_weak(conn, args);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1798 if (strcmp(cmd, "HOST") == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1799 return director_cmd_host(conn, args);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1800 if (strcmp(cmd, "HOST-REMOVE") == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1801 return director_cmd_host_remove(conn, args);
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1802 if (strcmp(cmd, "HOST-FLUSH") == 0)
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1803 return director_cmd_host_flush(conn, args);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1804 if (strcmp(cmd, "USER-MOVE") == 0)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1805 return director_cmd_user_move(conn, args);
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1806 if (strcmp(cmd, "USER-KICK") == 0)
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1807 return director_cmd_user_kick(conn, args);
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1808 if (strcmp(cmd, "USER-KICK-ALT") == 0)
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1809 return director_cmd_user_kick_alt(conn, args);
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
1810 if (strcmp(cmd, "USER-KICK-HASH") == 0)
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
1811 return director_cmd_user_kick_hash(conn, args);
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1812 if (strcmp(cmd, "USER-KILLED") == 0)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1813 return director_cmd_user_killed(conn, args);
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1814 if (strcmp(cmd, "USER-KILLED-EVERYWHERE") == 0)
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1815 return director_cmd_user_killed_everywhere(conn, args);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1816 if (strcmp(cmd, "DIRECTOR") == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1817 return director_cmd_director(conn, args);
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
1818 if (strcmp(cmd, "DIRECTOR-REMOVE") == 0)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
1819 return director_cmd_director_remove(conn, args);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1820 if (strcmp(cmd, "SYNC") == 0)
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1821 return director_connection_sync(conn, args);
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1822 if (strcmp(cmd, "CONNECT") == 0)
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1823 return director_cmd_connect(conn, args);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1824 if (strcmp(cmd, "QUIT") == 0) {
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1825 i_warning("Director %s disconnected us with reason: %s",
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1826 conn->name, t_strarray_join(args, " "));
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1827 return FALSE;
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1828 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1829
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1830 director_cmd_error(conn, "Unknown command %s", cmd);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1831 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1832 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1833
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1834 static bool
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1835 director_connection_handle_line(struct director_connection *conn,
22640
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1836 char *line)
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1837 {
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1838 const char *cmd, *const *args;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1839 bool ret;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1840
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
1841 dir_debug("input: %s: %s", conn->name, line);
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
1842
22640
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1843 args = t_strsplit_tabescaped_inplace(line);
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1844 cmd = args[0];
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1845 if (cmd == NULL) {
14479
293ada796ae6 director: Fixed protocol error detection/handling.
Timo Sirainen <tss@iki.fi>
parents: 14478
diff changeset
1846 director_cmd_error(conn, "Received empty line");
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1847 return FALSE;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1848 }
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1849
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1850 conn->cur_cmd = cmd;
22640
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1851 conn->cur_args = args;
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1852 ret = director_connection_handle_cmd(conn, cmd, args+1);
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1853 conn->cur_cmd = NULL;
22640
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1854 conn->cur_args = NULL;
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1855 return ret;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1856 }
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1857
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1858 static void
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1859 director_connection_log_disconnect(struct director_connection *conn, int err,
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1860 const char *errstr)
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1861 {
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1862 string_t *str = t_str_new(128);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1863
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1864 i_assert(conn->connected);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1865
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1866 if (conn->connect_request_to != NULL) {
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1867 i_warning("Director %s tried to connect to us, "
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1868 "should use %s instead",
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1869 conn->name, conn->connect_request_to->name);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1870 return;
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1871 }
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1872
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1873 str_printfa(str, "Director %s disconnected: ", conn->name);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1874 str_append(str, "Connection closed");
16618
0ad8da149774 director: Log director disconnection errno correctly.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
1875 if (err != 0 && err != EPIPE) {
0ad8da149774 director: Log director disconnection errno correctly.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
1876 errno = err;
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1877 if (errstr[0] == '\0')
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1878 str_printfa(str, ": %m");
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1879 else
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1880 str_printfa(str, ": %s", errstr);
16618
0ad8da149774 director: Log director disconnection errno correctly.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
1881 }
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1882
22255
a841e797bac2 director: Fix whitespace position in some log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22254
diff changeset
1883 str_append(str, " (");
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
1884 director_connection_append_stats(conn, str);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1885
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1886 if (!conn->me_received)
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1887 str_append(str, ", handshake ME not received");
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1888 else if (!conn->handshake_received)
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1889 str_append(str, ", handshake DONE not received");
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
1890 str_append_c(str, ')');
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1891 i_error("%s", str_c(str));
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1892 }
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1893
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1894 static void director_connection_input(struct director_connection *conn)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1895 {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1896 struct director *dir = conn->dir;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1897 char *line;
18664
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
1898 uoff_t prev_offset;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1899 bool ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1900
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1901 switch (i_stream_read(conn->input)) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1902 case 0:
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1903 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1904 case -1:
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1905 /* disconnected */
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1906 director_connection_log_disconnect(conn, conn->input->stream_errno,
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1907 i_stream_get_error(conn->input));
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1908 director_connection_disconnected(&conn, i_stream_get_error(conn->input));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1909 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1910 case -2:
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1911 /* buffer full */
14479
293ada796ae6 director: Fixed protocol error detection/handling.
Timo Sirainen <tss@iki.fi>
parents: 14478
diff changeset
1912 director_cmd_error(conn, "Director sent us more than %d bytes",
293ada796ae6 director: Fixed protocol error detection/handling.
Timo Sirainen <tss@iki.fi>
parents: 14478
diff changeset
1913 MAX_INBUF_SIZE);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1914 director_connection_reconnect(&conn, "Too long input line");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1915 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1916 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1917
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
1918 if (conn->to_disconnect != NULL) {
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
1919 /* just read everything the remote sends, and wait for it
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
1920 to disconnect. we mainly just want the remote to read the
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
1921 CONNECT we sent it. */
14683
9646f80ac3e9 Added i_stream_get_data_size(). Used it where possible.
Timo Sirainen <tss@iki.fi>
parents: 14682
diff changeset
1922 i_stream_skip(conn->input, i_stream_get_data_size(conn->input));
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
1923 return;
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
1924 }
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
1925 conn->last_input = ioloop_timeval;
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
1926 conn->refcount++;
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
1927
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1928 director_sync_freeze(dir);
18664
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
1929 prev_offset = conn->input->v_offset;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1930 while ((line = i_stream_next_line(conn->input)) != NULL) {
18664
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
1931 dir->ring_traffic_input += conn->input->v_offset - prev_offset;
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
1932 prev_offset = conn->input->v_offset;
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
1933
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1934 T_BEGIN {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1935 ret = director_connection_handle_line(conn, line);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1936 } T_END;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1937
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1938 if (!ret) {
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
1939 if (!director_connection_unref(conn))
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
1940 break;
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1941 director_connection_reconnect(&conn, t_strdup_printf(
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1942 "Invalid input: %s", line));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1943 break;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1944 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1945 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1946 director_sync_thaw(dir);
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
1947 if (conn != NULL) {
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
1948 if (director_connection_unref(conn))
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
1949 timeout_reset(conn->to_ping);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
1950 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1951 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1952
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1953 static void director_connection_send_directors(struct director_connection *conn)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1954 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1955 struct director_host *const *hostp;
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1956 string_t *str = t_str_new(64);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1957
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1958 array_foreach(&conn->dir->dir_hosts, hostp) {
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
1959 if ((*hostp)->removed)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
1960 continue;
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1961
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1962 str_truncate(str, 0);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1963 str_printfa(str, "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: 22640
diff changeset
1964 (*hostp)->ip_str, (*hostp)->port);
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1965 director_connection_send(conn, str_c(str));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1966 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1967 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1968
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1969 static void
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1970 director_connection_send_hosts(struct director_connection *conn)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1971 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1972 struct mail_host *const *hostp;
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1973 bool send_updowns;
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1974 string_t *str = t_str_new(128);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1975
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1976 i_assert(conn->version_received);
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1977
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1978 send_updowns = conn->minor_version >= DIRECTOR_VERSION_UPDOWN;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1979
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1980 str_printfa(str, "HOST-HAND-START\t%u\n", conn->dir->ring_handshaked);
11352
19336bddada2 director: Code cleanup - keep mail hosts in a struct rather than in static variables.
Timo Sirainen <tss@iki.fi>
parents: 11350
diff changeset
1981 array_foreach(mail_hosts_get(conn->dir->mail_hosts), hostp) {
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1982 struct mail_host *host = *hostp;
19408
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
1983 const char *host_tag = mail_host_get_tag(host);
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1984
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1985 str_printfa(str, "HOST\t%s\t%u",
22643
6e235143e177 director: Use *_host.ip_str to avoid net_ip2addr() calls
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22640
diff changeset
1986 host->ip_str, host->vhost_count);
19408
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
1987 if (host_tag[0] != '\0' || send_updowns) {
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1988 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
1989 str_append_tabescaped(str, host_tag);
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1990 }
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1991 if (send_updowns) {
19310
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1992 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: 18708
diff changeset
1993 (long)host->last_updown_change);
19310
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1994 if (host->hostname != NULL)
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1995 str_append_tabescaped(str, host->hostname);
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1996 }
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1997 str_append_c(str, '\n');
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1998 director_connection_send(conn, str_c(str));
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1999 str_truncate(str, 0);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2000 }
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
2001 str_printfa(str, "HOST-HAND-END\t%u\n", conn->dir->ring_handshaked);
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2002 director_connection_send(conn, str_c(str));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2003 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2004
18065
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2005 static int director_connection_send_done(struct director_connection *conn)
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2006 {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2007 i_assert(conn->version_received);
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2008
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2009 if (!conn->dir->set->director_consistent_hashing)
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2010 ;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2011 else if (conn->minor_version >= DIRECTOR_VERSION_OPTIONS) {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2012 director_connection_send(conn,
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2013 "OPTIONS\t"DIRECTOR_OPT_CONSISTENT_HASHING"\n");
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2014 } else {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2015 i_error("director(%s): Director version is too old for supporting director_consistent_hashing=yes",
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2016 conn->name);
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2017 return -1;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2018 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2019 director_connection_send(conn, "DONE\n");
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2020 return 0;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2021 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2022
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2023 static int director_connection_send_users(struct director_connection *conn)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2024 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2025 struct user *user;
22646
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2026 string_t *str = t_str_new(128);
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2027 char dec_buf[MAX_INT_STRLEN];
22648
6bd018a94a57 director: Don't block too long when sending users during director handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22646
diff changeset
2028 unsigned int sent_count = 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2029 int ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2030
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2031 i_assert(conn->version_received);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2032
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
2033 while ((user = director_iterate_users_next(conn->user_iter)) != NULL) {
22646
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2034 str_truncate(str, 0);
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2035 str_append(str, "USER\t");
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2036 str_append(str, dec2str_buf(dec_buf, user->username_hash));
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2037 str_append_c(str, '\t');
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2038 str_append(str, user->host->ip_str);
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2039 str_append_c(str, '\t');
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2040 str_append(str, dec2str_buf(dec_buf, user->timestamp));
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2041 if (user->weak)
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2042 str_append(str, "\tw");
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2043 str_append_c(str, '\n');
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2044 director_connection_send(conn, str_c(str));
22648
6bd018a94a57 director: Don't block too long when sending users during director handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22646
diff changeset
2045 if (++sent_count >= DIRECTOR_HANDSHAKE_MAX_USERS_SENT_PER_FLUSH) {
6bd018a94a57 director: Don't block too long when sending users during director handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22646
diff changeset
2046 /* Don't send too much at once to avoid hangs */
6bd018a94a57 director: Don't block too long when sending users during director handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22646
diff changeset
2047 timeout_reset(conn->to_ping);
6bd018a94a57 director: Don't block too long when sending users during director handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22646
diff changeset
2048 return 0;
6bd018a94a57 director: Don't block too long when sending users during director handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22646
diff changeset
2049 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2050
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2051 if (o_stream_get_buffer_used_size(conn->output) >= OUTBUF_FLUSH_THRESHOLD) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2052 if ((ret = o_stream_flush(conn->output)) <= 0) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2053 /* continue later */
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2054 timeout_reset(conn->to_ping);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2055 return ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2056 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2057 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2058 }
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
2059 director_iterate_users_deinit(&conn->user_iter);
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2060 if (director_connection_send_done(conn) < 0)
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2061 return -1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2062
16621
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
2063 if (conn->users_unsorted && conn->handshake_received) {
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
2064 /* we received remote's list of users before sending ours */
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
2065 conn->users_unsorted = FALSE;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21077
diff changeset
2066 mail_hosts_sort_users(conn->dir->mail_hosts);
16621
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
2067 }
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
2068
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2069 ret = o_stream_flush(conn->output);
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2070 timeout_reset(conn->to_ping);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2071 return ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2072 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2073
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2074 static int director_connection_output(struct director_connection *conn)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2075 {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2076 int ret;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2077
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2078 conn->last_output = ioloop_timeval;
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2079 if (conn->user_iter != NULL) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2080 /* still handshaking USER list */
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2081 o_stream_cork(conn->output);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2082 ret = director_connection_send_users(conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2083 o_stream_uncork(conn->output);
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
2084 if (ret < 0) {
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
2085 director_connection_disconnected(&conn,
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
2086 o_stream_get_error(conn->output));
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
2087 } else {
14480
d9f33d78fa3d director: Make sure handshaking doesn't get stuck sending USERs.
Timo Sirainen <tss@iki.fi>
parents: 14479
diff changeset
2088 o_stream_set_flush_pending(conn->output, TRUE);
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
2089 }
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2090 return ret;
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2091 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2092 return o_stream_flush(conn->output);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2093 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2094
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2095 static struct director_connection *
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2096 director_connection_init_common(struct director *dir, int fd)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2097 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2098 struct director_connection *conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2099
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2100 conn = i_new(struct director_connection, 1);
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2101 conn->refcount = 1;
22252
8882a5cbe76d director: Use more accurate timestamps for handshake timeout logging
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22251
diff changeset
2102 conn->created = ioloop_timeval;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2103 conn->fd = fd;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2104 conn->dir = dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2105 conn->input = i_stream_create_fd(conn->fd, MAX_INBUF_SIZE, FALSE);
22623
f733d647ff82 director: Add director_output_buffer_size setting
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22570
diff changeset
2106 conn->output = o_stream_create_fd(conn->fd, dir->set->director_output_buffer_size, FALSE);
14681
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14674
diff changeset
2107 o_stream_set_no_error_handling(conn->output, TRUE);
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2108 array_append(&dir->connections, &conn, 1);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2109 return conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2110 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2111
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2112 static void director_connection_send_handshake(struct director_connection *conn)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2113 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2114 director_connection_send(conn, t_strdup_printf(
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2115 "VERSION\t"DIRECTOR_VERSION_NAME"\t%u\t%u\n"
19294
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
2116 "ME\t%s\t%u\t%lld\n",
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2117 DIRECTOR_VERSION_MAJOR, DIRECTOR_VERSION_MINOR,
19294
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
2118 net_ip2addr(&conn->dir->self_ip), conn->dir->self_port,
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
2119 (long long)time(NULL)));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2120 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2121
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2122 static void director_connection_set_connected(struct director_connection *conn)
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2123 {
22651
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2124 struct rusage usage;
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2125
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2126 conn->connected = TRUE;
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2127 conn->connected_time = ioloop_timeval;
22651
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2128
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2129 if (getrusage(RUSAGE_SELF, &usage) == 0) {
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2130 conn->connected_user_cpu_set = TRUE;
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2131 conn->connected_user_cpu = usage.ru_utime;
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2132 }
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2133 }
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2134
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2135 struct director_connection *
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2136 director_connection_init_in(struct director *dir, int fd,
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2137 const struct ip_addr *ip)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2138 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2139 struct director_connection *conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2140
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2141 conn = director_connection_init_common(dir, fd);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2142 conn->in = TRUE;
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2143 director_connection_set_connected(conn);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2144 conn->name = i_strdup_printf("%s/in", net_ip2addr(ip));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2145 conn->io = io_add(conn->fd, IO_READ, director_connection_input, conn);
22250
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
2146 conn->to_ping = timeout_add(DIRECTOR_CONNECTION_ME_TIMEOUT_MSECS,
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
2147 director_connection_init_timeout, conn);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2148
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
2149 i_info("Incoming connection from director %s", conn->name);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2150 director_connection_send_handshake(conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2151 return conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2152 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2153
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2154 static void director_connection_connected(struct director_connection *conn)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2155 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2156 int err;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2157
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2158 if ((err = net_geterror(conn->fd)) != 0) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2159 i_error("director(%s): connect() failed: %s", conn->name,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2160 strerror(err));
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
2161 director_connection_disconnected(&conn, strerror(err));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2162 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2163 }
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2164 director_connection_set_connected(conn);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2165 o_stream_set_flush_callback(conn->output,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2166 director_connection_output, conn);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2167
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2168 io_remove(&conn->io);
14484
25ca6b6d754a director: Adding 25c941423e42 patch yet again, now it seems to work right.
Timo Sirainen <tss@iki.fi>
parents: 14483
diff changeset
2169 conn->io = io_add(conn->fd, IO_READ, director_connection_input, conn);
25ca6b6d754a director: Adding 25c941423e42 patch yet again, now it seems to work right.
Timo Sirainen <tss@iki.fi>
parents: 14483
diff changeset
2170
14477
ea5b949a623b director: Increased timeout for sending USER data in handshake.
Timo Sirainen <tss@iki.fi>
parents: 14476
diff changeset
2171 timeout_remove(&conn->to_ping);
22250
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
2172 conn->to_ping = timeout_add(DIRECTOR_CONNECTION_ME_TIMEOUT_MSECS,
14477
ea5b949a623b director: Increased timeout for sending USER data in handshake.
Timo Sirainen <tss@iki.fi>
parents: 14476
diff changeset
2173 director_connection_init_timeout, conn);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2174
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2175 o_stream_cork(conn->output);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2176 director_connection_send_handshake(conn);
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2177 director_connection_send_directors(conn);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2178 o_stream_uncork(conn->output);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2179 /* send the rest of the handshake after we've received the remote's
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2180 version number */
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2181 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2182
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2183 static void director_finish_sending_handshake(struct director_connection *conn)
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2184 {
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2185 if (
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2186 conn->in) {
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2187 /* only outgoing connections send hosts & users */
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2188 return;
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2189 }
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2190 o_stream_cork(conn->output);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2191 director_connection_send_hosts(conn);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2192
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2193 i_assert(conn->user_iter == NULL);
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
2194 conn->user_iter = director_iterate_users_init(conn->dir);
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
2195
14481
ce4e1bf7262d director: Another fix for stuck handshake.
Timo Sirainen <tss@iki.fi>
parents: 14480
diff changeset
2196 if (director_connection_send_users(conn) == 0)
ce4e1bf7262d director: Another fix for stuck handshake.
Timo Sirainen <tss@iki.fi>
parents: 14480
diff changeset
2197 o_stream_set_flush_pending(conn->output, TRUE);
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2198
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2199 o_stream_uncork(conn->output);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2200 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2201
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2202 struct director_connection *
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2203 director_connection_init_out(struct director *dir, int fd,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2204 struct director_host *host)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2205 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2206 struct director_connection *conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2207
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
2208 i_assert(!host->removed);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
2209
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2210 /* make sure we don't keep old sequence values across restarts */
16699
9531ec8afe8b director: Reset last-seen-sync-sequence after remote director restarts.
Timo Sirainen <tss@iki.fi>
parents: 16695
diff changeset
2211 director_host_restarted(host);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2212
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2213 conn = director_connection_init_common(dir, fd);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2214 conn->name = i_strdup_printf("%s/out", host->name);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2215 conn->host = host;
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
2216 director_host_ref(host);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2217 conn->io = io_add(conn->fd, IO_WRITE,
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2218 director_connection_connected, conn);
22250
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
2219 conn->to_ping = timeout_add(DIRECTOR_CONNECTION_CONNECT_TIMEOUT_MSECS,
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
2220 director_connection_init_timeout, conn);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2221 return conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2222 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2223
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2224 void director_connection_deinit(struct director_connection **_conn,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2225 const char *remote_reason)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2226 {
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2227 struct director_connection *const *conns, *conn = *_conn;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2228 struct director *dir = conn->dir;
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2229 unsigned int i, count;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2230
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2231 *_conn = NULL;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2232
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2233 i_assert(conn->fd != -1);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2234
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2235 if (conn->host != NULL) {
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2236 dir_debug("Disconnecting from %s: %s",
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2237 conn->host->name, remote_reason);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2238 }
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2239 if (*remote_reason != '\0' &&
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2240 conn->minor_version >= DIRECTOR_VERSION_QUIT) {
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2241 o_stream_send_str(conn->output, t_strdup_printf(
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2242 "QUIT\t%s\n", remote_reason));
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2243 }
12935
e9139f74c451 director: Improved debug/error logging.
Timo Sirainen <tss@iki.fi>
parents: 12934
diff changeset
2244
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2245 conns = array_get(&dir->connections, &count);
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2246 for (i = 0; i < count; i++) {
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2247 if (conns[i] == conn) {
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2248 array_delete(&dir->connections, i, 1);
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2249 break;
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2250 }
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2251 }
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2252 i_assert(i < count);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2253 if (dir->left == conn) {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2254 dir->left = NULL;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2255 /* if there is already another handshaked incoming connection,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2256 use it as the new "left" */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2257 director_assign_left(dir);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2258 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2259 if (dir->right == conn)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2260 dir->right = NULL;
11572
659bb1a26da4 director: Added initial testing framework and some debugging output.
Timo Sirainen <tss@iki.fi>
parents: 11571
diff changeset
2261
22669
4c0e2030200a director: Make sure users are sorted after unfinished handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22668
diff changeset
2262 if (conn->users_unsorted) {
4c0e2030200a director: Make sure users are sorted after unfinished handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22668
diff changeset
2263 /* Users were received, but handshake didn't finish.
4c0e2030200a director: Make sure users are sorted after unfinished handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22668
diff changeset
2264 Finish sorting so the users won't stay in wrong order. */
4c0e2030200a director: Make sure users are sorted after unfinished handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22668
diff changeset
2265 mail_hosts_sort_users(conn->dir->mail_hosts);
4c0e2030200a director: Make sure users are sorted after unfinished handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22668
diff changeset
2266 }
4c0e2030200a director: Make sure users are sorted after unfinished handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22668
diff changeset
2267
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2268 if (conn->connect_request_to != NULL) {
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2269 director_host_unref(conn->connect_request_to);
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2270 conn->connect_request_to = NULL;
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2271 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2272 if (conn->user_iter != NULL)
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
2273 director_iterate_users_deinit(&conn->user_iter);
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
2274 if (conn->to_disconnect != NULL)
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
2275 timeout_remove(&conn->to_disconnect);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2276 if (conn->to_pong != NULL)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2277 timeout_remove(&conn->to_pong);
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2278 timeout_remove(&conn->to_ping);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2279 if (conn->io != NULL)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2280 io_remove(&conn->io);
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2281 i_stream_close(conn->input);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2282 o_stream_close(conn->output);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2283 i_close_fd(&conn->fd);
11569
467ca06a7dbe director: Outgoing director connections shouldn't be counted as master clients.
Timo Sirainen <tss@iki.fi>
parents: 11373
diff changeset
2284
467ca06a7dbe director: Outgoing director connections shouldn't be counted as master clients.
Timo Sirainen <tss@iki.fi>
parents: 11373
diff changeset
2285 if (conn->in)
467ca06a7dbe director: Outgoing director connections shouldn't be counted as master clients.
Timo Sirainen <tss@iki.fi>
parents: 11373
diff changeset
2286 master_service_client_connection_destroyed(master_service);
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2287 director_connection_unref(conn);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2288
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2289 if (dir->left == NULL || dir->right == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2290 /* we aren't synced until we're again connected to a ring */
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2291 dir->sync_seq++;
13921
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13053
diff changeset
2292 director_set_ring_unsynced(dir);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2293 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2294 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2295
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2296 static bool director_connection_unref(struct director_connection *conn)
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2297 {
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2298 i_assert(conn->refcount > 0);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2299 if (--conn->refcount > 0)
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2300 return TRUE;
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2301
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2302 if (conn->host != NULL)
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2303 director_host_unref(conn->host);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2304 i_stream_unref(&conn->input);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2305 o_stream_unref(&conn->output);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2306 i_free(conn->name);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2307 i_free(conn);
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2308 return FALSE;
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2309 }
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2310
18858
8bde19f080ad director: explicitly mark _disconnect() helper static to match proto
Phil Carmody <phil@dovecot.fi>
parents: 18729
diff changeset
2311 static void director_connection_disconnected(struct director_connection **_conn,
8bde19f080ad director: explicitly mark _disconnect() helper static to match proto
Phil Carmody <phil@dovecot.fi>
parents: 18729
diff changeset
2312 const char *reason)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2313 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2314 struct director_connection *conn = *_conn;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2315 struct director *dir = conn->dir;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2316
22446
8bfe8a2fed69 director: Fix rapid reconnection on failed outgoing connections
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22311
diff changeset
2317 if ((conn->connected_time.tv_sec == 0 ||
8bfe8a2fed69 director: Fix rapid reconnection on failed outgoing connections
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22311
diff changeset
2318 conn->connected_time.tv_sec + DIRECTOR_SUCCESS_MIN_CONNECT_SECS > ioloop_time) &&
14570
40f958c7643b director: Don't crash with quickly disconnecting incoming director connections.
Timo Sirainen <tss@iki.fi>
parents: 14494
diff changeset
2319 conn->host != NULL) {
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2320 /* connection didn't exist for very long, assume it has a
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2321 network problem */
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2322 conn->host->last_network_failure = ioloop_time;
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2323 }
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2324
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
2325 director_connection_deinit(_conn, reason);
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2326 if (dir->right == NULL)
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
2327 director_connect(dir, "Reconnecting after disconnection");
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2328 }
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2329
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2330 static void director_connection_reconnect(struct director_connection **_conn,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2331 const char *reason)
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2332 {
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2333 struct director_connection *conn = *_conn;
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2334 struct director *dir = conn->dir;
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2335
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2336 director_connection_deinit(_conn, reason);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2337 if (dir->right == NULL)
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
2338 director_connect(dir, "Reconnecting after error");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2339 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2340
22624
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2341 static void director_disconnect_write_error(struct director_connection *conn)
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2342 {
22666
0b8c69533353 director: Reconnect after detecting a write failure to director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22651
diff changeset
2343 struct director *dir = conn->dir;
0b8c69533353 director: Reconnect after detecting a write failure to director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22651
diff changeset
2344
22624
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2345 director_connection_deinit(&conn, "write failure");
22666
0b8c69533353 director: Reconnect after detecting a write failure to director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22651
diff changeset
2346 if (dir->right == NULL)
0b8c69533353 director: Reconnect after detecting a write failure to director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22651
diff changeset
2347 director_connect(dir, "Reconnecting after write failure");
22624
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2348 }
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2349
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2350 void director_connection_send(struct director_connection *conn,
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2351 const char *data)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2352 {
21322
5ab8dc1a4a6f global: Change string position/length from unsigned int to size_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21079
diff changeset
2353 size_t len = strlen(data);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2354 off_t ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2355
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2356 if (conn->output->closed || !conn->connected)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2357 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2358
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2359 if (director_debug) T_BEGIN {
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2360 const char *const *lines = t_strsplit(data, "\n");
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2361 for (; lines[1] != NULL; lines++)
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2362 dir_debug("output: %s: %s", conn->name, *lines);
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2363 } T_END;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2364 ret = o_stream_send(conn->output, data, len);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2365 if (ret != (off_t)len) {
20264
0fd0fb05e2b3 global: Use [io]_stream_get_error() insted of %m
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19973
diff changeset
2366 if (ret < 0) {
0fd0fb05e2b3 global: Use [io]_stream_get_error() insted of %m
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19973
diff changeset
2367 i_error("director(%s): write() failed: %s", conn->name,
0fd0fb05e2b3 global: Use [io]_stream_get_error() insted of %m
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19973
diff changeset
2368 o_stream_get_error(conn->output));
0fd0fb05e2b3 global: Use [io]_stream_get_error() insted of %m
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19973
diff changeset
2369 } else {
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2370 i_error("director(%s): Output buffer full, "
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2371 "disconnecting", conn->name);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2372 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2373 o_stream_close(conn->output);
22624
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2374 /* closing the stream when output buffer is full doesn't cause
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2375 disconnection itself. */
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2376 if (conn->to_disconnect != NULL)
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2377 timeout_remove(&conn->to_disconnect);
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2378 conn->to_disconnect =
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2379 timeout_add_short(0, director_disconnect_write_error, conn);
18664
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
2380 } else {
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
2381 conn->dir->ring_traffic_output += len;
22626
989dcf906522 director: Fix updating director connection's last_output timestamp
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22624
diff changeset
2382 conn->last_output = ioloop_timeval;
22627
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2383 conn->peak_bytes_buffered =
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2384 I_MAX(conn->peak_bytes_buffered,
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2385 o_stream_get_buffer_used_size(conn->output));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2386 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2387 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2388
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2389 static void
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2390 director_connection_ping_idle_timeout(struct director_connection *conn)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2391 {
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2392 string_t *str = t_str_new(128);
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2393
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
2394 str_printfa(str, "Ping timed out in %u secs, disconnecting (",
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
2395 DIRECTOR_CONNECTION_PING_IDLE_TIMEOUT_MSECS/1000);
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
2396 director_connection_append_stats(conn, str);
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2397 if (conn->handshake_received)
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2398 str_append(str, ", handshaked");
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2399 if (conn->synced)
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2400 str_append(str, ", synced");
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2401 str_append_c(str, ')');
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2402 i_error("director(%s): %s", conn->name, str_c(str));
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
2403 director_connection_disconnected(&conn, "Ping timeout");
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2404 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2405
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2406 static void director_connection_pong_timeout(struct director_connection *conn)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2407 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2408 i_error("director(%s): PONG reply not received although other "
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2409 "input keeps coming, disconnecting", conn->name);
18662
27baf04f2b18 director: If we disconnect a director, pass the reason all the way to deinit's debug logging.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
2410 director_connection_disconnected(&conn, "Pong timeout");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2411 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2412
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2413 void director_connection_ping(struct director_connection *conn)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2414 {
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
2415 if (conn->ping_waiting)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2416 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2417
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2418 timeout_remove(&conn->to_ping);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2419 conn->to_ping = timeout_add(DIRECTOR_CONNECTION_PING_IDLE_TIMEOUT_MSECS,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2420 director_connection_ping_idle_timeout, conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2421 conn->to_pong = timeout_add(DIRECTOR_CONNECTION_PONG_TIMEOUT_MSECS,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2422 director_connection_pong_timeout, conn);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2423 director_connection_send(conn, "PING\n");
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
2424 conn->ping_waiting = TRUE;
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
2425 conn->ping_sent_time = ioloop_timeval;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2426 }
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
2427
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
2428 const char *director_connection_get_name(struct director_connection *conn)
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
2429 {
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
2430 return conn->name;
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
2431 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2432
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2433 struct director_host *
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2434 director_connection_get_host(struct director_connection *conn)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2435 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2436 return conn->host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2437 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2438
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2439 bool director_connection_is_handshaked(struct director_connection *conn)
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2440 {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2441 return conn->handshake_received;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2442 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2443
18062
ade6dcace5cd doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
2444 bool director_connection_is_synced(struct director_connection *conn)
ade6dcace5cd doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
2445 {
ade6dcace5cd doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
2446 return conn->synced;
ade6dcace5cd doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
2447 }
ade6dcace5cd doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
2448
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2449 bool director_connection_is_incoming(struct director_connection *conn)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2450 {
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2451 return conn->in;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2452 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2453
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
2454 unsigned int
084064444f89 director: Don't try to send the new SYNC parameter to old director versions.
Timo Sirainen <tss@iki.fi>
parents: 14409
diff changeset
2455 director_connection_get_minor_version(struct director_connection *conn)
084064444f89 director: Don't try to send the new SYNC parameter to old director versions.
Timo Sirainen <tss@iki.fi>
parents: 14409
diff changeset
2456 {
084064444f89 director: Don't try to send the new SYNC parameter to old director versions.
Timo Sirainen <tss@iki.fi>
parents: 14409
diff changeset
2457 return conn->minor_version;
084064444f89 director: Don't try to send the new SYNC parameter to old director versions.
Timo Sirainen <tss@iki.fi>
parents: 14409
diff changeset
2458 }
084064444f89 director: Don't try to send the new SYNC parameter to old director versions.
Timo Sirainen <tss@iki.fi>
parents: 14409
diff changeset
2459
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2460 void director_connection_cork(struct director_connection *conn)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2461 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2462 o_stream_cork(conn->output);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2463 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2464
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2465 void director_connection_uncork(struct director_connection *conn)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2466 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2467 o_stream_uncork(conn->output);
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2468 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2469
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2470 void director_connection_set_synced(struct director_connection *conn,
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2471 bool synced)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2472 {
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2473 if (conn->synced == synced)
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2474 return;
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2475 conn->synced = synced;
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2476
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2477 /* switch ping timeout, unless we're already waiting for PONG */
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2478 if (conn->ping_waiting)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2479 return;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2480
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2481 director_connection_set_ping_timeout(conn);
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2482 }
22627
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2483
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2484 void director_connection_get_status(struct director_connection *conn,
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2485 struct director_connection_status *status_r)
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2486 {
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2487 i_zero(status_r);
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2488 status_r->bytes_read = conn->input->v_offset;
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2489 status_r->bytes_sent = conn->output->offset;
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2490 status_r->bytes_buffered = o_stream_get_buffer_used_size(conn->output);
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2491 status_r->peak_bytes_buffered = conn->peak_bytes_buffered;
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2492 status_r->last_input = conn->last_input;
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2493 status_r->last_output = conn->last_output;
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
2494 status_r->last_ping_msecs = conn->last_ping_msecs;
22627
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2495 }