* There is now a dedicated thread for doing database checkpoints.
authorArt Cancro <ajc@citadel.org>
Thu, 16 Jun 2005 02:42:58 +0000 (02:42 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 16 Jun 2005 02:42:58 +0000 (02:42 +0000)
citadel/ChangeLog
citadel/citserver.c
citadel/database.h
citadel/database_sleepycat.c
citadel/server_main.c
citadel/sysdep.c
citadel/sysdep_decls.h

index f1629c8ed7cfb439f1626190a74c59699a79780b..a94045b0704e9859e5a8c6d4a3db030bbc651464 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 651.1  2005/06/16 02:42:58  ajc
+* There is now a dedicated thread for doing database checkpoints.
+
 Revision 651.0  2005/06/12 03:46:30  ajc
 * THIS IS 6.51
 
@@ -6878,3 +6881,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 1e32ea54b5ceca67679346b84a3bd6d76b30c88b..85f593641318e9bfdc56e7f1c72cf0ea5401ce6d 100644 (file)
@@ -152,6 +152,10 @@ void master_cleanup(int exitcode) {
        lprintf(CTDL_INFO, "Waiting for the indexer thread to shut down\n");
        pthread_join(indexer_thread_tid, NULL);
 
+       /* Shut down the checkpoint thread */
+       lprintf(CTDL_INFO, "Waiting for the checkpoint thread to shut down\n");
+       pthread_join(checkpoint_thread_tid, NULL);
+
        /* Close databases */
        lprintf(CTDL_INFO, "Closing databases\n");
        close_databases();
index 420fe6d1837841d82a0b5fcc09bb65a365da65ef..7fd42bcb8f80b2dc5bea7a48a78fe2fdf8f59aee 100644 (file)
@@ -15,6 +15,7 @@ void cdb_allocate_tsd(void);
 void cdb_free_tsd(void);
 void cdb_check_handles(void);
 void cdb_trunc(int cdb);
+void *checkpoint_thread(void *arg);
 
 /*
  * Database records beginning with this magic number are assumed to
index 1e2b4f6cebaa92f8f978952dbdbdb13117b22c3b..1e4251bb726dd2dcc9e176dfdcab6e44858a932a 100644 (file)
@@ -253,8 +253,6 @@ static void cdb_cull_logs(void)
                }
                free(list);
        }
-
-       lprintf(CTDL_INFO, "Database log file cull ended.\n");
 }
 
 
@@ -264,8 +262,15 @@ static void cdb_cull_logs(void)
 static void cdb_checkpoint(void)
 {
        int ret;
-       /* static time_t last_cull = 0L; */
+       static time_t last_run = 0L;
+
+       /* Only do a checkpoint once per minute. */
+       if ((time(NULL) - last_run) < 60L) {
+               return;
+       }
+       last_run = time(NULL);
 
+       lprintf(CTDL_DEBUG, "-- db checkpoint --\n");
        ret = dbenv->txn_checkpoint(dbenv,
                                    MAX_CHECKPOINT_KBYTES,
                                    MAX_CHECKPOINT_MINUTES, 0);
@@ -278,13 +283,31 @@ static void cdb_checkpoint(void)
 
        /* After a successful checkpoint, we can cull the unused logs */
        cdb_cull_logs();
+}
+
+
+/*
+ * Main loop for the checkpoint thread.
+ */
+void *checkpoint_thread(void *arg) {
+       struct CitContext checkpointCC;
+
+       lprintf(CTDL_DEBUG, "checkpoint_thread() initializing\n");
+
+       memset(&checkpointCC, 0, sizeof(struct CitContext));
+       checkpointCC.internal_pgm = 1;
+       checkpointCC.cs_pid = 0;
+       pthread_setspecific(MyConKey, (void *)&checkpointCC );
 
-       /* Cull the logs if we haven't done so for 24 hours
-          if ((time(NULL) - last_cull) > 86400L) {
-          last_cull = time(NULL);
-          cdb_cull_logs();
-          } */
+       cdb_allocate_tsd();
+
+       while (!time_to_die) {
+               cdb_checkpoint();
+               sleep(1);
+       }
 
+       lprintf(CTDL_DEBUG, "checkpoint_thread() exiting\n");
+       pthread_exit(NULL);
 }
 
 /*
@@ -406,7 +429,6 @@ void open_databases(void)
        }
 
        cdb_allocate_tsd();
-       CtdlRegisterSessionHook(cdb_checkpoint, EVT_TIMER);
 
        /* Now make sure we own all the files, because in a few milliseconds
         * we're going to drop root privs.
index 3c610aba915ae23e95de5a140df1216becc5f86d..6497d37871423acb56d9a9520b05e30272db795f 100644 (file)
@@ -243,7 +243,7 @@ int main(int argc, char **argv)
        end_critical_section(S_WORKER_LIST);
 
        /* Create the indexer thread. */
-       create_indexer_thread();
+       create_maintenance_threads();
 
        /* This thread is now useless.  It can't be turned into a worker
         * thread because its stack is too small, but it can't be killed
index b71c068a2819e4f359d47c1b64109f46bf346c90..1179ea604fcee87a6c8a8f6ae77ee7fec0db7428 100644 (file)
@@ -99,6 +99,7 @@ time_t last_purge = 0;                                /* Last dead session purge */
 static int num_threads = 0;                    /* Current number of threads */
 int num_sessions = 0;                          /* Current number of sessions */
 pthread_t indexer_thread_tid;
+pthread_t checkpoint_thread_tid;
 
 int syslog_facility = (-1);
 int enable_syslog = 0;
@@ -815,8 +816,9 @@ void create_worker(void) {
 
 /*
  * Create the indexer thread and begin its operation.
+ * Then create the checkpoint thread and begin its operation.
  */
-void create_indexer_thread(void) {
+void create_maintenance_threads(void) {
        int ret;
        pthread_attr_t attr;
 
@@ -838,10 +840,12 @@ void create_indexer_thread(void) {
                return;
        }
 
-       if ((ret = pthread_create(&indexer_thread_tid, &attr, indexer_thread, NULL) != 0))
-       {
-               lprintf(CTDL_ALERT, "Can't create indexer thread: %s\n",
-                       strerror(ret));
+       if ((ret = pthread_create(&indexer_thread_tid, &attr, indexer_thread, NULL) != 0)) {
+               lprintf(CTDL_ALERT, "Can't create thread: %s\n", strerror(ret));
+       }
+
+       if ((ret = pthread_create(&checkpoint_thread_tid, &attr, checkpoint_thread, NULL) != 0)) {
+               lprintf(CTDL_ALERT, "Can't create thread: %s\n", strerror(ret));
        }
 
        pthread_attr_destroy(&attr);
index 99071ec3cc3b4c9fee1cb6ebae8981740d97dcfa..c805176a0f5a5d3cf8ad0da10e11297243347585 100644 (file)
@@ -98,5 +98,6 @@ char *tracked_strdup(const char *s, char *file, int line);
 void dump_heap(void);
 #endif
 
-void create_indexer_thread(void);
+void create_maintenance_threads(void);
 extern pthread_t indexer_thread_tid;
+extern pthread_t checkpoint_thread_tid;