]> code.citadel.org Git - citadel.git/blobdiff - citadel/database_sleepycat.c
Removed the 'defrag databases' stub function and command
[citadel.git] / citadel / database_sleepycat.c
index 2ca3bb9223e829085ddc3d27fdef167b62b58a03..01cfb31628e9e3642f7e1303788876673c54e2d7 100644 (file)
 #endif
 
 
-#include <pthread.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
 #include "database.h"
 #include "msgbase.h"
 #include "sysdep_decls.h"
+#include "threads.h"
 #include "config.h"
 
 #include "ctdl_module.h"
 static DB *dbp[MAXCDB];                /* One DB handle for each Citadel database */
 static DB_ENV *dbenv;          /* The DB environment (global) */
 
-struct cdbtsd {                        /* Thread-specific DB stuff */
-       DB_TXN *tid;            /* Transaction handle */
-       DBC *cursors[MAXCDB];   /* Cursors, for traversals... */
-};
 
 #ifdef HAVE_ZLIB
 #include <zlib.h>
 #endif
 
-static pthread_key_t tsdkey;
-
-#define MYCURSORS      (((struct cdbtsd*)pthread_getspecific(tsdkey))->cursors)
-#define MYTID          (((struct cdbtsd*)pthread_getspecific(tsdkey))->tid)
 
 /* Verbose logging callback */
 void cdb_verbose_log(const DB_ENV *dbenv, const char *msg)
@@ -157,10 +149,10 @@ static void bailIfCursor(DBC ** cursors, const char *msg)
                }
 }
 
-static void check_handles(void *arg)
+void check_handles(void *arg)
 {
        if (arg != NULL) {
-               struct cdbtsd *tsd = (struct cdbtsd *) arg;
+               ThreadTSD *tsd = (ThreadTSD *) arg;
 
                bailIfCursor(tsd->cursors, "in check_handles");
 
@@ -172,59 +164,9 @@ static void check_handles(void *arg)
        }
 }
 
-static void dest_tsd(void *arg)
-{
-       if (arg != NULL) {
-               check_handles(arg);
-               free(arg);
-       }
-}
-
-/*
- * Ensure that we have a key for thread-specific data.  We don't
- * put anything in here that Citadel cares about; this is just database
- * related stuff like cursors and transactions.
- *
- * This should be called immediately after startup by any thread which wants
- * to use database calls, except for whatever thread calls open_databases.
- */
-void cdb_allocate_tsd(void)
-{
-       struct cdbtsd *tsd;
-
-       if (pthread_getspecific(tsdkey) != NULL)
-               return;
-
-       tsd = malloc(sizeof(struct cdbtsd));
-
-       tsd->tid = NULL;
-
-       memset(tsd->cursors, 0, sizeof tsd->cursors);
-       pthread_setspecific(tsdkey, tsd);
-}
-
-void cdb_free_tsd(void)
-{
-       dest_tsd(pthread_getspecific(tsdkey));
-       pthread_setspecific(tsdkey, NULL);
-}
-
 void cdb_check_handles(void)
 {
-       check_handles(pthread_getspecific(tsdkey));
-}
-
-
-/*
- * Reclaim unused space in the databases.  We need to do each one of
- * these discretely, rather than in a loop.
- *
- * This is a stub function in the Sleepycat DB backend, because there is no
- * such API call available.
- */
-void defrag_databases(void)
-{
-       /* do nothing */
+       check_handles(pthread_getspecific(ThreadKey));
 }
 
 
@@ -280,16 +222,20 @@ void cmd_cull(char *argbuf) {
 /*
  * Request a checkpoint of the database.
  */
-static void cdb_checkpoint(void)
+void cdb_checkpoint(void)
 {
        int ret;
-       static time_t last_run = 0L;
+//     static time_t last_run = 0L;
 
        /* Only do a checkpoint once per minute. */
+/*
+ * Don't need this any more, since the thread that calls us sleeps for 60 seconds between calls
        if ((time(NULL) - last_run) < 60L) {
                return;
        }
        last_run = time(NULL);
+*/
 
        lprintf(CTDL_DEBUG, "-- db checkpoint --\n");
        ret = dbenv->txn_checkpoint(dbenv,
@@ -309,29 +255,6 @@ static void cdb_checkpoint(void)
 }
 
 
-/*
- * 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 );
-
-       cdb_allocate_tsd();
-
-       while (!time_to_die) {
-               cdb_checkpoint();
-               sleep(1);
-       }
-
-       lprintf(CTDL_DEBUG, "checkpoint_thread() exiting\n");
-       pthread_exit(NULL);
-}
 
 /*
  * Open the various databases we'll be using.  Any database which
@@ -453,15 +376,6 @@ void open_databases(void)
                }
        }
 
-       if ((ret = pthread_key_create(&tsdkey, dest_tsd))) {
-               lprintf(CTDL_EMERG, "pthread_key_create: %s\n",
-                       strerror(ret));
-               exit(CTDLEXIT_DB);
-       }
-
-       cdb_allocate_tsd();
-       
-       CtdlRegisterMaintenanceThread ("checkpoint", checkpoint_thread);
 }
 
 
@@ -505,8 +419,8 @@ void close_databases(void)
        int a;
        int ret;
 
-       cdb_free_tsd();
-
+       ctdl_thread_internal_free_tsd();
+       
        if ((ret = dbenv->txn_checkpoint(dbenv, 0, 0, 0))) {
                lprintf(CTDL_EMERG,
                        "txn_checkpoint: %s\n", db_strerror(ret));