]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
indexer: Fix tracking indexer-worker's process_limit
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 7 Sep 2021 12:47:23 +0000 (15:47 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 15 Sep 2021 10:14:44 +0000 (10:14 +0000)
After recent changes, the process_limit was too often thought to be 1.

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

index d50655f0a3af33add4317151e1f5a4990f9dd20a..9d23f652e5b62e613ca6d0552ca94e8d24ff4a15 100644 (file)
@@ -29,10 +29,10 @@ struct worker_connection {
 
        char *request_username;
        struct indexer_request *request;
-
-       unsigned int process_limit;
 };
 
+static unsigned int worker_last_process_limit = 0;
+
 static void worker_connection_call_callback(struct worker_connection *worker,
                                            int percentage)
 {
@@ -56,8 +56,7 @@ void worker_connection_destroy(struct connection *conn)
 static int
 worker_connection_handshake_args(struct connection *conn, const char *const *args)
 {
-       struct worker_connection *worker =
-               container_of(conn, struct worker_connection, conn);
+       unsigned int process_limit;
        int ret;
        if (!conn->version_received) {
                if ((ret = connection_handshake_args_default(conn, args)) < 1)
@@ -65,13 +64,13 @@ worker_connection_handshake_args(struct connection *conn, const char *const *arg
                /* we are not done yet */
                return 0;
        }
-       i_assert(worker->process_limit == 0);
-       if (str_to_uint(args[0], &worker->process_limit) < 0 ||
-           worker->process_limit == 0) {
+       if (str_to_uint(args[0], &process_limit) < 0 ||
+           process_limit == 0) {
                e_error(conn->event, "Worker sent invalid process limit '%s'",
                        args[0]);
                return -1;
        }
+       worker_last_process_limit = process_limit;
        return 1;
 }
 
@@ -102,17 +101,9 @@ bool worker_connection_is_connected(struct connection *conn)
        return !conn->disconnected;
 }
 
-bool worker_connection_get_process_limit(struct connection *conn,
-                                        unsigned int *limit_r)
+unsigned int worker_connections_get_process_limit(void)
 {
-       struct worker_connection *worker =
-               container_of(conn, struct worker_connection, conn);
-
-       if (worker->process_limit == 0)
-               return FALSE;
-
-       *limit_r = worker->process_limit;
-       return TRUE;
+       return worker_last_process_limit;
 }
 
 void worker_connection_request(struct connection *conn,
index c307a63fd50c516d8d6befb03fe4a83b5aeac2e6..aea46e0860266302f34bbf3dd30d4d39b549b1f3 100644 (file)
@@ -17,11 +17,9 @@ struct connection_list *worker_connection_list_create(void);
 /* Returns TRUE if worker is connected to (not necessarily handshaked yet) */
 bool worker_connection_is_connected(struct connection *conn);
 
-/* After initial handshake the worker process tells how many of its kind
-   can be at maximum. This returns the value, of FALSE if handshake isn't
-   finished yet. */
-bool worker_connection_get_process_limit(struct connection *conn,
-                                        unsigned int *limit_r);
+/* Returns the last process_limit returned by a worker connection handshake.
+   If no handshakes have been received yet, returns 0. */
+unsigned int worker_connections_get_process_limit(void);
 
 /* Send a new indexing request for username+mailbox. The status callback is
    called as necessary with the given context. Requests can be queued, but
index 16f8feb6e334d0c774be0edca96574e4aad1c1b1..991aaabee56b03b2dadd01534c5bcd205da7e009 100644 (file)
@@ -68,29 +68,12 @@ static int worker_pool_add_connection(struct worker_pool *pool,
        return 0;
 }
 
-static unsigned int worker_pool_find_max_connections(struct worker_pool *pool)
-{
-       struct connection *list;
-       unsigned int limit;
-
-       if (pool->connection_list->connections == NULL)
-               return 1;
-
-       for (list = pool->connection_list->connections; list != NULL; list = list->next) {
-               if (worker_connection_get_process_limit(list, &limit))
-                       return limit;
-       }
-       /* we have at least one connection that has already been created,
-          but without having handshaked yet. wait until it's finished. */
-       return 0;
-}
-
 bool worker_pool_get_connection(struct worker_pool *pool,
                                struct connection **conn_r)
 {
        unsigned int max_connections;
 
-       max_connections = worker_pool_find_max_connections(pool);
+       max_connections = I_MAX(1, worker_connections_get_process_limit());
        if (pool->connection_list->connections_count >= max_connections)
                return FALSE;
        if (worker_pool_add_connection(pool, conn_r) < 0)