X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fdatabase_sleepycat.c;h=1e4251bb726dd2dcc9e176dfdcab6e44858a932a;hb=5cbfcc2545d5b9f6b947c7fecd1f9f81cabbae4a;hp=1e2b4f6cebaa92f8f978952dbdbdb13117b22c3b;hpb=596a7da4859d0dbf87fba6f6587c612e1cda95ac;p=citadel.git 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.