comparison src/director/user-directory.c @ 22675:d689d7d99b4f

director: Delay sorting users until there are no more user iterators This shouldn't have normally happened. Only when an outgoing handshake was going on at the same time as a) another outgoing handshake was going on, or b) doveadm was doing HOST-RESET-USERS
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sat, 25 Nov 2017 10:05:27 +0200
parents a96fa917ced1
children c9549bea9106
comparison
equal deleted inserted replaced
22674:af1a9f282179 22675:d689d7d99b4f
33 /* If user's expire time is less than this many seconds away, 33 /* If user's expire time is less than this many seconds away,
34 don't assume that other directors haven't yet expired it */ 34 don't assume that other directors haven't yet expired it */
35 unsigned int user_near_expiring_secs; 35 unsigned int user_near_expiring_secs;
36 struct timeout *to_expire; 36 struct timeout *to_expire;
37 time_t to_expire_timestamp; 37 time_t to_expire_timestamp;
38
39 bool sort_pending;
38 }; 40 };
39 41
40 static void user_move_iters(struct user_directory *dir, struct user *user) 42 static void user_move_iters(struct user_directory *dir, struct user *user)
41 { 43 {
42 struct user_directory_iter *const *iterp; 44 struct user_directory_iter *const *iterp;
197 { 199 {
198 ARRAY(struct user *) users; 200 ARRAY(struct user *) users;
199 struct user *user, *const *userp; 201 struct user *user, *const *userp;
200 unsigned int i, users_count = hash_table_count(dir->hash); 202 unsigned int i, users_count = hash_table_count(dir->hash);
201 203
204 dir->sort_pending = FALSE;
205
202 if (users_count == 0) { 206 if (users_count == 0) {
203 i_assert(dir->head == NULL); 207 i_assert(dir->head == NULL);
208 return;
209 }
210
211 if (array_count(&dir->iters) > 0) {
212 /* We can't sort the directory while there are iterators
213 or they'll skip users. Do the sort after there are no more
214 iterators. */
215 dir->sort_pending = TRUE;
204 return; 216 return;
205 } 217 }
206 218
207 /* place all users into array and sort it */ 219 /* place all users into array and sort it */
208 i_array_init(&users, users_count); 220 i_array_init(&users, users_count);
316 if (iters[i] == iter) { 328 if (iters[i] == iter) {
317 array_delete(&iter->dir->iters, i, 1); 329 array_delete(&iter->dir->iters, i, 1);
318 break; 330 break;
319 } 331 }
320 } 332 }
333 if (array_count(&iter->dir->iters) == 0 && iter->dir->sort_pending)
334 user_directory_sort(iter->dir);
321 i_free(iter); 335 i_free(iter);
322 } 336 }