]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
indexer: Disconnect from indexer-worker after each request
authorSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Mon, 14 Dec 2020 21:39:39 +0000 (21:39 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 15 Jan 2021 18:14:24 +0000 (18:14 +0000)
This allows indexer-worker to properly handle service configurations such as
service_count and idle_kill time.

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

index 6de6c274307c8d92a1c815f462b8afab1ae0ebb1..4f75dd4c5e7c27b0be45dd6e68b3891a662478b8 100644 (file)
@@ -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;
index 304c7845349eda8a52e539784df88f830c6513a2..56da061a4cbb5bd50b40a23828abe20521a190ae 100644 (file)
@@ -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);
index 75801e73e5953f867bb2058ee1bd2168c60b70ef..85ac344695e1df4068df1b2adb137712ce2c8569 100644 (file)
@@ -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
index b784915ba560cce37bd813c423d7b9f607190472..558c60934ac6683566af5e18a536c62937961b8e 100644 (file)
@@ -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;
                }