]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
indexer: worker - Fix busy/free status
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 6 May 2021 11:55:55 +0000 (14:55 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 14 Jun 2021 14:56:40 +0000 (17:56 +0300)
Determining whether worker is free or not should be determined
using worker_connection_is_busy, not whether there are
connections in the list.

A worker connection is busy when it has a request.

src/indexer/indexer.c
src/indexer/worker-pool.c

index 092c5faf582cd79e021a7fc19f7e1d2b092cf50b..508c185512b595c23c722fc62e6ff1710157c213 100644 (file)
@@ -66,7 +66,7 @@ static void queue_try_send_more(struct indexer_queue *queue)
        while ((request = indexer_queue_request_peek(queue)) != NULL) {
                conn = worker_pool_find_username_connection(worker_pool,
                                                            request->username);
-               if (conn != NULL) {
+               if (conn != NULL && worker_connection_is_busy(conn)) {
                        /* There is already a connection handling a request
                         * for this user. Move the request to the back of the
                         * queue and handle requests from other users.
@@ -80,12 +80,11 @@ static void queue_try_send_more(struct indexer_queue *queue)
                                first_moved_request = request;
                        indexer_queue_move_head_to_tail(queue);
                        continue;
+               } else if (conn == NULL) {
+                       /* create a new connection to a worker */
+                       if (!worker_pool_get_connection(worker_pool, &conn))
+                               break;
                }
-
-               /* create a new connection to a worker */
-               if (!worker_pool_get_connection(worker_pool, &conn))
-                       break;
-
                indexer_queue_request_remove(queue);
                worker_send_request(conn, request);
        }
index 5fc380330b72a7888e9afc00e367be8c192bf5d1..6367265885dc9f971a995589c1b8ffac64509c2e 100644 (file)
@@ -45,7 +45,11 @@ void worker_pool_deinit(struct worker_pool **_pool)
 
 bool worker_pool_have_busy_connections(struct worker_pool *pool)
 {
-       return pool->connection_list->connections_count > 0;
+       struct connection *list;
+       for (list = pool->connection_list->connections; list != NULL; list = list->next)
+               if (worker_connection_is_busy(list))
+                       return TRUE;
+       return FALSE;
 }
 
 static int worker_pool_add_connection(struct worker_pool *pool,