From 5cbfcc2545d5b9f6b947c7fecd1f9f81cabbae4a Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 16 Jun 2005 02:42:58 +0000 Subject: [PATCH] * There is now a dedicated thread for doing database checkpoints. --- citadel/ChangeLog | 4 ++++ citadel/citserver.c | 4 ++++ citadel/database.h | 1 + citadel/database_sleepycat.c | 40 ++++++++++++++++++++++++++++-------- citadel/server_main.c | 2 +- citadel/sysdep.c | 14 ++++++++----- citadel/sysdep_decls.h | 3 ++- 7 files changed, 52 insertions(+), 16 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index f1629c8ed..a94045b07 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/citserver.c b/citadel/citserver.c index 1e32ea54b..85f593641 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -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(); diff --git a/citadel/database.h b/citadel/database.h index 420fe6d18..7fd42bcb8 100644 --- a/citadel/database.h +++ b/citadel/database.h @@ -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 diff --git a/citadel/database_sleepycat.c b/citadel/database_sleepycat.c index 1e2b4f6ce..1e4251bb7 100644 --- a/citadel/database_sleepycat.c +++ b/citadel/database_sleepycat.c @@ -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. diff --git a/citadel/server_main.c b/citadel/server_main.c index 3c610aba9..6497d3787 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -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 diff --git a/citadel/sysdep.c b/citadel/sysdep.c index b71c068a2..1179ea604 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -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); diff --git a/citadel/sysdep_decls.h b/citadel/sysdep_decls.h index 99071ec3c..c805176a0 100644 --- a/citadel/sysdep_decls.h +++ b/citadel/sysdep_decls.h @@ -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; -- 2.30.2