annotate src/director/director-connection.c @ 22683:5f9ff9066649

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