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