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

lib-imap: Fix "Don't accept strings with NULs" cherry-pick
author Timo Sirainen <timo.sirainen@open-xchange.com>
date Thu, 29 Aug 2019 09:55:25 +0300
parents cb108f786fb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 22694
diff changeset
1 /* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
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)
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
66 /* 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
67 #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
68 /* 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
69 #define DIRECTOR_CONNECTION_PING_SYNC_INTERVAL_MSECS 1000
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
70 /* Log a warning if PING reply or PONG response takes longer than this */
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
71 #define DIRECTOR_CONNECTION_PINGPONG_WARN_MSECS (5*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
72 /* 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
73 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
74 #define DIRECTOR_SUCCESS_MIN_CONNECT_SECS 40
22674
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
75 /* If USER request doesn't have a timestamp, user isn't refreshed if it was
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
76 already refreshed director_user_expire/4 seconds ago. This value is the
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
77 hardcoded maximum for that value. */
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
78 #define DIRECTOR_SKIP_RECENT_REFRESH_MAX_SECS 15
22567
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
79 #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
80 #define DIRECTOR_WAIT_DISCONNECT_SECS 10
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
81 #define DIRECTOR_HANDSHAKE_WARN_SECS 29
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
82 #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
83 #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
84 /* 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
85 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
86 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
87 #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
88 #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
89 /* 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
90 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
91 #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
92
22672
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
93 #define CMD_IS_USER_HANDSHAKE(minor_version, args) \
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
94 ((minor_version) < DIRECTOR_VERSION_HANDSHAKE_U_CMD && \
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
95 str_array_length(args) > 2)
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
96
18065
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
97 #define DIRECTOR_OPT_CONSISTENT_HASHING "consistent-hashing"
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
98
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 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
100 int refcount;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 struct director *dir;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
102 char *name;
22252
8882a5cbe76d director: Use more accurate timestamps for handshake timeout logging
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22251
diff changeset
103 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
104 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
105 unsigned int minor_version;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
107 struct timeval last_input, last_output;
22627
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
108 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
109
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
110 struct timeval ping_sent_time;
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
111 size_t ping_sent_buffer_size;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
112 struct timeval ping_sent_user_cpu;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
113 uoff_t ping_sent_input_offset, ping_sent_output_offset;
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
114 unsigned int last_ping_msecs;
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
115
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 /* 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
117 ME-line is received */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 struct director_host *host;
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
119 /* this is set only for wrong connections: */
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
120 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
121
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122 int fd;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 struct io *io;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 struct istream *input;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 struct ostream *output;
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
126 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
127
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
128 struct director_user_iter *user_iter;
22677
2fa7cadb2e58 director: Include number of USERs received in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22676
diff changeset
129 unsigned int users_received, handshake_users_received;
22679
496ac7e7563f director: Include number of users sent in handshake in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22678
diff changeset
130 unsigned int handshake_users_sent;
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);
22677
2fa7cadb2e58 director: Include number of USERs received in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22676
diff changeset
186 str_printfa(str, ", %u+%u USERs received",
2fa7cadb2e58 director: Include number of USERs received in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22676
diff changeset
187 conn->handshake_users_received, conn->users_received);
22679
496ac7e7563f director: Include number of users sent in handshake in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22678
diff changeset
188 if (conn->handshake_users_sent > 0) {
496ac7e7563f director: Include number of users sent in handshake in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22678
diff changeset
189 str_printfa(str, ", %u USERs sent in handshake",
496ac7e7563f director: Include number of users sent in handshake in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22678
diff changeset
190 conn->handshake_users_sent);
496ac7e7563f director: Include number of users sent in handshake in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22678
diff changeset
191 }
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
192 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
193 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
194 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
195 }
29ae473d0b7c director: Fix logging last input/output time when there was no input/output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22255
diff changeset
196 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
197 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
198 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
199 }
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
200 if (conn->connected) {
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
201 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
202 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
203 }
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
204 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
205 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
206 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
207 }
22649
bb7c452e3662 director: Include peak output buffer size in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22648
diff changeset
208 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
209 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
210 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
211 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
212 /* 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
213 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
214 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
215 &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
216 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
217 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
218 }
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
219 }
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
220
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
221 static void
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
222 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
223 {
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
224 struct timeval start_time;
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
225 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
226
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
227 if (!conn->connected) {
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->created;
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
229 str_append(reason, "Connect timed out");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
230 } 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
231 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
232 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
233 } 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
234 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
235 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
236 } else {
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
237 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
238 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
239 }
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
240 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
241 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
242 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
243 str_append_c(reason, ')');
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
244
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
245 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
246 director_connection_disconnected(&conn, "Handshake timeout");
14409
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
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
249 static void
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
250 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
251 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
252 unsigned int msecs;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
253
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
254 msecs = conn->synced || !conn->handshake_received ?
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
255 DIRECTOR_CONNECTION_PING_INTERVAL_MSECS :
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
256 DIRECTOR_CONNECTION_PING_SYNC_INTERVAL_MSECS;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
257
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
258 timeout_remove(&conn->to_ping);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
259 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
260 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
261
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
262 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
263 {
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
264 director_connection_log_disconnect(conn, ETIMEDOUT, "");
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
265 director_connection_deinit(&conn,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
266 "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
267 }
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
268
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
269 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
270 struct director_host *host)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
271 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
272 const char *connect_str;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
273
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
274 if (conn->to_disconnect != NULL)
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
275 return;
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
276
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
277 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
278 host->ip_str, host->port);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
279 director_connection_send(conn, connect_str);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
280 o_stream_uncork(conn->output);
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
281
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
282 /* 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
283 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
284 multiple log lines about it. */
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
285 conn->connect_request_to = host;
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
286 director_host_ref(conn->connect_request_to);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
287
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
288 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
289 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
290 director_connection_wait_timeout, conn);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
291 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
292
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
293 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
294 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
295 struct director *dir = conn->dir;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
296
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
297 if (dir->left != NULL && dir->right != NULL) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
298 /* 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
299 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
300 dir->sync_seq++;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
301 director_set_ring_unsynced(dir);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
302 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
303 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
304 mail_hosts_hash(dir->mail_hosts));
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
305 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
306 director_connection_set_ping_timeout(conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
307 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
308
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
309 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
310 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
311 struct director *dir = conn->dir;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
312
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
313 i_assert(conn->in);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
314 i_assert(dir->left != conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
315
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
316 /* 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
317 if (conn->host->self) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
318 i_error("Connection from self, dropping");
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
319 return FALSE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
320 } else if (dir->left == NULL) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
321 /* no conflicts yet */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
322 } else if (dir->left->host == conn->host) {
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
323 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
324 dir->left->host->name, conn->host->name);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
325 director_connection_deinit(&dir->left, t_strdup_printf(
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
326 "Replacing with %s", conn->host->name));
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
327 } else if (dir->left->verifying_left) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
328 /* 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
329 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
330 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
331 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
332 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
333 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
334 } 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
335 dir->self_host) < 0) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
336 /* the old connection is the correct one.
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
337 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
338 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
339 return TRUE;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
340 } else {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
341 /* 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
342 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
343 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
344 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
345 switch will be fast. */
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 dir->left = conn;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
349 i_free(conn->name);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
350 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
351 director_connection_assigned(conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
352 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
353 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
354
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
355 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
356 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
357 struct director_connection *conn, *const *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
358
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
359 array_foreach(&dir->connections, connp) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
360 conn = *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
361
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
362 if (conn->in && conn->handshake_received &&
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
363 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
364 /* either use this or disconnect it */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
365 if (!director_connection_assign_left(conn)) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
366 /* we don't want this */
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
367 director_connection_deinit(&conn,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
368 "Unwanted incoming connection");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
369 director_assign_left(dir);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
370 break;
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 }
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 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
375
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
376 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
377 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
378 struct director_connection *const *connp;
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 array_foreach(&dir->connections, connp) {
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
381 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
382 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
383 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
384 return FALSE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
385 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
386
20971
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
387 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
388 {
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
389 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
390
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
391 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
392
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
393 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
394 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
395 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
396 continue;
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 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
399 (*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
400 (*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
401 (*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
402 (*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
403 }
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
404 }
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
405
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
406 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
407 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
408 struct director *dir = conn->dir;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
410 i_assert(!conn->in);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
411
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
412 if (dir->right != NULL) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
413 /* 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
414 connection. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
415 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
416 dir->self_host) <= 0) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
417 /* the old connection is the correct one */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
418 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
419 "(already connected to correct one: %s)",
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
420 conn->host->name, dir->right->host->name);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
421 conn->wrong_host = TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
422 return FALSE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
423 }
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
424 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
425 dir->right->host->name, conn->host->name);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
426 director_connection_deinit(&dir->right, t_strdup_printf(
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
427 "Replacing with %s", conn->host->name));
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
428 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
429 dir->right = conn;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
430 i_free(conn->name);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
431 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
432 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
433 director_send_delayed_syncs(dir);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
434 return TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
435 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
436
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 static bool
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 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
439 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
440 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
441 {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
442 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
443 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
444 return FALSE;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
445 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446 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
447 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
448 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 }
19035
aabfe48db1cf Changed type of internet port values to in_port_t everywhere.
Stephan Bosch <stephan@rename-it.nl>
parents: 18858
diff changeset
450 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
451 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
452 return FALSE;
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 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
457 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
458 const char *const *args)
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 struct director *dir = conn->dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
461 const char *connect_str;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462 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
463 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
464 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
465
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 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
467 return FALSE;
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
468 if (conn->me_received) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
469 director_cmd_error(conn, "Duplicate ME");
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
470 return FALSE;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
471 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 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
474 conn->host->port != port)) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 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
476 "(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
477 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
478 net_ip2addr(&ip), port);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 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
482 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
483
19294
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
484 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
485 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
486 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
487
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
488 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
489 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
490 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
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 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
493 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
494 (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
495 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
496 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
497 }
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
498 }
d96595e2363b director: Log a warning if directors' clocks are too much out of sync.
Timo Sirainen <tss@iki.fi>
parents: 19293
diff changeset
499
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
500 timeout_remove(&conn->to_ping);
22250
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
501 if (conn->in) {
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
502 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
503 director_connection_init_timeout, conn);
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
504 } else {
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
505 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
506 director_connection_init_timeout, conn);
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
507 }
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
508
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
509 if (!conn->in)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
510 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
511
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
512 /* Incoming connection:
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 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
515 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
516
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
517 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
518 is most likely dead.
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
519
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
520 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
521 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
522
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
523 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
524 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
525 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
526 */
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
527 i_assert(conn->host == NULL);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
528 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
529 /* 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
530 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
531 conn->host->removed = FALSE;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
532 director_host_ref(conn->host);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
533 /* 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
534 director_host_restarted(conn->host);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
535
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
536 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
537 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
538 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
539 /* 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
540 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
541 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
542 "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
543 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
544 return FALSE;
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
545 } else if (dir->left == NULL) {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
546 /* 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
547 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
548 conn->host->last_network_failure = 0;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
549 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
550 director_connect(dir, "Connecting to left");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
551 } else if (dir->left->host == conn->host) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
552 /* b) */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
553 i_assert(dir->left != conn);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
554 director_connection_deinit(&dir->left,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
555 "Replacing with new incoming connection");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
556 } 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
557 dir->self_host) < 0) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
558 /* c) */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
559 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
560 conn->host->ip_str,
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
561 conn->host->port);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
562 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
563 } else {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
564 /* d) */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
565 dir->left->verifying_left = TRUE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
566 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
567 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
568 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
569 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
570
22674
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
571 static inline bool
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
572 user_need_refresh(struct director *dir, struct user *user,
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
573 time_t timestamp, bool unknown_timestamp)
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
574 {
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
575 if (timestamp <= (time_t)user->timestamp) {
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
576 /* we already have this timestamp */
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
577 return FALSE;
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
578 }
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
579 if (unknown_timestamp) {
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
580 /* Old director sent USER command without timestamp. We don't
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
581 know what it is exactly, but we can assume that it's very
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
582 close to the current time (which timestamp parameter is
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
583 already set to). However, try to break USER loops here when
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
584 director ring latency is >1sec, but below skip_recent_secs
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
585 by just not refreshing the user. */
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
586 unsigned int skip_recent_secs =
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
587 I_MIN(dir->set->director_user_expire/4,
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
588 DIRECTOR_SKIP_RECENT_REFRESH_MAX_SECS);
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
589 if ((time_t)user->timestamp + skip_recent_secs >= timestamp)
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
590 return FALSE;
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
591 }
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
592 return TRUE;
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
593 }
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
594
22691
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
595 static int
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
596 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
597 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
598 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
599 struct user **user_r)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
600 {
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
601 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
602 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
603 bool ret = FALSE, unset_weak_user = FALSE;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21077
diff changeset
604 struct user_directory *users = host->tag->users;
22674
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
605 bool unknown_timestamp = (timestamp == (time_t)-1);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
606
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
607 *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
608
22674
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
609 if (unknown_timestamp) {
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
610 /* Old director version sent USER without timestamp. */
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
611 timestamp = ioloop_time;
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
612 }
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
613
22671
ad943b175750 director: Ignore refresh requests for already expired user timestamps
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22670
diff changeset
614 if (timestamp + (time_t)dir->set->director_user_expire <= ioloop_time) {
22691
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
615 /* Ignore this refresh entirely, regardless of whether the
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
616 user already exists or not. */
22671
ad943b175750 director: Ignore refresh requests for already expired user timestamps
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22670
diff changeset
617 dir_debug("user refresh: %u has expired timestamp %ld",
ad943b175750 director: Ignore refresh requests for already expired user timestamps
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22670
diff changeset
618 username_hash, (long)timestamp);
22691
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
619 return -1;
22671
ad943b175750 director: Ignore refresh requests for already expired user timestamps
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22670
diff changeset
620 }
ad943b175750 director: Ignore refresh requests for already expired user timestamps
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22670
diff changeset
621
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
622 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
623 if (user == NULL) {
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
624 *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
625 host, timestamp);
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
626 (*user_r)->weak = weak;
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
627 dir_debug("user refresh: %u added", username_hash);
22691
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
628 return 1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
629 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
630
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
631 if (user->weak) {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
632 if (!weak) {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
633 /* removing user's weakness */
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
634 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
635 username_hash);
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
636 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
637 user->weak = FALSE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
638 ret = TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
639 } else {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
640 /* 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
641 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
642 } else if (weak &&
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
643 !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
644 /* mark the user as weak */
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
645 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
646 user->weak = TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
647 ret = TRUE;
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
648 } else if (weak) {
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
649 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
650 "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
651 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
652 user->host->ip_str);
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
653 host = user->host;
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
654 ret = TRUE;
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
655 } else if (user->host == host) {
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
656 /* update to the same host */
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
657 } 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
658 /* 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
659 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
660 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
661 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
662 "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
663 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
664 ret = TRUE;
20986
410eacd7ad40 director: Code cleanup - added USER_IS_BEING_KILLED() macro
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
665 } 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
666 /* 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
667 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
668 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
669 "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
670 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
671 host = user->host;
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
672 } else {
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
673 /* 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
674 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
675 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
676
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
677 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
678 "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
679 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
680 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
681
d048cebc1fd4 director: Add more info to "User hash .. is being redirected to two hosts" error.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
682 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
683 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
684 (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
685 }
20986
410eacd7ad40 director: Code cleanup - added USER_IS_BEING_KILLED() macro
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20981
diff changeset
686 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
687 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
688 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
689 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
690 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
691 }
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
692 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
693 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
694
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
695 /* 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
696 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
697 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
698 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
699 /* 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
700 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
701 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
702
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 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
704 *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
705 } else {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
706 /* keep the host */
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
707 host = user->host;
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
708 }
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
709 /* 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
710 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
711 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
712 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
713 username_hash, &host->ip);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
714 ret = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
715 }
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
716 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
717 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
718 user->host = host;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
719 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
720 ret = TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
721 }
22673
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
722 /* Update user's timestamp if it's higher than the current one. Note
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
723 that we'll preserve the original timestamp. This is important when
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
724 the director ring is slow and a single USER can traverse through
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
725 the ring more than a second. We don't want to get into a loop where
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
726 the same USER goes through the ring forever. */
22674
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
727 if (user_need_refresh(dir, user, timestamp, unknown_timestamp)) {
22673
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
728 /* NOTE: This makes the users list somewhat out-of-order.
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
729 It's not a big problem - most likely it's only a few seconds
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
730 difference. The worst that can happen is that some users
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
731 take up memory that should have been freed already. */
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
732 dir_debug("user refresh: %u refreshed timestamp from %u to %ld",
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
733 username_hash, user->timestamp, (long)timestamp);
21074
6543f5b25252 director: Code cleanup - use temporary users variables
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20988
diff changeset
734 user_directory_refresh(users, user);
22673
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
735 user->timestamp = timestamp;
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
736 ret = TRUE;
22673
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
737 } else {
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
738 dir_debug("user refresh: %u ignored timestamp %ld (we have %u)",
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
739 username_hash, (long)timestamp, user->timestamp);
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
740 }
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
741
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
742 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
743 /* 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
744 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
745 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
746 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
747
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
748 *user_r = user;
22691
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
749 return ret ? 1 : 0;
11321
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
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
752 static bool
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
753 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
754 const char *const *args)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
755 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
756 unsigned int username_hash, timestamp;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
757 struct ip_addr ip;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
758 struct mail_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
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 weak, forced;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
761
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
762 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
763 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
764 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
765 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
766 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
767 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
768 }
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
769 weak = args[3] != NULL && args[3][0] == 'w';
22677
2fa7cadb2e58 director: Include number of USERs received in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22676
diff changeset
770 conn->handshake_users_received++;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
771
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
772 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
773 if (host == NULL) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
774 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
775 conn->name, args[1]);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
776 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
777 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
778
22668
3d99067fb0b9 director: Make sure user's timestamp isn't set to future
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22666
diff changeset
779 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
780 /* 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
781 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
782 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
783 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
784 }
22678
ea5633b00934 director: Show number of incoming USERs/sec in ps title
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22677
diff changeset
785 conn->dir->num_incoming_requests++;
22691
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
786 if (director_user_refresh(conn, username_hash, host,
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
787 timestamp, weak, &forced, &user) < 0) {
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
788 /* user expired - ignore */
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
789 return TRUE;
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
790 }
22670
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
791 /* Possibilities:
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
792
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
793 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
794 timestamp.
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
795
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
796 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
797 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
798
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
799 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
800 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
801 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
802
a96fa917ced1 director: Keep users unsorted during handshake and sort them at the end
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22669
diff changeset
803 (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
804 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
805 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
806 if (user->timestamp < timestamp)
16621
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
807 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
808 /* 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
809 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
810 conn->users_unsorted = TRUE;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
811 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
812 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
813
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
814 static bool
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
815 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
816 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
817 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
818 unsigned int username_hash;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
819 struct ip_addr ip;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
820 struct mail_host *host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
821 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
822 bool forced;
22674
af1a9f282179 director: Avoid USER loops with >1s ring latency also with old directors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22673
diff changeset
823 time_t timestamp = (time_t)-1;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
824
22673
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
825 if (str_array_length(args) < 2 ||
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
826 str_to_uint(args[0], &username_hash) < 0 ||
22673
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
827 net_addr2ip(args[1], &ip) < 0 ||
867c3905ac0b director: Avoid USER loops when ring latency is over 1 second
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22672
diff changeset
828 (args[2] != NULL && str_to_time(args[2], &timestamp) < 0)) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
829 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
830 return FALSE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
831 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
832
22678
ea5633b00934 director: Show number of incoming USERs/sec in ps title
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22677
diff changeset
833 /* could this before it's potentially ignored */
ea5633b00934 director: Show number of incoming USERs/sec in ps title
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22677
diff changeset
834 conn->dir->num_incoming_requests++;
ea5633b00934 director: Show number of incoming USERs/sec in ps title
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22677
diff changeset
835
22677
2fa7cadb2e58 director: Include number of USERs received in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22676
diff changeset
836 conn->users_received++;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
837 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
838 if (host == NULL) {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
839 /* 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
840 return TRUE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
841 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
842
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
843 if (director_user_refresh(conn, username_hash,
22691
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
844 host, timestamp, FALSE, &forced, &user) > 0) {
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
845 /* user changed - forward the USER in the ring */
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
846 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
847 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
848 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
849 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
850 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
851 return TRUE;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
852 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
853
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
854 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
855 const char *const *args)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
856 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
857 struct director_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
858 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
859 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
860 bool log_add = FALSE;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
861
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
862 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
863 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
864
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
865 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
866 if (host != NULL) {
14493
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
867 if (host == conn->dir->self_host) {
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
868 /* ignore updates to ourself */
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
869 return TRUE;
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
870 }
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
871 if (host->removed) {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
872 /* 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
873 return TRUE;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
874 }
14493
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
875
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
876 /* 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
877 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
878 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
879 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
880 to it) */
ad4d877d655b director: Don't reset directors' last_network_failure while handshaking
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22564
diff changeset
881 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
882 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
883 /* 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
884 director_host_restarted(host);
14493
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
885 } else {
1856e9085f94 director: Forward DIRECTOR commands to other connected directors.
Timo Sirainen <tss@iki.fi>
parents: 14488
diff changeset
886 /* 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
887 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
888 log_add = TRUE;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
889 }
16789
5d43c926eb97 director: Make sure director restart notifications go to everyone in the ring.
Timo Sirainen <tss@iki.fi>
parents: 16788
diff changeset
890 /* 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
891 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
892 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
893 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
894 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
895 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
896 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
897 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
898 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
899 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
900 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
901 "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
902 } 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
903 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
904 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
905 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
906 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
907 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
908
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
909 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
910 const char *const *args)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
911 {
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
912 struct director_host *host;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
913 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
914 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
915
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
916 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
917 return FALSE;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
918
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
919 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
920 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
921 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
922 return TRUE;
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
923 }
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
924
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
925 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
926 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
927 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
928 {
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
929 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
930 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
931 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
932
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
933 if (args[0] == NULL ||
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
934 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
935 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
936 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
937 }
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
938
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
939 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
940 /* 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
941 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
942 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
943 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
944 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
945 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
946 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
947 }
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
948 } 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
949 /* ignore whatever remote sends */
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
950 dir_debug("%s: Remote is joining our ring - "
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
951 "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
952 conn->ignore_host_events = TRUE;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
953 } else {
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
954 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
955 }
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
956 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
957 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
958 }
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
959
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
960 static int
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
961 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
962 const char *const **_args, unsigned int *seq_r,
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
963 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
964 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
965 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
966 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
967 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
968 unsigned int seq;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
969 struct director_host *host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
970
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
971 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
972 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
973 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
974 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
975 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
976 return -1;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
977 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
978 *_args = args + 3;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
979 *seq_r = seq;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
980
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
981 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
982 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
983 /* 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
984 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
985 ourself. */
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
986 *host_r = NULL;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
987 } else {
15350
bb095315d025 Make static analyzer happier.
Timo Sirainen <tss@iki.fi>
parents: 15337
diff changeset
988 *host_r = host;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
989 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
990 /* already seen this */
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
991 return 1;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
992 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
993 host->last_seq = seq;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
994 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
995 return 0;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
996 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
997
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
998 static int
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
999 director_cmd_is_seen(struct director_connection *conn,
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1000 const char *const **_args,
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1001 struct director_host **host_r)
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1002 {
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1003 unsigned int seq;
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1004
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1005 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
1006 }
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1007
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1008 static bool
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1009 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
1010 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
1011 {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1012 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
1013 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
1014 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
1015 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
1016 struct user *user;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1017 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
1018 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
1019 int ret;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1020
15320
e4c337f38ed6 director: Fixed previous broken change for handling USER-WEAK commands.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1021 /* 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
1022 duplicate commands */
e4c337f38ed6 director: Fixed previous broken change for handling USER-WEAK commands.
Timo Sirainen <tss@iki.fi>
parents: 15132
diff changeset
1023 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
1024 return FALSE;
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1025
22678
ea5633b00934 director: Show number of incoming USERs/sec in ps title
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22677
diff changeset
1026 /* could this before it's potentially ignored */
ea5633b00934 director: Show number of incoming USERs/sec in ps title
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22677
diff changeset
1027 conn->dir->num_incoming_requests++;
ea5633b00934 director: Show number of incoming USERs/sec in ps title
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22677
diff changeset
1028
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1029 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
1030 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
1031 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
1032 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
1033 return FALSE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1034 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1035
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1036 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
1037 if (host == NULL) {
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1038 /* 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
1039 return TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1040 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1041
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
1042 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
1043 /* 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
1044 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
1045 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
1046 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
1047 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
1048 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
1049 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
1050 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
1051 } 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
1052 /* 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
1053 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
1054 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
1055 username_hash);
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
1056 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
1057 weak = FALSE;
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
1058 } else {
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
1059 /* 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
1060 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
1061 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
1062 travelled through the ring. */
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
1063 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
1064 username_hash, dir_host->ip_str);
16619
9b8b5ce6ecb0 director: Fixes to handling users near expiration.
Timo Sirainen <tss@iki.fi>
parents: 16618
diff changeset
1065 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
1066 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1067
22691
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
1068 ret = director_user_refresh(conn, username_hash,
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
1069 host, ioloop_time, weak, &forced, &user);
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
1070 /* user is refreshed with ioloop_time, it can't be expired already */
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
1071 i_assert(ret >= 0);
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
1072 if (ret > 0 || weak_forward) {
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
1073 /* user changed, or we've decided that we need to forward
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
1074 the weakness notification to the rest of the ring even
dca05b22217b director: Fix crash when handling expired USER timestamps.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22689
diff changeset
1075 though we already knew it. */
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
1076 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
1077 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
1078 if (!user->weak)
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1079 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
1080 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
1081 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
1082 dir_host, user);
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1083 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1084 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1085 return TRUE;
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1086 }
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1087
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
1088 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
1089 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
1090 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
1091 {
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
1092 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
1093 struct mail_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1094 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
1095 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
1096 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
1097 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
1098 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
1099
19309
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1100 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
1101 if (arg_count < 2 ||
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1102 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
1103 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
1104 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
1105 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1106 }
19309
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1107 if (arg_count >= 3)
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1108 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
1109 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
1110 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
1111 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
1112 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
1113 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
1114 }
19309
8e9cada0c8fc director: Small code cleanup - make it easier to add parameters to HOST
Timo Sirainen <tss@iki.fi>
parents: 19294
diff changeset
1115 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
1116 }
19310
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1117 if (arg_count >= 5)
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1118 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
1119 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
1120 /* 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
1121 a completed ring and we do. */
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
1122 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
1123 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
1124 }
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1125 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
1126 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
1127 return FALSE;
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1128 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1129
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
1130 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
1131 if (host == NULL) {
19310
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
1132 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
1133 hostname, &ip, tag);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1134 update = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1135 } else {
18729
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
1136 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
1137 host->down != down;
19292
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1138
19408
7e47f561ad49 director: Code cleanup - access host->tag via mail_host_get_tag()
Timo Sirainen <tss@iki.fi>
parents: 19407
diff changeset
1139 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
1140 if (strcmp(tag, host_tag) != 0) {
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1141 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
1142 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
1143 host_tag, tag);
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1144 mail_host_set_tag(host, tag);
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1145 update = TRUE;
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
1146 }
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
1147 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
1148 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
1149
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1150 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
1151 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
1152 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
1153 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
1154 /* 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
1155 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
1156 }
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
1157 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
1158 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
1159 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
1160 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
1161 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
1162 }
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1163 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
1164 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
1165 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
1166 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
1167 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
1168 }
01e33753b08e director: "Host is being updated before previous update had finished" logs now details.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
1169 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
1170
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
1171 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
1172 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
1173 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
1174 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
1175 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
1176 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
1177 /* 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
1178 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
1179 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
1180 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
1181 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1182 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1183
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1184 if (update) {
21842
86e52ff70044 director: Log vhost count changes and HOST-UP/DOWN
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21390
diff changeset
1185 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
1186 conn->name);
86e52ff70044 director: Log vhost count changes and HOST-UP/DOWN
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21390
diff changeset
1187 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
1188 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
1189 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
1190 } else {
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1191 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
1192 "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
1193 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
1194 (long)last_updown_change,
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1195 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
1196 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1197 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1198 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1199
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1200 static bool
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1201 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
1202 const char *const *args)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1203 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1204 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
1205 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1206
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1207 static bool
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1208 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
1209 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1210 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
1211 int ret;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1212
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1213 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
1214 return ret > 0;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1215 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
1216 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1217
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1218 static bool
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1219 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
1220 const char *const *args)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1221 {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1222 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
1223 struct mail_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1224 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
1225 int ret;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1226
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1227 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
1228 return ret > 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1229
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1230 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
1231 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
1232 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
1233 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1234 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1235
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
1236 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
1237 if (host != NULL)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1238 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
1239 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1240 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1241
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1242 static bool
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1243 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
1244 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
1245 {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1246 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
1247 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
1248 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
1249 int ret;
11355
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1250
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1251 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
1252 return ret > 0;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1253
11816
9e41df232dd6 director: Fixed handling HOST-FLUSH commands.
Timo Sirainen <tss@iki.fi>
parents: 11758
diff changeset
1254 if (str_array_length(args) != 1 ||
9e41df232dd6 director: Fixed handling HOST-FLUSH commands.
Timo Sirainen <tss@iki.fi>
parents: 11758
diff changeset
1255 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
1256 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
1257 return FALSE;
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1258 }
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1259
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1260 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
1261 if (host != NULL)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1262 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
1263 return TRUE;
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1264 }
ef1de95396d4 Added doveadm director flush command for dropping user associations from memory.
Timo Sirainen <tss@iki.fi>
parents: 11352
diff changeset
1265
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1266 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
1267 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
1268 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
1269 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1270 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
1271 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
1272 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
1273 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
1274 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
1275
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1276 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
1277 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
1278
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1279 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
1280 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
1281 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
1282 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
1283 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
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
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1286 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
1287 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
1288 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
1289 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
1290 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1291 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
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
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1294 static bool
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1295 director_cmd_user_kick(struct director_connection *conn,
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1296 const char *const *args)
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1297 {
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1298 struct director_host *dir_host;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1299 int ret;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1300
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1301 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
1302 return ret > 0;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1303
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1304 if (str_array_length(args) != 1) {
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1305 director_cmd_error(conn, "Invalid parameters");
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1306 return FALSE;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1307 }
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1308
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1309 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
1310 return TRUE;
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1311 }
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1312
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1313 static bool
20846
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1314 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
1315 const char *const *args)
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1316 {
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1317 struct director_host *dir_host;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1318 int ret;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1319
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1320 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
1321 return ret > 0;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1322
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1323 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
1324 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
1325 return FALSE;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1326 }
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1327
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1328 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
1329 return TRUE;
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1330 }
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1331
9d70a6f86e24 doveadm director kick: Added -f <passdb field> parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20575
diff changeset
1332 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
1333 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
1334 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
1335 {
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
1336 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
1337 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
1338 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
1339 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
1340
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
1341 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
1342 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
1343
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
1344 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
1345 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
1346 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
1347 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
1348 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
1349 }
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
1350
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
1351 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
1352 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
1353 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
1354 }
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
1355
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
1356 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
1357 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
1358 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
1359 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1360 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
1361
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1362 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
1363 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
1364 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
1365 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
1366 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1367
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1368 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
1369 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
1370 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1371
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1372 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
1373 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
1374 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
1375 {
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1376 struct director_host *dir_host;
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1377 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
1378 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
1379
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1380 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
1381 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
1382
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1383 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
1384 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
1385 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
1386 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
1387 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1388
20981
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1389 if (ret > 0) {
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1390 i_assert(dir_host != NULL);
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1391 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
1392 "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
1393 seq, dir_host->name, dir_host->last_seq);
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1394 return TRUE;
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1395 }
699e305f6a39 director: Improve debug logging output.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20980
diff changeset
1396
13045
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1397 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
1398 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
1399 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
1400 }
79f9dce5d5fd director: Added support for moving user to another server with "doveadm director move".
Timo Sirainen <tss@iki.fi>
parents: 12935
diff changeset
1401
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1402 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
1403 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1404 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
1405 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
1406 string_t *str;
14478
ee169584bc44 director: Improved debug handshake message.
Timo Sirainen <tss@iki.fi>
parents: 14477
diff changeset
1407
16621
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
1408 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
1409 /* 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
1410 conn->users_unsorted = FALSE;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21077
diff changeset
1411 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
1412 }
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
1413
18063
91c525000811 director: Always log a message when director handshake finishes.
Timo Sirainen <tss@iki.fi>
parents: 18062
diff changeset
1414 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
1415 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
1416 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
1417 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
1418 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
1419 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
1420 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
1421 else
91c525000811 director: Always log a message when director handshake finishes.
Timo Sirainen <tss@iki.fi>
parents: 18062
diff changeset
1422 i_info("%s", str_c(str));
11579
61708c33154d director: Debug message improvements.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
1423
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1424 /* 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
1425 if needed */
14432
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
1426 conn->host->last_network_failure = 0;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1427
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1428 conn->handshake_received = TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1429 if (conn->in) {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1430 /* 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
1431 whole handshake. */
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1432 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
1433
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1434 /* 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
1435 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
1436 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
1437 conn->host->ip_str,
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1438 conn->host->port));
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1439 /* this is our "left" side. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1440 return director_connection_assign_left(conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1441 } else {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1442 /* handshaked to "right" side. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1443 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
1444 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1445 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1446
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1447 static int
18065
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1448 director_handshake_cmd_options(struct director_connection *conn,
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1449 const char *const *args)
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1450 {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1451 bool consistent_hashing = FALSE;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1452 unsigned int i;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1453
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1454 for (i = 0; args[i] != NULL; i++) {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1455 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
1456 consistent_hashing = TRUE;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1457 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1458 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
1459 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
1460 conn->name);
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1461 return -1;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1462 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1463 return 1;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1464 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1465
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1466 static int
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1467 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
1468 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
1469 {
19036
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1470 unsigned int major_version;
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1471
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1472 /* 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
1473 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
1474 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
1475 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
1476 "(%s vs %s)",
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1477 conn->name, args[0], DIRECTOR_VERSION_NAME);
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1478 return -1;
19036
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1479 } 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
1480 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
1481 i_error("director(%s): Invalid protocol version: "
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1482 "%s.%s", conn->name, args[1], args[2]);
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1483 return -1;
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1484 } 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
1485 i_error("director(%s): Incompatible protocol version: "
19036
f78e38c7cba2 Removed all invocations of atoi().
Stephan Bosch <stephan@rename-it.nl>
parents: 19035
diff changeset
1486 "%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
1487 DIRECTOR_VERSION_MAJOR);
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1488 return -1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1489 }
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1490 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
1491 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
1492 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
1493 return -1;
19411
0e05efd14b39 director: Fixed backend selection when multiple tags were used.
Timo Sirainen <tss@iki.fi>
parents: 19408
diff changeset
1494 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1495 conn->version_received = TRUE;
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
1496 director_finish_sending_handshake(conn);
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1497 return 1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1498 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1499 if (!conn->version_received) {
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1500 director_cmd_error(conn, "Incompatible protocol");
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1501 return -1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1502 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1503
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1504 if (strcmp(cmd, "ME") == 0)
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1505 return director_cmd_me(conn, args) ? 1 : -1;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1506 if (!conn->me_received) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1507 director_cmd_error(conn, "Expecting ME command first");
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1508 return -1;
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
1509 }
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
1510
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1511 /* incoming connections get a HOST list */
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1512 if (conn->handshake_sending_hosts) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1513 if (strcmp(cmd, "HOST") == 0)
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1514 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
1515 if (strcmp(cmd, "HOST-HAND-END") == 0) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1516 conn->ignore_host_events = FALSE;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1517 conn->handshake_sending_hosts = FALSE;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1518 return 1;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1519 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1520 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
1521 return -1;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1522 }
18065
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1523 if (strcmp(cmd, "OPTIONS") == 0)
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
1524 return director_handshake_cmd_options(conn, args);
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1525 if (strcmp(cmd, "HOST-HAND-START") == 0) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1526 if (!conn->in) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1527 director_cmd_error(conn,
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1528 "Host list is only for incoming connections");
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1529 return -1;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1530 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1531 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
1532 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1533
22672
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
1534 if (conn->in &&
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
1535 (strcmp(cmd, "U") == 0 ||
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
1536 (strcmp(cmd, "USER") == 0 &&
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
1537 CMD_IS_USER_HANDSHAKE(conn->minor_version, args))))
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1538 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
1539
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1540 /* both get DONE */
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1541 if (strcmp(cmd, "DONE") == 0)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1542 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
1543 return 0;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1544 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1545
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
1546 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
1547 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
1548 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
1549 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
1550 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
1551 {
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1552 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
1553
14306
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1554 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
1555 /* 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
1556 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
1557 }
334424e7465e director: Keep track of the highest supported protocol version in the ring.
Timo Sirainen <tss@iki.fi>
parents: 14303
diff changeset
1558
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1559 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
1560 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
1561 /* 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
1562 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
1563 }
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1564 /* 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
1565 successfully connected to both directions */
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1566 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
1567
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
1568 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
1569 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
1570 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
1571 "(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
1572 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
1573 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
1574 (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
1575 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
1576 }
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
1577
14310
7a26c427fc78 director: Avoid user getting redirected to different servers near its expiration.
Timo Sirainen <tss@iki.fi>
parents: 14306
diff changeset
1578 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
1579 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
1580 /* 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
1581 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
1582 } 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
1583 /* 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
1584 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
1585 } else {
19292
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1586 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
1587 conn->name, seq,
bae8efd8b5b3 director: Use mail_hosts_hash() to improve debug log messages.
Timo Sirainen <tss@iki.fi>
parents: 19289
diff changeset
1588 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
1589 int sync_msecs =
0281041d5067 director: Track show long the last ring sync took.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22628
diff changeset
1590 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
1591 if (sync_msecs >= 0)
0281041d5067 director: Track show long the last ring sync took.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22628
diff changeset
1592 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
1593 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
1594 }
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
1595 } else {
16790
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1596 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
1597 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
1598 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
1599 /* stale SYNC event */
16787
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1600 dir_debug("Ignore stale SYNC event for %s "
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1601 "(seq %u < %u, timestamp=%u)",
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1602 host->name, seq, host->last_sync_seq,
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1603 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
1604 return FALSE;
16790
c30453a58b4c director: Detect lost director restarts and reset last_sync_seq.
Timo Sirainen <tss@iki.fi>
parents: 16789
diff changeset
1605 } 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
1606 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
1607 "(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
1608 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
1609 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
1610 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
1611 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
1612 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
1613 } 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
1614 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
1615 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
1616 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
1617 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
1618 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
1619 "(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
1620 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
1621 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
1622 } 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
1623 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
1624 /* we've received this too many times already */
16786
17389ac3cb66 director: Added more debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16699
diff changeset
1625 dir_debug("Ignore duplicate #%u SYNC event for %s "
17389ac3cb66 director: Added more debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16699
diff changeset
1626 "(seq=%u, timestamp %u <= %u)",
16787
22a3ef9a006d director: Fix & improvement to debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16786
diff changeset
1627 host->last_sync_seq_counter, host->name, seq,
16786
17389ac3cb66 director: Added more debug logging.
Timo Sirainen <tss@iki.fi>
parents: 16699
diff changeset
1628 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
1629 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
1630 }
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
1631
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
1632 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
1633 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
1634 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
1635 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
1636 "(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
1637 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
1638 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
1639 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
1640 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
1641 }
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
1642 /* 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
1643 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
1644 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
1645 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
1646 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
1647 "(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
1648 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
1649 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
1650 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
1651 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
1652 }
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
1653 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
1654 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
1655 /* 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
1656 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
1657 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
1658 } else {
3e6f922c2322 director: If SYNCs are received during handshake, send them later.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20846
diff changeset
1659 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
1660 "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
1661 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
1662 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
1663 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
1664 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
1665 }
13940
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1666 }
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
1667 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
1668 }
9e43af01f147 director: Make sure ring syncing doesn't get lost when directors get disconnected.
Timo Sirainen <tss@iki.fi>
parents: 13921
diff changeset
1669
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1670 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
1671 const char *const *args)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1672 {
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
1673 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
1674 struct director_host *host;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
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;
19289
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1677 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
1678 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
1679
19289
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1680 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
1681 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
1682 !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
1683 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
1684 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
1685 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1686 }
19289
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1687 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
1688 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
1689 return FALSE;
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1690 }
4e0c9df36a78 director: Small code cleanup - make it easier to add parameters to SYNC
Timo Sirainen <tss@iki.fi>
parents: 19287
diff changeset
1691 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
1692 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
1693 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
1694 }
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
1695 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
1696 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
1697 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
1698 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1699
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1700 /* 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
1701 removed and we can ignore this sync. */
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
1702 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
1703 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
1704 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
1705 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
1706 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
1707 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
1708 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1709
19954
82ffadc8c4d7 director: Don't re-send SYNC unnecessarily often.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19953
diff changeset
1710 /* 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
1711 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
1712 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
1713 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
1714 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
1715 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
1716 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
1717 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
1718 (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
1719 (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
1720 return TRUE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1721 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1722
22567
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1723 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
1724 {
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1725 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
1726 }
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1727
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1728 static void
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1729 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
1730 {
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1731 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
1732
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1733 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
1734 if (dir->right == NULL)
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1735 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
1736 }
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1737
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1738 static void
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1739 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
1740 {
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1741 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
1742 return;
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1743 conn->to_disconnect =
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1744 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
1745 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
1746 }
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1747
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1748 static bool director_cmd_connect(struct director_connection *conn,
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1749 const char *const *args)
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1750 {
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1751 struct director *dir = conn->dir;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1752 struct director_host *host;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1753 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
1754 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
1755 const char *right_state;
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1756
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1757 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
1758 !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
1759 director_cmd_error(conn, "Invalid parameters");
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1760 return FALSE;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1761 }
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1762
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1763 host = director_host_get(conn->dir, &ip, port);
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1764
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1765 /* remote suggests us to connect elsewhere */
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1766 if (dir->right != NULL &&
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1767 director_host_cmp_to_self(host, dir->right->host,
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1768 dir->self_host) <= 0) {
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1769 /* 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
1770 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
1771 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
1772 director_reconnect_after_wrong_connect(conn);
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1773 return TRUE;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1774 }
22568
c50f46578b86 director: Ignore CONNECT requests to hosts that have been removed already
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22567
diff changeset
1775 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
1776 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
1777 host->name);
c50f46578b86 director: Ignore CONNECT requests to hosts that have been removed already
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22567
diff changeset
1778 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
1779 return TRUE;
c50f46578b86 director: Ignore CONNECT requests to hosts that have been removed already
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22567
diff changeset
1780 }
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1781
19973
0b5aeb95924a director: Avoid a potential assert-crash after removing a director from ring.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19954
diff changeset
1782 /* 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
1783 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
1784 /* 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
1785 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
1786
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
1787 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
1788 right_state = "initializing right";
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
1789 } else {
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
1790 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
1791 dir->right->name);
22567
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1792 /* 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
1793 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
1794 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
1795 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
1796 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
1797 conn->to_disconnect =
c27c8ce1d534 director: After CONNECT was received, make sure we disconnect
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22565
diff changeset
1798 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
1799 }
11579
61708c33154d director: Debug message improvements.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
1800 }
61708c33154d director: Debug message improvements.
Timo Sirainen <tss@iki.fi>
parents: 11572
diff changeset
1801
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
1802 /* connect here */
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
1803 (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
1804 "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
1805 conn->name, right_state));
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1806 return TRUE;
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1807 }
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1808
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1809 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
1810 {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1811 struct director_connection *const *connp, *conn;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1812
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1813 array_foreach(&dir->connections, connp) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1814 conn = *connp;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1815
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1816 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
1817 conn->to_disconnect == NULL &&
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1818 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
1819 dir->self_host) < 0)
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1820 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
1821 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1822 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1823
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1824 static bool director_cmd_ping(struct director_connection *conn,
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1825 const char *const *args)
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1826 {
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1827 time_t sent_time;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1828 uintmax_t send_buffer_size;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1829
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1830 if (str_array_length(args) >= 2 &&
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1831 str_to_time(args[0], &sent_time) == 0 &&
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1832 str_to_uintmax(args[1], &send_buffer_size) == 0) {
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1833 int diff_secs = ioloop_time - sent_time;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1834 if (diff_secs*1000+500 > DIRECTOR_CONNECTION_PINGPONG_WARN_MSECS) {
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1835 i_warning("director(%s): PING response took %d secs to receive "
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1836 "(send buffer was %ju bytes)",
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1837 conn->name, diff_secs, send_buffer_size);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1838 }
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1839 }
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1840 director_connection_send(conn,
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1841 t_strdup_printf("PONG\t%ld\t%zu\n",
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1842 (long)ioloop_time, o_stream_get_buffer_used_size(conn->output)));
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1843 return TRUE;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1844 }
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1845
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1846 static void
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1847 director_ping_append_extra(struct director_connection *conn, string_t *str,
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1848 time_t pong_sent_time,
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1849 uintmax_t pong_send_buffer_size)
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1850 {
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1851 struct rusage usage;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1852
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1853 str_printfa(str, "buffer size at PING was %zu bytes", conn->ping_sent_buffer_size);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1854 if (pong_sent_time != 0) {
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1855 str_printfa(str, ", remote sent it %ld secs ago",
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1856 (long)(ioloop_time - pong_sent_time));
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1857 }
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1858 if (pong_send_buffer_size != (uintmax_t)-1) {
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1859 str_printfa(str, ", remote buffer size at PONG was %ju bytes",
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1860 pong_send_buffer_size);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1861 }
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1862 if (conn->ping_sent_user_cpu.tv_sec != (time_t)-1 &&
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1863 getrusage(RUSAGE_SELF, &usage) == 0) {
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1864 int diff = timeval_diff_msecs(&usage.ru_utime,
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1865 &conn->ping_sent_user_cpu);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1866 str_printfa(str, ", %u.%03u CPU secs since PING was sent",
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1867 diff/1000, diff%1000);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1868 }
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1869 str_printfa(str, ", %"PRIuUOFF_T" bytes input",
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1870 conn->input->v_offset - conn->ping_sent_input_offset);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1871 str_printfa(str, ", %"PRIuUOFF_T" bytes output",
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1872 conn->output->offset - conn->ping_sent_output_offset);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1873 }
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1874
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1875 static bool director_cmd_pong(struct director_connection *conn,
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1876 const char *const *args)
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1877 {
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1878 time_t sent_time;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1879 uintmax_t send_buffer_size;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1880
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1881 if (!conn->ping_waiting)
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1882 return TRUE;
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
1883 conn->ping_waiting = FALSE;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1884 timeout_remove(&conn->to_pong);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1885
22689
ac58eecfb8b0 director: Fix logging of uninitialized PONG buffer size
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22684
diff changeset
1886 if (str_array_length(args) < 2 ||
ac58eecfb8b0 director: Fix logging of uninitialized PONG buffer size
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22684
diff changeset
1887 str_to_time(args[0], &sent_time) < 0 ||
ac58eecfb8b0 director: Fix logging of uninitialized PONG buffer size
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22684
diff changeset
1888 str_to_uintmax(args[1], &send_buffer_size) < 0) {
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1889 sent_time = 0;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1890 send_buffer_size = (uintmax_t)-1;
22689
ac58eecfb8b0 director: Fix logging of uninitialized PONG buffer size
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22684
diff changeset
1891 }
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1892
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
1893 int ping_msecs = timeval_diff_msecs(&ioloop_timeval, &conn->ping_sent_time);
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1894 if (ping_msecs >= 0) {
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1895 if (ping_msecs > DIRECTOR_CONNECTION_PINGPONG_WARN_MSECS) {
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1896 string_t *extra = t_str_new(128);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1897 director_ping_append_extra(conn, extra, sent_time, send_buffer_size);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1898 i_warning("director(%s): PONG response took %u.%03u secs (%s)",
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1899 conn->name, ping_msecs/1000, ping_msecs%1000,
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1900 str_c(extra));
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1901 }
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
1902 conn->last_ping_msecs = ping_msecs;
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1903 }
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
1904
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1905 if (conn->verifying_left) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1906 conn->verifying_left = FALSE;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1907 if (conn == conn->dir->left) {
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1908 /* 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
1909 incoming connections to connect to it instead. */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1910 director_disconnect_wrong_lefts(conn->dir);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1911 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1912 }
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1913
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
1914 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
1915 return TRUE;
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1916 }
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
1917
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1918 static bool
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1919 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
1920 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
1921 {
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1922 int ret;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1923
11327
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
1924 if (!conn->handshake_received) {
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1925 ret = director_connection_handle_handshake(conn, cmd, args);
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1926 if (ret > 0)
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1927 return TRUE;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1928 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
1929 /* 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
1930 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
1931 return FALSE;
9d886ae434c3 director: If connecting to director fails, try connecting to next one.
Timo Sirainen <tss@iki.fi>
parents: 11321
diff changeset
1932 }
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
1933 /* 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
1934 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1935
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1936 if (strcmp(cmd, "PING") == 0)
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1937 return director_cmd_ping(conn, args);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
1938 if (strcmp(cmd, "PONG") == 0)
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
1939 return director_cmd_pong(conn, args);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1940 if (strcmp(cmd, "USER") == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1941 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
1942 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
1943 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
1944 if (strcmp(cmd, "HOST") == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1945 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
1946 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
1947 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
1948 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
1949 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
1950 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
1951 return director_cmd_user_move(conn, args);
17418
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1952 if (strcmp(cmd, "USER-KICK") == 0)
64808a9703db doveadm director kick command added.
Timo Sirainen <tss@iki.fi>
parents: 17259
diff changeset
1953 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
1954 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
1955 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
1956 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
1957 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
1958 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
1959 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
1960 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
1961 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
1962 if (strcmp(cmd, "DIRECTOR") == 0)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1963 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
1964 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
1965 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
1966 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
1967 return director_connection_sync(conn, args);
11571
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1968 if (strcmp(cmd, "CONNECT") == 0)
75d5e31ea8cc director: Handle CONNECT commands (properly).
Timo Sirainen <tss@iki.fi>
parents: 11569
diff changeset
1969 return director_cmd_connect(conn, args);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1970 if (strcmp(cmd, "QUIT") == 0) {
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1971 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
1972 conn->name, t_strarray_join(args, " "));
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1973 return FALSE;
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
1974 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1975
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1976 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
1977 return FALSE;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1978 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1979
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1980 static bool
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1981 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
1982 char *line)
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1983 {
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1984 const char *cmd, *const *args;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1985 bool ret;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1986
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
1987 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
1988
22640
cf23a90cd2ca director: Use t_strsplit_tabescaped_inplace() for director connection input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22629
diff changeset
1989 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
1990 cmd = args[0];
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1991 if (cmd == NULL) {
14479
293ada796ae6 director: Fixed protocol error detection/handling.
Timo Sirainen <tss@iki.fi>
parents: 14478
diff changeset
1992 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
1993 return FALSE;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1994 }
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1995
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
1996 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
1997 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
1998 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
1999 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
2000 conn->cur_args = NULL;
14407
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
2001 return ret;
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
2002 }
d6cd93e32b37 director: Improved error logging for handling invalid commands/parameters.
Timo Sirainen <tss@iki.fi>
parents: 14406
diff changeset
2003
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2004 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
2005 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
2006 const char *errstr)
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2007 {
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2008 string_t *str = t_str_new(128);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2009
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2010 i_assert(conn->connected);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2011
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2012 if (conn->connect_request_to != NULL) {
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2013 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
2014 "should use %s instead",
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2015 conn->name, conn->connect_request_to->name);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2016 return;
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2017 }
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2018
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2019 str_printfa(str, "Director %s disconnected: ", conn->name);
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2020 str_append(str, "Connection closed");
16618
0ad8da149774 director: Log director disconnection errno correctly.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
2021 if (err != 0 && err != EPIPE) {
0ad8da149774 director: Log director disconnection errno correctly.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
2022 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
2023 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
2024 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
2025 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
2026 str_printfa(str, ": %s", errstr);
16618
0ad8da149774 director: Log director disconnection errno correctly.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
2027 }
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2028
22255
a841e797bac2 director: Fix whitespace position in some log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22254
diff changeset
2029 str_append(str, " (");
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
2030 director_connection_append_stats(conn, str);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2031
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2032 if (!conn->me_received)
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2033 str_append(str, ", handshake ME not received");
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2034 else if (!conn->handshake_received)
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2035 str_append(str, ", handshake DONE not received");
22692
281472b3bb20 director: Log whether connection is synced when it's being disconnected.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22691
diff changeset
2036 if (conn->synced)
281472b3bb20 director: Log whether connection is synced when it's being disconnected.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22691
diff changeset
2037 str_append(str, ", synced");
22253
9676f01a11df director: Log more connection state information on handshaking errors
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22252
diff changeset
2038 str_append_c(str, ')');
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2039 i_error("%s", str_c(str));
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2040 }
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2041
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2042 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
2043 {
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2044 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
2045 char *line;
18664
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
2046 uoff_t prev_offset;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2047 bool ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2048
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2049 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
2050 case 0:
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2051 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2052 case -1:
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2053 /* 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
2054 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
2055 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
2056 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
2057 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2058 case -2:
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2059 /* buffer full */
14479
293ada796ae6 director: Fixed protocol error detection/handling.
Timo Sirainen <tss@iki.fi>
parents: 14478
diff changeset
2060 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
2061 MAX_INBUF_SIZE);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2062 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
2063 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2064 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2065
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
2066 if (conn->to_disconnect != NULL) {
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
2067 /* 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
2068 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
2069 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
2070 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
2071 return;
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
2072 }
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2073 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
2074 conn->refcount++;
14494
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
2075
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2076 director_sync_freeze(dir);
18664
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
2077 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
2078 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
2079 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
2080 prev_offset = conn->input->v_offset;
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
2081
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2082 T_BEGIN {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2083 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
2084 } T_END;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2085
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2086 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
2087 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
2088 break;
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2089 director_connection_reconnect(&conn, t_strdup_printf(
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2090 "Invalid input: %s", line));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2091 break;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2092 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2093 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2094 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
2095 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
2096 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
2097 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
2098 }
11321
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
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2101 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
2102 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2103 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
2104 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
2105
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2106 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
2107 if ((*hostp)->removed)
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
2108 continue;
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2109
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2110 str_truncate(str, 0);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2111 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
2112 (*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
2113 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
2114 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2115 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2116
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
2117 static void
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2118 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
2119 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2120 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
2121 bool send_updowns;
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2122 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
2123
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2124 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
2125
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
2126 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
2127
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
2128 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
2129 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
2130 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
2131 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
2132
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
2133 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
2134 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
2135 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
2136 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
2137 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
2138 }
0ee3e734249a director: Added "up" vs "down" states and doveadm director up/down commands.
Timo Sirainen <tss@iki.fi>
parents: 18708
diff changeset
2139 if (send_updowns) {
19310
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
2140 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
2141 (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
2142 if (host->hostname != NULL)
7f718c840aff director: Remember backends' hostnames and send them in login reply.
Timo Sirainen <tss@iki.fi>
parents: 19309
diff changeset
2143 str_append_tabescaped(str, host->hostname);
18067
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
2144 }
a7e830b9b967 director: Added support for backend cluster "tags".
Timo Sirainen <tss@iki.fi>
parents: 18065
diff changeset
2145 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
2146 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
2147 str_truncate(str, 0);
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2148 }
11350
5f77c91f3df0 director: Preserve old mail server state when a new director connects to ring.
Timo Sirainen <tss@iki.fi>
parents: 11349
diff changeset
2149 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
2150 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
2151 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2152
18065
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2153 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
2154 {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2155 i_assert(conn->version_received);
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2156
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2157 if (!conn->dir->set->director_consistent_hashing)
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2158 ;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2159 else if (conn->minor_version >= DIRECTOR_VERSION_OPTIONS) {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2160 director_connection_send(conn,
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2161 "OPTIONS\t"DIRECTOR_OPT_CONSISTENT_HASHING"\n");
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2162 } else {
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2163 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
2164 conn->name);
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2165 return -1;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2166 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2167 director_connection_send(conn, "DONE\n");
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2168 return 0;
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2169 }
b9df3d654710 director: Added director_consistent_hashing setting.
Timo Sirainen <tss@iki.fi>
parents: 18063
diff changeset
2170
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2171 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
2172 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2173 struct user *user;
22646
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2174 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
2175 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
2176 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
2177 int ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2178
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2179 i_assert(conn->version_received);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2180
22672
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
2181 /* with new versions use "U" for sending the handshake users, because
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
2182 otherwise their parameters may look identical and can't be
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
2183 distinguished. */
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
2184 if (director_connection_get_minor_version(conn) >= DIRECTOR_VERSION_HANDSHAKE_U_CMD)
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
2185 str_append(str, "U\t");
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
2186 else
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
2187 str_append(str, "USER\t");
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
2188 size_t cmd_prefix_len = str_len(str);
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
2189 while ((user = director_iterate_users_next(conn->user_iter)) != NULL) {
22672
d811474ef901 director: Replace USER command during handshake with "U"
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22671
diff changeset
2190 str_truncate(str, cmd_prefix_len);
22646
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2191 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
2192 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
2193 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
2194 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
2195 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
2196 if (user->weak)
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2197 str_append(str, "\tw");
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2198 str_append_c(str, '\n');
22679
496ac7e7563f director: Include number of users sent in handshake in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22678
diff changeset
2199
496ac7e7563f director: Include number of users sent in handshake in disconnection log lines
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22678
diff changeset
2200 conn->handshake_users_sent++;
22646
340fd327a965 director: Avoid str_printfa() in director_connection_send_users()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22643
diff changeset
2201 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
2202 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
2203 /* 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
2204 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
2205 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
2206 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2207
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2208 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
2209 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
2210 /* continue later */
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2211 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
2212 return ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2213 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2214 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2215 }
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
2216 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
2217 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
2218 return -1;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2219
16621
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
2220 if (conn->users_unsorted && conn->handshake_received) {
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
2221 /* 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
2222 conn->users_unsorted = FALSE;
21079
d6f399a7f672 director: Keep per-tag directory
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21077
diff changeset
2223 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
2224 }
5ef62caea61b director: Update existing users' timestamps during handshake.
Timo Sirainen <tss@iki.fi>
parents: 16619
diff changeset
2225
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2226 ret = o_stream_flush(conn->output);
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2227 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
2228 return ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2229 }
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 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
2232 {
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2233 int ret;
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2234
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2235 conn->last_output = ioloop_timeval;
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2236 if (conn->user_iter != NULL) {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2237 /* still handshaking USER list */
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2238 o_stream_cork(conn->output);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2239 ret = director_connection_send_users(conn);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2240 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
2241 if (ret < 0) {
22694
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2242 director_connection_log_disconnect(conn, conn->output->stream_errno,
22693
a11fd794807e director: Log connection stats for all types of disconnections
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22692
diff changeset
2243 o_stream_get_error(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
2244 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
2245 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
2246 } else {
14480
d9f33d78fa3d director: Make sure handshaking doesn't get stuck sending USERs.
Timo Sirainen <tss@iki.fi>
parents: 14479
diff changeset
2247 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
2248 }
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2249 return ret;
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2250 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2251 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
2252 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2253
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2254 static struct director_connection *
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2255 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
2256 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2257 struct director_connection *conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2258
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2259 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
2260 conn->refcount = 1;
22252
8882a5cbe76d director: Use more accurate timestamps for handshake timeout logging
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22251
diff changeset
2261 conn->created = ioloop_timeval;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2262 conn->fd = fd;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2263 conn->dir = dir;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2264 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
2265 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
2266 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
2267 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
2268 return conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2269 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2270
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2271 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
2272 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2273 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
2274 "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
2275 "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
2276 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
2277 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
2278 (long long)time(NULL)));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2279 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2280
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2281 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
2282 {
22651
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2283 struct rusage usage;
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2284
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2285 conn->connected = TRUE;
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2286 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
2287
61402b07ad0a director: Include used CPU secs in director connection log messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22650
diff changeset
2288 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
2289 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
2290 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
2291 }
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2292 }
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2293
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2294 struct director_connection *
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2295 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
2296 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
2297 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2298 struct director_connection *conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2299
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2300 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
2301 conn->in = TRUE;
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2302 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
2303 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
2304 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
2305 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
2306 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
2307
22564
17b1e65e6d70 director: Log info line for every incoming/outgoing connection
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22562
diff changeset
2308 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
2309 director_connection_send_handshake(conn);
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2310 return conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2311 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2312
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2313 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
2314 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2315 int err;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2316
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2317 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
2318 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
2319 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
2320 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
2321 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2322 }
22650
e010a312c871 director: Deduplicate code into director_connection_set_connected()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22649
diff changeset
2323 director_connection_set_connected(conn);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2324 o_stream_set_flush_callback(conn->output,
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2325 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
2326
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2327 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
2328 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
2329
14477
ea5b949a623b director: Increased timeout for sending USER data in handshake.
Timo Sirainen <tss@iki.fi>
parents: 14476
diff changeset
2330 timeout_remove(&conn->to_ping);
22250
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
2331 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
2332 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
2333
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2334 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
2335 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
2336 director_connection_send_directors(conn);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2337 o_stream_uncork(conn->output);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2338 /* 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
2339 version number */
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2340 }
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2341
20972
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2342 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
2343 {
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2344 if (
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2345 conn->in) {
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2346 /* 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
2347 return;
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2348 }
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2349 o_stream_cork(conn->output);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2350 director_connection_send_hosts(conn);
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2351
14f621e65819 director: Fix sending up/down state in handshakes.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20971
diff changeset
2352 i_assert(conn->user_iter == NULL);
22676
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2353 /* Iterate only through users that aren't refreshed since the
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2354 iteration started. The refreshed users will already be sent as
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2355 regular USER updates, so they don't need to be sent again.
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2356
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2357 We especially don't want to send these users again, because
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2358 otherwise in a rapidly changing director we might never end up
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2359 sending all the users when they constantly keep being added to the
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2360 end of the list. (The iteration lists users in order from older to
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2361 newer.) */
c9549bea9106 director: Don't send USERs in handshake that were already sent between handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22674
diff changeset
2362 conn->user_iter = director_iterate_users_init(conn->dir, TRUE);
21075
6a363cb51d7f director: Code cleanup - added user director_iterate_users_*() wrappers.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21074
diff changeset
2363
14481
ce4e1bf7262d director: Another fix for stuck handshake.
Timo Sirainen <tss@iki.fi>
parents: 14480
diff changeset
2364 if (director_connection_send_users(conn) == 0)
ce4e1bf7262d director: Another fix for stuck handshake.
Timo Sirainen <tss@iki.fi>
parents: 14480
diff changeset
2365 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
2366
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2367 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
2368 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2369
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2370 struct director_connection *
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2371 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
2372 struct director_host *host)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2373 {
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2374 struct director_connection *conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2375
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
2376 i_assert(!host->removed);
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
2377
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2378 /* 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
2379 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
2380
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2381 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
2382 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
2383 conn->host = host;
14571
42cca8a1d179 director: Implemented ability to remove directors from a running ring.
Timo Sirainen <tss@iki.fi>
parents: 14570
diff changeset
2384 director_host_ref(host);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2385 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
2386 director_connection_connected, conn);
22250
81a74bce2b07 director: Fix handshake timeout lengths
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21842
diff changeset
2387 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
2388 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
2389 return conn;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2390 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2391
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2392 void director_connection_deinit(struct director_connection **_conn,
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2393 const char *remote_reason)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2394 {
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2395 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
2396 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
2397 unsigned int i, count;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2398
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2399 *_conn = NULL;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2400
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2401 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
2402
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2403 if (conn->host != NULL) {
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2404 dir_debug("Disconnecting from %s: %s",
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2405 conn->host->name, remote_reason);
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2406 }
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2407 if (*remote_reason != '\0' &&
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2408 conn->minor_version >= DIRECTOR_VERSION_QUIT) {
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2409 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
2410 "QUIT\t%s\n", remote_reason));
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2411 }
12935
e9139f74c451 director: Improved debug/error logging.
Timo Sirainen <tss@iki.fi>
parents: 12934
diff changeset
2412
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2413 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
2414 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
2415 if (conns[i] == conn) {
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2416 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
2417 break;
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2418 }
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2419 }
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2420 i_assert(i < count);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2421 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
2422 dir->left = NULL;
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2423 /* 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
2424 use it as the new "left" */
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2425 director_assign_left(dir);
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2426 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2427 if (dir->right == conn)
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2428 dir->right = NULL;
11572
659bb1a26da4 director: Added initial testing framework and some debugging output.
Timo Sirainen <tss@iki.fi>
parents: 11571
diff changeset
2429
22669
4c0e2030200a director: Make sure users are sorted after unfinished handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22668
diff changeset
2430 if (conn->users_unsorted) {
4c0e2030200a director: Make sure users are sorted after unfinished handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22668
diff changeset
2431 /* 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
2432 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
2433 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
2434 }
4c0e2030200a director: Make sure users are sorted after unfinished handshake
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22668
diff changeset
2435
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2436 if (conn->connect_request_to != NULL) {
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2437 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
2438 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
2439 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2440 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
2441 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
2442 if (conn->to_disconnect != NULL)
d27b743c9921 director: Delay disconnecting director after sending CONNECT command.
Timo Sirainen <tss@iki.fi>
parents: 14493
diff changeset
2443 timeout_remove(&conn->to_disconnect);
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2444 if (conn->to_pong != NULL)
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2445 timeout_remove(&conn->to_pong);
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2446 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
2447 if (conn->io != NULL)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2448 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
2449 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
2450 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
2451 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
2452
467ca06a7dbe director: Outgoing director connections shouldn't be counted as master clients.
Timo Sirainen <tss@iki.fi>
parents: 11373
diff changeset
2453 if (conn->in)
467ca06a7dbe director: Outgoing director connections shouldn't be counted as master clients.
Timo Sirainen <tss@iki.fi>
parents: 11373
diff changeset
2454 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
2455 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
2456
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2457 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
2458 /* 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
2459 dir->sync_seq++;
13921
c70965e8b27d director: If request is timed out, log an error.
Timo Sirainen <tss@iki.fi>
parents: 13053
diff changeset
2460 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
2461 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2462 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2463
22570
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2464 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
2465 {
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2466 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
2467 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
2468 return TRUE;
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2469
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2470 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
2471 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
2472 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
2473 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
2474 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
2475 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
2476 return FALSE;
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2477 }
39b2dd549e8a director: Don't crash if DIRECTOR-REMOVE is received for itself
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22568
diff changeset
2478
18858
8bde19f080ad director: explicitly mark _disconnect() helper static to match proto
Phil Carmody <phil@dovecot.fi>
parents: 18729
diff changeset
2479 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
2480 const char *reason)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2481 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2482 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
2483 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
2484
22446
8bfe8a2fed69 director: Fix rapid reconnection on failed outgoing connections
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22311
diff changeset
2485 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
2486 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
2487 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
2488 /* 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
2489 network problem */
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2490 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
2491 }
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2492
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
2493 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
2494 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
2495 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
2496 }
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2497
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2498 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
2499 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
2500 {
366b9e5fc85c director: Don't communicate with directors that recently sent invalid input.
Timo Sirainen <tss@iki.fi>
parents: 14431
diff changeset
2501 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
2502 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
2503
15132
27d3289e1f5c director: Improved logging related to disconnections.
Timo Sirainen <tss@iki.fi>
parents: 15131
diff changeset
2504 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
2505 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
2506 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
2507 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2508
22624
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2509 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
2510 {
22666
0b8c69533353 director: Reconnect after detecting a write failure to director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22651
diff changeset
2511 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
2512
22624
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2513 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
2514 if (dir->right == NULL)
0b8c69533353 director: Reconnect after detecting a write failure to director
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22651
diff changeset
2515 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
2516 }
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2517
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2518 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
2519 const char *data)
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2520 {
21322
5ab8dc1a4a6f global: Change string position/length from unsigned int to size_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21079
diff changeset
2521 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
2522 off_t ret;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2523
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2524 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
2525 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2526
15326
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2527 if (director_debug) T_BEGIN {
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2528 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
2529 for (; lines[1] != NULL; lines++)
48af47f2eb9c director: -D parameter now enables extensive debug logging.
Timo Sirainen <tss@iki.fi>
parents: 15324
diff changeset
2530 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
2531 } T_END;
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2532 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
2533 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
2534 if (ret < 0) {
22694
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2535 director_connection_log_disconnect(conn,
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2536 conn->output->stream_errno,
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2537 t_strdup_printf("write() failed: %s",
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2538 o_stream_get_error(conn->output)));
20264
0fd0fb05e2b3 global: Use [io]_stream_get_error() insted of %m
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19973
diff changeset
2539 } else {
22694
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2540 director_connection_log_disconnect(conn, EINVAL,
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2541 t_strdup_printf("Output buffer full at %zu",
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2542 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
2543 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2544 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
2545 /* 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
2546 disconnection itself. */
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2547 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
2548 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
2549 conn->to_disconnect =
f7e2f55e6e91 director: Close director connection immediately when output buffer is full
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22623
diff changeset
2550 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
2551 } else {
502755a1af5f director: Include useful statistics in process title.
Timo Sirainen <tss@iki.fi>
parents: 18663
diff changeset
2552 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
2553 conn->last_output = ioloop_timeval;
22627
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2554 conn->peak_bytes_buffered =
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2555 I_MAX(conn->peak_bytes_buffered,
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2556 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
2557 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2558 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2559
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2560 static void
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2561 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
2562 {
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2563 string_t *str = t_str_new(128);
22682
6fdc4e5710c8 director: Log exactly how long PING was waited on before it timed out.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22680
diff changeset
2564 int diff = timeval_diff_msecs(&ioloop_timeval, &conn->ping_sent_time);
20575
bceac5d8ae3b director: Added more debug information to "Ping timed out" error
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20295
diff changeset
2565
22693
a11fd794807e director: Log connection stats for all types of disconnections
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22692
diff changeset
2566 str_printfa(str, "Ping timed out in %u.%03u secs: ",
22682
6fdc4e5710c8 director: Log exactly how long PING was waited on before it timed out.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22680
diff changeset
2567 diff/1000, diff%1000);
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2568 director_ping_append_extra(conn, str, 0, (uintmax_t)-1);
22694
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2569 director_connection_log_disconnect(conn, EINVAL, 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
2570 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
2571 }
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2572
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2573 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
2574 {
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2575 int diff = timeval_diff_msecs(&ioloop_timeval, &conn->ping_sent_time);
22693
a11fd794807e director: Log connection stats for all types of disconnections
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22692
diff changeset
2576 const char *errstr;
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2577
22693
a11fd794807e director: Log connection stats for all types of disconnections
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22692
diff changeset
2578 errstr = t_strdup_printf(
a11fd794807e director: Log connection stats for all types of disconnections
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22692
diff changeset
2579 "PONG reply not received in %u.%03u secs, "
a11fd794807e director: Log connection stats for all types of disconnections
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22692
diff changeset
2580 "although other input keeps coming",
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2581 diff/1000, diff%1000);
22694
2cf68aa64129 director: Fix logging disconnection error reasons
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22693
diff changeset
2582 director_connection_log_disconnect(conn, EINVAL, errstr);
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
2583 director_connection_disconnected(&conn, "Pong timeout");
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2584 }
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2585
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2586 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
2587 {
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
2588 if (conn->ping_waiting)
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2589 return;
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2590
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2591 timeout_remove(&conn->to_ping);
22683
5f9ff9066649 director: Add director_ping_idle/max_timeout setting.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22682
diff changeset
2592 conn->to_ping = timeout_add(conn->dir->set->director_ping_idle_timeout*1000,
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2593 director_connection_ping_idle_timeout, conn);
22683
5f9ff9066649 director: Add director_ping_idle/max_timeout setting.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22682
diff changeset
2594 conn->to_pong = timeout_add(conn->dir->set->director_ping_max_timeout*1000,
14409
b43ae3805f5f director: Redesigned connection handling and error handling.
Timo Sirainen <tss@iki.fi>
parents: 14408
diff changeset
2595 director_connection_pong_timeout, conn);
11586
e75dab14bb2f director: Send PINGs every 15 seconds for idling director connections.
Timo Sirainen <tss@iki.fi>
parents: 11585
diff changeset
2596 conn->ping_waiting = TRUE;
22628
8623737c0129 director: Track connections' last ping time
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22627
diff changeset
2597 conn->ping_sent_time = ioloop_timeval;
22684
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2598 conn->ping_sent_buffer_size = o_stream_get_buffer_used_size(conn->output);
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2599 conn->ping_sent_input_offset = conn->input->v_offset;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2600 conn->ping_sent_output_offset = conn->output->offset;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2601
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2602 struct rusage usage;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2603 if (getrusage(RUSAGE_SELF, &usage) == 0)
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2604 conn->ping_sent_user_cpu = usage.ru_utime;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2605 else
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2606 conn->ping_sent_user_cpu.tv_sec = (time_t)-1;
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2607 /* send it after getting the buffer size */
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2608 director_connection_send(conn, t_strdup_printf(
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2609 "PING\t%ld\t%zu\n", (long)ioloop_time,
d3d8164a2083 director: Improve PING/PONG timeout errors and add new warnings
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22683
diff changeset
2610 conn->ping_sent_buffer_size));
11321
5f350b5ff6d9 Added initial implementation of a director process (for NFS users).
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2611 }
11585
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
2612
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
2613 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
2614 {
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
2615 return conn->name;
f0fb8151c6b4 director: A lot of fixes.
Timo Sirainen <tss@iki.fi>
parents: 11581
diff changeset
2616 }
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2617
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2618 struct director_host *
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2619 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
2620 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2621 return conn->host;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2622 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2623
14408
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2624 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
2625 {
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2626 return conn->handshake_received;
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2627 }
544a8c4705e5 director: Handle all commands during handshake.
Timo Sirainen <tss@iki.fi>
parents: 14407
diff changeset
2628
18062
ade6dcace5cd doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
2629 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
2630 {
ade6dcace5cd doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
2631 return conn->synced;
ade6dcace5cd doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
2632 }
ade6dcace5cd doveadm director ring status shows now more information
Timo Sirainen <tss@iki.fi>
parents: 17419
diff changeset
2633
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2634 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
2635 {
14406
c760ac046203 director: List of director connections belongs to struct director.
Timo Sirainen <tss@iki.fi>
parents: 14405
diff changeset
2636 return conn->in;
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2637 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2638
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
2639 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
2640 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
2641 {
084064444f89 director: Don't try to send the new SYNC parameter to old director versions.
Timo Sirainen <tss@iki.fi>
parents: 14409
diff changeset
2642 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
2643 }
084064444f89 director: Don't try to send the new SYNC parameter to old director versions.
Timo Sirainen <tss@iki.fi>
parents: 14409
diff changeset
2644
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2645 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
2646 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2647 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
2648 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2649
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2650 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
2651 {
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2652 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
2653 }
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2654
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2655 void director_connection_set_synced(struct director_connection *conn,
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2656 bool synced)
11629
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2657 {
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2658 if (conn->synced == synced)
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2659 return;
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2660 conn->synced = synced;
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2661
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2662 /* 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
2663 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
2664 return;
a07aa85f68c9 director: Lots of fixes. It should be pretty stable now.
Timo Sirainen <tss@iki.fi>
parents: 11598
diff changeset
2665
14405
168e3b5cb6e8 director: Changes to PING handling.
Timo Sirainen <tss@iki.fi>
parents: 14310
diff changeset
2666 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
2667 }
22627
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2668
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2669 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
2670 struct director_connection_status *status_r)
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2671 {
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2672 i_zero(status_r);
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2673 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
2674 status_r->bytes_sent = conn->output->offset;
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2675 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
2676 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
2677 status_r->last_input = conn->last_input;
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2678 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
2679 status_r->last_ping_msecs = conn->last_ping_msecs;
22680
21e9717ba702 director: DIRECTOR-LIST - Show number of USERs sent/received in "handshaking" state
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22679
diff changeset
2680 status_r->handshake_users_sent = conn->handshake_users_sent;
21e9717ba702 director: DIRECTOR-LIST - Show number of USERs sent/received in "handshaking" state
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22679
diff changeset
2681 status_r->handshake_users_received = conn->handshake_users_received;
22627
bcb064465b54 director: Add director_connection_get_status()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22626
diff changeset
2682 }