From: Timo Sirainen Date: Tue, 7 Sep 2021 12:47:23 +0000 (+0300) Subject: indexer: Fix tracking indexer-worker's process_limit X-Git-Tag: 2.3.17~127 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9718957b84f18ab53d185bc244db7c7275a05bd6;p=thirdparty%2Fdovecot%2Fcore.git indexer: Fix tracking indexer-worker's process_limit After recent changes, the process_limit was too often thought to be 1. --- diff --git a/src/indexer/worker-connection.c b/src/indexer/worker-connection.c index d50655f0a3..9d23f652e5 100644 --- a/src/indexer/worker-connection.c +++ b/src/indexer/worker-connection.c @@ -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, diff --git a/src/indexer/worker-connection.h b/src/indexer/worker-connection.h index c307a63fd5..aea46e0860 100644 --- a/src/indexer/worker-connection.h +++ b/src/indexer/worker-connection.h @@ -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 diff --git a/src/indexer/worker-pool.c b/src/indexer/worker-pool.c index 16f8feb6e3..991aaabee5 100644 --- a/src/indexer/worker-pool.c +++ b/src/indexer/worker-pool.c @@ -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)