]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts: Send session ID to indexer and indexer-worker for logging purposes.
authorTimo Sirainen <tss@iki.fi>
Mon, 21 Sep 2015 14:01:05 +0000 (17:01 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 21 Sep 2015 14:01:05 +0000 (17:01 +0300)
src/indexer/indexer-client.c
src/indexer/indexer-queue.c
src/indexer/indexer-queue.h
src/indexer/master-connection.c
src/indexer/worker-connection.c
src/plugins/fts/fts-indexer.c
src/plugins/fts/fts-storage.c

index a03b80ee8005b173c537932b4c48a351a6f90c10..0a34b0b0ee925fad4dc6212335ef8041ab130fce 100644 (file)
@@ -67,9 +67,10 @@ indexer_client_request_queue(struct indexer_client *client, bool append,
                             const char *const *args, const char **error_r)
 {
        struct indexer_client_request *ctx = NULL;
+       const char *session_id = NULL;
        unsigned int tag, max_recent_msgs;
 
-       /* <tag> <user> <mailbox> [<max_recent_msgs>] */
+       /* <tag> <user> <mailbox> [<max_recent_msgs> [<session ID>]] */
        if (str_array_length(args) < 3) {
                *error_r = "Wrong parameter count";
                return -1;
@@ -83,6 +84,8 @@ indexer_client_request_queue(struct indexer_client *client, bool append,
        else if (str_to_uint(args[3], &max_recent_msgs) < 0) {
                *error_r = "Invalid max_recent_msgs";
                return -1;
+       } else {
+               session_id = args[4];
        }
 
        if (tag != 0) {
@@ -93,7 +96,7 @@ indexer_client_request_queue(struct indexer_client *client, bool append,
        }
 
        indexer_queue_append(client->queue, append, args[1], args[2],
-                            max_recent_msgs, ctx);
+                            session_id, max_recent_msgs, ctx);
        o_stream_nsend_str(client->output, t_strdup_printf("%u\tOK\n", tag));
        return 0;
 }
index 7397b88d80dbfb16a2589cd7162956b0de81f56d..880f88b1492c3976e941819f2da2feed3614eec8 100644 (file)
@@ -82,6 +82,7 @@ static void request_add_context(struct indexer_request *request, void *context)
 static struct indexer_request *
 indexer_queue_append_request(struct indexer_queue *queue, bool append,
                             const char *username, const char *mailbox,
+                            const char *session_id,
                             unsigned int max_recent_msgs, void *context)
 {
        struct indexer_request *request;
@@ -91,6 +92,7 @@ indexer_queue_append_request(struct indexer_queue *queue, bool append,
                request = i_new(struct indexer_request, 1);
                request->username = i_strdup(username);
                request->mailbox = i_strdup(mailbox);
+               request->session_id = i_strdup(session_id);
                request->max_recent_msgs = max_recent_msgs;
                request_add_context(request, context);
                hash_table_insert(queue->requests, request, request);
@@ -130,12 +132,14 @@ static void indexer_queue_append_finish(struct indexer_queue *queue)
 
 void indexer_queue_append(struct indexer_queue *queue, bool append,
                          const char *username, const char *mailbox,
-                         unsigned int max_recent_msgs, void *context)
+                         const char *session_id, unsigned int max_recent_msgs,
+                         void *context)
 {
        struct indexer_request *request;
 
        request = indexer_queue_append_request(queue, append, username, mailbox,
-                                              max_recent_msgs, context);
+                                              session_id, max_recent_msgs,
+                                              context);
        request->index = TRUE;
        indexer_queue_append_finish(queue);
 }
@@ -147,7 +151,7 @@ void indexer_queue_append_optimize(struct indexer_queue *queue,
        struct indexer_request *request;
 
        request = indexer_queue_append_request(queue, TRUE, username, mailbox,
-                                              0, context);
+                                              NULL, 0, context);
        request->optimize = TRUE;
        indexer_queue_append_finish(queue);
 }
index 7cdeaaf0f7cf1da54230e7ef21706e71f27e8fbe..aeddabcec89ccb71d84f84e167585961414a398a 100644 (file)
@@ -8,6 +8,7 @@ struct indexer_request {
 
        char *username;
        char *mailbox;
+       char *session_id;
        unsigned int max_recent_msgs;
 
        /* index messages in this mailbox */
@@ -38,7 +39,8 @@ void indexer_queue_set_listen_callback(struct indexer_queue *queue,
        
 void indexer_queue_append(struct indexer_queue *queue, bool append,
                          const char *username, const char *mailbox,
-                         unsigned int max_recent_msgs, void *context);
+                         const char *session_id, unsigned int max_recent_msgs,
+                         void *context);
 void indexer_queue_append_optimize(struct indexer_queue *queue,
                                   const char *username, const char *mailbox,
                                   void *context);
index 306d186fa986c1966b64036d909c24407e54e938..a0b13f433aaf33f8888cedc86fe23997249ed29b 100644 (file)
@@ -201,9 +201,9 @@ master_connection_input_line(struct master_connection *conn, const char *line)
        unsigned int max_recent_msgs;
        int ret;
 
-       /* <username> <mailbox> <max_recent_msgs> [i][o] */
-       if (str_array_length(args) != 4 ||
-           str_to_uint(args[2], &max_recent_msgs) < 0 || args[3][0] == '\0') {
+       /* <username> <mailbox> <session ID> <max_recent_msgs> [i][o] */
+       if (str_array_length(args) != 5 ||
+           str_to_uint(args[3], &max_recent_msgs) < 0 || args[4][0] == '\0') {
                i_error("Invalid input from master: %s", line);
                return -1;
        }
@@ -212,6 +212,7 @@ master_connection_input_line(struct master_connection *conn, const char *line)
        input.module = "mail";
        input.service = "indexer-worker";
        input.username = args[0];
+       input.session_id = args[2][0] == '\0' ? NULL : args[2];
 
        if (mail_storage_service_lookup_next(conn->storage_service, &input,
                                             &service_user, &user, &error) <= 0) {
@@ -220,7 +221,7 @@ master_connection_input_line(struct master_connection *conn, const char *line)
        } else {
                indexer_worker_refresh_proctitle(user->username, args[1], 0, 0);
                ret = index_mailbox(conn, user, args[1],
-                                   max_recent_msgs, args[3]);
+                                   max_recent_msgs, args[4]);
                indexer_worker_refresh_proctitle(NULL, NULL, 0, 0);
                mail_user_unref(&user);
                mail_storage_service_user_free(&service_user);
index 4f542b9f05627d26c91bf5e79a3e0302090481cc..9644fec55da804cb9201a746144932348354c178 100644 (file)
@@ -241,6 +241,9 @@ void worker_connection_request(struct worker_connection *conn,
                str_append_tabescaped(str, request->username);
                str_append_c(str, '\t');
                str_append_tabescaped(str, request->mailbox);
+               str_append_c(str, '\t');
+               if (request->session_id != NULL)
+                       str_append_tabescaped(str, request->session_id);
                str_printfa(str, "\t%u\t", request->max_recent_msgs);
                if (request->index)
                        str_append_c(str, 'i');
index 76283dcf0492b321597b226ac19a59acd47f84eb..6ec686662eba1c62d7a42d32218a37e5de872aba 100644 (file)
@@ -113,9 +113,10 @@ int fts_indexer_init(struct fts_backend *backend, struct mailbox *box,
                return 0;
        }
 
-       cmd = t_strdup_printf("PREPEND\t1\t%s\t%s\n",
+       cmd = t_strdup_printf("PREPEND\t1\t%s\t%s\t0\t%s\n",
                              str_tabescape(box->storage->user->username),
-                             str_tabescape(box->vname));
+                             str_tabescape(box->vname),
+                             str_tabescape(box->storage->user->session_id));
        fd = fts_indexer_cmd(box->storage->user, cmd, &path);
        if (fd == -1)
                return -1;
index ea972ec6ebf3fe1c21c354fcaaeac6e6aa67ff23..ef73507b8e7fcd42bc3c82074cf2cd0e703d3e40 100644 (file)
@@ -612,7 +612,10 @@ static void fts_queue_index(struct mailbox *box)
        str_append_tabescaped(str, user->username);
        str_append_c(str, '\t');
        str_append_tabescaped(str, box->vname);
-       str_printfa(str, "\t%u\n", max_recent_msgs);
+       str_printfa(str, "\t%u", max_recent_msgs);
+       str_append_c(str, '\t');
+       str_append_tabescaped(str, box->storage->user->session_id);
+       str_append_c(str, '\n');
        if (write_full(fd, str_data(str), str_len(str)) < 0)
                i_error("write(%s) failed: %m", path);
        i_close_fd(&fd);