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