fulltext: after the indexer runs for 60 seconds (tunable), yield the thread
authorArt Cancro <ajc@citadel.org>
Fri, 1 Sep 2023 15:07:42 +0000 (15:07 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 1 Sep 2023 15:07:42 +0000 (15:07 +0000)
citadel/server/modules/fulltext/serv_fulltext.c
citadel/server/modules/fulltext/serv_fulltext.h

index 7f7dd7959b2a984eb91eb41e1873fed92bcf45ab..ea374542e4ac3150a8574845e0fefc3d82f2b0c8 100644 (file)
@@ -34,7 +34,6 @@
 #include "../../context.h"
 #include "../../ctdl_module.h"
 
-
 // These can be global variables because only one indexer runs at a time.
 Array *messages_to_be_indexed = NULL;
 long highest_msg_already_indexed = 0;
@@ -226,6 +225,7 @@ void do_fulltext_indexing(void) {
        // Here it is ... do each message!
        long msgnum = 0;
        long prev_msgnum = 0;
+       time_t started_indexing_at = time(NULL);
        for (i=0; i<array_len(messages_to_be_indexed); ++i) {
                memcpy(&msgnum, array_get_element_at(messages_to_be_indexed, i), sizeof(long));
 
@@ -234,6 +234,10 @@ void do_fulltext_indexing(void) {
                }
 
                prev_msgnum = msgnum;
+               if (time(NULL) - started_indexing_at >= MAXIMUM_INDEXER_RUN_TIME) {
+                       syslog(LOG_DEBUG, "fulltext: indexer has run for %ld seconds; yielding the thread", time(NULL) - started_indexing_at);
+                       i = array_len(messages_to_be_indexed);          // go out of scope to make it stop
+               }
        }
 
        array_free(messages_to_be_indexed);
@@ -344,7 +348,7 @@ char *ctdl_module_init_fulltext(void) {
        if (!threading) {
                CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
                CtdlRegisterDeleteHook(ft_delete_remove);
-               CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER, PRIO_CLEANUP + 300);
+               CtdlRegisterSessionHook(do_fulltext_indexing, EVT_HOUSE, PRIO_CLEANUP + 300);
        }
        // return our module name for the log
        return "fulltext";
index e96a8f60c6945b0ffabb180c77e72233e1aa143d..32f5d5f996870bc8c4a0d9fa26eaed2cc6400de0 100644 (file)
@@ -5,3 +5,7 @@
 
 void ft_index_message(long msgnum, int op);
 Array *CtdlFullTextSearch(const char *search_string);
+
+// After this many seconds, the indexer will stop and yield the housekeeping thread.
+// On the next cycle it will run again and pick up where it left off.
+#define        MAXIMUM_INDEXER_RUN_TIME 60