]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/fulltext/serv_fulltext.c
Changed the way we do the TSD area.
[citadel.git] / citadel / modules / fulltext / serv_fulltext.c
index ba3f948a01af4885838f2918864738f11e2914eb..7c76d9d640f7fba95570c91be1b0bbf5eea9ec7d 100644 (file)
@@ -30,6 +30,7 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -39,7 +40,6 @@
 #include "msgbase.h"
 #include "control.h"
 #include "room_ops.h"
-#include "tools.h"
 #include "serv_fulltext.h"
 #include "ft_wordbreaker.h"
 
@@ -219,7 +219,9 @@ void do_fulltext_indexing(void) {
        int i;
        static time_t last_index = 0L;
        static time_t last_progress = 0L;
-
+       time_t run_time = 0L;
+       time_t end_time = 0L;
+       
        /*
         * Don't do this if the site doesn't have it enabled.
         */
@@ -231,9 +233,13 @@ void do_fulltext_indexing(void) {
         * Make sure we don't run the indexer too frequently.
         * FIXME move the setting into config
         */
+/*
+ * The thread sleeps for 300 seconds so we don't need this here any more
        if ( (time(NULL) - last_index) < 300L) {
                return;
        }
+*/
 
        /*
         * Check to see whether the fulltext index is up to date; if there
@@ -242,17 +248,18 @@ void do_fulltext_indexing(void) {
        if (CitControl.MMfulltext >= CitControl.MMhighest) {
                return;         /* nothing to do! */
        }
-
-       lprintf(CTDL_DEBUG, "do_fulltext_indexing() started\n");
+       
+       run_time = time(NULL);
+       lprintf(CTDL_DEBUG, "do_fulltext_indexing() started (%ld)\n", run_time);
        
        /*
         * If we've switched wordbreaker modules, burn the index and start
         * over.
         */
        begin_critical_section(S_CONTROL);
-       lprintf(CTDL_DEBUG, "wb ver on disk = %d, code ver = %d\n",
-                       CitControl.fulltext_wordbreaker, FT_WORDBREAKER_ID);
        if (CitControl.fulltext_wordbreaker != FT_WORDBREAKER_ID) {
+               lprintf(CTDL_DEBUG, "wb ver on disk = %d, code ver = %d\n",
+                       CitControl.fulltext_wordbreaker, FT_WORDBREAKER_ID);
                lprintf(CTDL_INFO, "(re)initializing full text index\n");
                cdb_trunc(CDB_FULLTEXT);
                CitControl.MMfulltext = 0L;
@@ -290,7 +297,7 @@ void do_fulltext_indexing(void) {
                        ft_index_message(ft_newmsgs[i], 1);
 
                        /* Check to see if we need to quit early */
-                       if (time_to_die) {
+                       if (CtdlThreadCheckStop()) {
                                lprintf(CTDL_DEBUG, "Indexer quitting early\n");
                                ft_newhighest = ft_newmsgs[i];
                                break;
@@ -310,6 +317,8 @@ void do_fulltext_indexing(void) {
                ft_num_alloc = 0;
                ft_newmsgs = NULL;
        }
+       end_time = time(NULL);
+       lprintf(CTDL_DEBUG, "do_fulltext_indexing() duration (%ld)\n", end_time - run_time);
 
        /* Save our place so we don't have to do this again */
        ft_flush_cache();
@@ -330,6 +339,8 @@ void do_fulltext_indexing(void) {
 void *indexer_thread(void *arg) {
        struct CitContext indexerCC;
 
+       CtdlThreadAllocTSD();
+       
        lprintf(CTDL_DEBUG, "indexer_thread() initializing\n");
 
        memset(&indexerCC, 0, sizeof(struct CitContext));
@@ -337,15 +348,13 @@ void *indexer_thread(void *arg) {
        indexerCC.cs_pid = 0;
        pthread_setspecific(MyConKey, (void *)&indexerCC );
 
-       cdb_allocate_tsd();
-
-       while (!time_to_die) {
+       while (!CtdlThreadCheckStop()) {
                do_fulltext_indexing();
-               sleep(1);
+               CtdlThreadSleep(300);
        }
 
        lprintf(CTDL_DEBUG, "indexer_thread() exiting\n");
-       pthread_exit(NULL);
+       return NULL;
 }
 
 
@@ -481,12 +490,17 @@ void ft_delete_remove(char *room, long msgnum)
 
 CTDL_MODULE_INIT(fulltext)
 {
-       initialize_ft_cache();
-       CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
-       CtdlRegisterDeleteHook(ft_delete_remove);
-       CtdlRegisterSearchFuncHook(ft_search, "fulltext");
-       CtdlRegisterMaintenanceThread ("indexer", indexer_thread);
-
+       if (!threading)
+       {
+               initialize_ft_cache();
+               CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search");
+               CtdlRegisterDeleteHook(ft_delete_remove);
+               CtdlRegisterSearchFuncHook(ft_search, "fulltext");
+       }
+       else
+       {
+               CtdlThreadCreate("Indexer", CTDLTHREAD_BIGSTACK, indexer_thread, NULL);
+       }
        /* return our Subversion id for the Log */
        return "$Id$";
 }