From: Siavash Tavakoli Date: Mon, 14 Dec 2020 21:39:39 +0000 (+0000) Subject: indexer: Disconnect from indexer-worker after each request X-Git-Tag: 2.3.14.rc1~101 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1e8fc75ecf85118fe226072652aa7ab9cf7b1697;p=thirdparty%2Fdovecot%2Fcore.git indexer: Disconnect from indexer-worker after each request This allows indexer-worker to properly handle service configurations such as service_count and idle_kill time. --- diff --git a/src/indexer/indexer-worker.c b/src/indexer/indexer-worker.c index 6de6c27430..4f75dd4c5e 100644 --- a/src/indexer/indexer-worker.c +++ b/src/indexer/indexer-worker.c @@ -8,7 +8,6 @@ #include "master-service-settings.h" #include "master-connection.h" -static struct master_connection *master_conn; static struct mail_storage_service_ctx *storage_service; static void client_connected(struct master_service_connection *conn) @@ -77,7 +76,7 @@ int main(int argc, char *argv[]) master_service_run(master_service, client_connected); if (master_conn != NULL) - master_connection_destroy(&master_conn); + master_connection_destroy(); mail_storage_service_deinit(&storage_service); master_service_deinit(&master_service); return 0; diff --git a/src/indexer/master-connection.c b/src/indexer/master-connection.c index 304c784534..56da061a4c 100644 --- a/src/indexer/master-connection.c +++ b/src/indexer/master-connection.c @@ -22,6 +22,8 @@ #define INDEXER_WORKER_HANDSHAKE "VERSION\tindexer-worker-master\t1\t0\n%u\n" #define INDEXER_MASTER_NAME "indexer-master-worker" +struct master_connection *master_conn; + struct master_connection { struct mail_storage_service_ctx *storage_service; @@ -264,7 +266,7 @@ static void master_connection_input(struct master_connection *conn) int ret; if (i_stream_read(conn->input) < 0) { - master_service_stop(master_service); + master_connection_destroy(); return; } @@ -276,7 +278,7 @@ static void master_connection_input(struct master_connection *conn) INDEXER_PROTOCOL_MAJOR_VERSION)) { i_error("Indexer master not compatible with this master " "(mixed old and new binaries?)"); - master_service_stop(master_service); + master_connection_destroy(); return; } conn->version_received = TRUE; @@ -287,7 +289,7 @@ static void master_connection_input(struct master_connection *conn) ret = master_connection_input_line(conn, line); } T_END; if (ret < 0) { - master_service_stop(master_service); + master_connection_destroy(); break; } } @@ -311,11 +313,11 @@ master_connection_create(int fd, struct mail_storage_service_ctx *storage_servic return conn; } -void master_connection_destroy(struct master_connection **_conn) +void master_connection_destroy(void) { - struct master_connection *conn = *_conn; + struct master_connection *conn = master_conn; - *_conn = NULL; + master_conn = NULL; io_remove(&conn->io); i_stream_destroy(&conn->input); diff --git a/src/indexer/master-connection.h b/src/indexer/master-connection.h index 75801e73e5..85ac344695 100644 --- a/src/indexer/master-connection.h +++ b/src/indexer/master-connection.h @@ -1,8 +1,10 @@ #ifndef MASTER_CONNECTION_H #define MASTER_CONNECTION_H +extern struct master_connection *master_conn; + struct master_connection * master_connection_create(int fd, struct mail_storage_service_ctx *storage_service); -void master_connection_destroy(struct master_connection **conn); +void master_connection_destroy(void); #endif diff --git a/src/indexer/worker-connection.c b/src/indexer/worker-connection.c index b784915ba5..558c60934a 100644 --- a/src/indexer/worker-connection.c +++ b/src/indexer/worker-connection.c @@ -118,6 +118,11 @@ worker_connection_input_line(struct worker_connection *conn, const char *line) { void *const *contextp, *context; int percentage; + /* return -1 -> error + 0 -> request completed (100%) + 1 -> request continues (<100%) + */ + int ret = 1; if (aqueue_count(conn->request_queue) == 0) { i_error("Input from worker without pending requests: %s", line); @@ -138,10 +143,14 @@ worker_connection_input_line(struct worker_connection *conn, const char *line) aqueue_delete_tail(conn->request_queue); if (aqueue_count(conn->request_queue) == 0) i_free_and_null(conn->request_username); + if (percentage < 0) + ret = -1; + else + ret = 0; } conn->callback(percentage, context); - return 0; + return ret; } static void worker_connection_input(struct worker_connection *conn) @@ -179,7 +188,7 @@ static void worker_connection_input(struct worker_connection *conn) } while ((line = i_stream_next_line(conn->input)) != NULL) { - if (worker_connection_input_line(conn, line) < 0) { + if (worker_connection_input_line(conn, line) <= 0) { worker_connection_disconnect(conn); break; }