$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
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
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();
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
}
free(list);
}
-
- lprintf(CTDL_INFO, "Database log file cull ended.\n");
}
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);
/* 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);
}
/*
}
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.
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
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;
/*
* 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;
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);
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;