]> code.citadel.org Git - citadel.git/blobdiff - citadel/database_sleepycat.c
* Dropped support for GDBM and for versions of Berkeley DB prior to 4.1
[citadel.git] / citadel / database_sleepycat.c
index ae63d5e9ae38b9301e38d3854f7fc2effb1a5bd6..5df1e6e3c7a9b21760624e17f9f66e3473e5943f 100644 (file)
 #include <db.h>
 #elif defined(HAVE_DB4_DB_H)
 #include <db4/db.h>
-#elif defined(HAVE_DB3_DB_H)
-#include <db3/db.h>
 #else
-#error Neither <db.h> nor <db3/db.h> was found by configure. Install db3-devel.
+#error Neither <db.h> nor <db4/db.h> was found by configure. Install db4-devel.
 #endif
 
+
+#if DB_VERSION_MAJOR < 4 || DB_VERSION_MINOR < 1
+#error Citadel requires Berkeley DB v4.1 or newer.  Please upgrade.
+#endif
+
+
 #include <pthread.h>
 #include "citadel.h"
 #include "server.h"
-#include "dynloader.h"
+#include "serv_extensions.h"
 #include "citserver.h"
 #include "database.h"
 #include "msgbase.h"
@@ -71,7 +75,9 @@ static pthread_key_t tsdkey;
 
 /* just a little helper function */
 static void txabort(DB_TXN *tid) {
-        int ret = txn_abort(tid);
+        int ret;
+
+       ret = tid->abort(tid);
 
         if (ret) {
                 lprintf(1, "cdb_*: txn_abort: %s\n", db_strerror(ret));
@@ -81,7 +87,9 @@ static void txabort(DB_TXN *tid) {
 
 /* this one is even more helpful than the last. */
 static void txcommit(DB_TXN *tid) {
-        int ret = txn_commit(tid, 0);
+        int ret;
+
+       ret = tid->commit(tid, 0);
 
         if (ret) {
                 lprintf(1, "cdb_*: txn_commit: %s\n", db_strerror(ret));
@@ -91,7 +99,9 @@ static void txcommit(DB_TXN *tid) {
 
 /* are you sensing a pattern yet? */
 static void txbegin(DB_TXN **tid) {
-        int ret = txn_begin(dbenv, NULL, tid, 0);
+        int ret;
+
+       ret = dbenv->txn_begin(dbenv, NULL, tid, 0);
 
         if (ret) {
                 lprintf(1, "cdb_*: txn_begin: %s\n", db_strerror(ret));
@@ -154,7 +164,7 @@ void cdb_allocate_tsd(void) {
        if (pthread_getspecific(tsdkey) != NULL)
                return;
 
-       tsd = mallok(sizeof *tsd);
+       tsd = mallok(sizeof(struct cdbtsd));
 
        tsd->tid = NULL;
 
@@ -199,13 +209,7 @@ static void cdb_cull_logs(void) {
        flags = DB_ARCH_ABS;
 
        /* Get the list of names. */
-#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR < 3
-       if ((ret = log_archive(dbenv, &list, flags, NULL)) != 0) {
-#elif DB_VERSION_MAJOR >= 4
        if ((ret = dbenv->log_archive(dbenv, &list, flags)) != 0) {
-#else
-       if ((ret = log_archive(dbenv, &list, flags)) != 0) {
-#endif
                lprintf(1, "cdb_cull_logs: %s\n", db_strerror(ret));
                return;
        }
@@ -242,21 +246,15 @@ static void cdb_checkpoint(void) {
        int ret;
        static time_t last_cull = 0L;
 
-#if DB_VERSION_MAJOR >= 4
        ret = dbenv->txn_checkpoint(dbenv,
-#else
-       ret = txn_checkpoint(dbenv,
-#endif
                                MAX_CHECKPOINT_KBYTES,
                                MAX_CHECKPOINT_MINUTES,
                                0);
-       if ( (ret != 0) && (ret != DB_INCOMPLETE) ) {
-               lprintf(1, "cdb_checkpoint: txn_checkpoint: %s\n", db_strerror(ret));
-               abort();
-       }
 
-       if (ret == DB_INCOMPLETE) {
-               lprintf(3, "WARNING: txn_checkpoint: %s\n", db_strerror(ret));
+       if (ret != 0) {
+               lprintf(1, "cdb_checkpoint: txn_checkpoint: %s\n",
+                       db_strerror(ret));
+               abort();
        }
 
        /* Cull the logs if we haven't done so for 24 hours */
@@ -344,10 +342,13 @@ void open_databases(void)
                snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", i);
 
                ret = dbp[i]->open(dbp[i],
+                               NULL,
                                dbfilename,
                                NULL,
                                DB_BTREE,
-                               DB_CREATE|DB_THREAD,
+                               DB_CREATE|DB_THREAD
+                               |DB_AUTO_COMMIT
+                               ,
                                0600);
                if (ret) {
                        lprintf(1, "cdb_*: db_open[%d]: %s\n", i, db_strerror(ret));
@@ -377,11 +378,7 @@ void close_databases(void)
 
        cdb_free_tsd();
 
-#if DB_VERSION_MAJOR >= 4
        if ((ret = dbenv->txn_checkpoint(dbenv, 0, 0, 0))) {
-#else
-       if ((ret = txn_checkpoint(dbenv, 0, 0, 0))) {
-#endif
                lprintf(1, "cdb_*: txn_checkpoint: %s\n", db_strerror(ret));
                abort();
        }
@@ -828,9 +825,7 @@ void cdb_trunc(int cdb)
 {
   DB_TXN *tid;
   int ret;
-#if DB_VERSION_MAJOR > 3 || DB_VERSION_MINOR > 2
   u_int32_t count;
-#endif
   
   if (MYTID != NULL)
     {
@@ -841,56 +836,6 @@ void cdb_trunc(int cdb)
     {
       bailIfCursor(MYCURSORS, "attempt to write during r/o cursor");
       
-#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR < 3
-      for (;;)
-       {
-         DBT key, data;
-
-         /* Initialize the key/data pair so the flags aren't set. */
-         memset(&key, 0, sizeof(key));
-         memset(&data, 0, sizeof(data));
-
-         txbegin(&tid);
-         
-         ret = dbp[cdb]->cursor(dbp[cdb], tid, &MYCURSORS[cdb], 0);
-         if (ret)
-           {
-             lprintf(1, "cdb_trunc: db_cursor: %s\n", db_strerror(ret));
-             abort();
-           }
-
-         ret = MYCURSORS[cdb]->c_get(MYCURSORS[cdb],
-                                     &key, &data, DB_NEXT);
-         if (ret)
-           {
-             cclose(MYCURSORS[cdb]);
-             txabort(tid);
-             if (ret == DB_LOCK_DEADLOCK)
-               continue;
-
-             if (ret == DB_NOTFOUND)
-               break;
-
-             lprintf(1, "cdb_trunc: c_get: %s\n", db_strerror(ret));
-             abort();
-           }
-
-         ret = MYCURSORS[cdb]->c_del(MYCURSORS[cdb], 0);
-         if (ret)
-           {
-             cclose(MYCURSORS[cdb]);
-             txabort(tid);
-             if (ret == DB_LOCK_DEADLOCK)
-               continue;
-
-             lprintf(1, "cdb_trunc: c_del: %s\n", db_strerror(ret));
-             abort();
-           }
-
-         cclose(MYCURSORS[cdb]);
-         txcommit(tid);
-       }
-#else
     retry:
       txbegin(&tid);
       
@@ -915,6 +860,5 @@ void cdb_trunc(int cdb)
        {
          txcommit(tid);
        }
-#endif
     }
 }