summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3b8600a)
Author: noodles
Date: 2003/01/22 23:31:32
Add transaction support to DB3 backend to attempt to prevent locking with
multiple instances running at once.
* Copyright 2002 Project Purple
*/
* Copyright 2002 Project Purple
*/
#include <sys/types.h>
#include <sys/uio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <ctype.h>
#include "onak-conf.h"
#include "parsekey.h"
#include "onak-conf.h"
#include "parsekey.h"
+/**
+ * dbenv - our database environment.
+ */
+static DB_ENV *dbenv = NULL;
+
/**
* dbconn - our connection to the key database.
*/
/**
* dbconn - our connection to the key database.
*/
*/
static DB *worddb = NULL;
*/
static DB *worddb = NULL;
+/**
+ * txn - our current transaction id.
+ */
+static DB_TXN *txn = NULL;
+
/**
* makewordlist - Takes a string and splits it into a set of unique words.
* @wordlist: The current word list.
/**
* makewordlist - Takes a string and splits it into a set of unique words.
* @wordlist: The current word list.
char buf[1024];
int ret = 0;
char buf[1024];
int ret = 0;
- strcpy(buf, config.db_dir);
- strcat(buf, "/keydb.db");
-
- ret = db_create(&dbconn, NULL, 0);
+ ret = db_env_create(&dbenv, 0);
+ if (ret != 0) {
+ fprintf(stderr, "db_env_create: %s\n", db_strerror(ret));
+ exit(1);
+ }
+
+ ret = dbenv->open(dbenv, config.db_dir,
+ DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_LOCK |
+ DB_INIT_TXN |
+ DB_RECOVER | DB_CREATE,
+ 0);
+ if (ret != 0) {
+ dbenv->err(dbenv, ret, "%s", config.db_dir);
+ exit(1);
+ }
+
+ ret = db_create(&dbconn, dbenv, 0);
if (ret != 0) {
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit(1);
}
if (ret != 0) {
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit(1);
}
- ret = dbconn->open(dbconn, buf, NULL, DB_HASH,
+ ret = dbconn->open(dbconn, "keydb.db",
+ NULL,
+ DB_HASH,
DB_CREATE,
0664);
if (ret != 0) {
DB_CREATE,
0664);
if (ret != 0) {
- dbconn->err(dbconn, ret, "%s", buf);
+ dbconn->err(dbconn, ret, "keydb.db");
- strcpy(buf, config.db_dir);
- strcat(buf, "/worddb");
-
- ret = db_create(&worddb, NULL, 0);
+ ret = db_create(&worddb, dbenv, 0);
if (ret != 0) {
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit(1);
}
ret = worddb->set_flags(worddb, DB_DUP);
if (ret != 0) {
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit(1);
}
ret = worddb->set_flags(worddb, DB_DUP);
- ret = worddb->open(worddb, buf, NULL, DB_BTREE,
+ ret = worddb->open(worddb, "worddb", NULL, DB_BTREE,
DB_CREATE,
0664);
if (ret != 0) {
DB_CREATE,
0664);
if (ret != 0) {
- worddb->err(worddb, ret, "%s", buf);
+ worddb->err(worddb, ret, "worddb");
worddb = NULL;
dbconn->close(dbconn, 0);
dbconn = NULL;
worddb = NULL;
dbconn->close(dbconn, 0);
dbconn = NULL;
+ dbenv->close(dbenv, 0);
+ dbenv = NULL;
*/
bool starttrans(void)
{
*/
bool starttrans(void)
{
+ int ret;
+
+ assert(txn == NULL);
+
+ ret = txn_begin(dbenv,
+ NULL, /* No parent transaction */
+ &txn,
+ 0);
+ if (ret != 0) {
+ dbenv->err(dbenv, ret, "starttrans():");
+ exit(1);
+ }
+
+ int ret;
+
+ assert(txn != NULL);
+
+ ret = txn_commit(txn,
+ 0);
+ if (ret != 0) {
+ dbenv->err(dbenv, ret, "endtrans():");
+ exit(1);
+ }
+ txn = NULL;
+
key.data = &keyid;
keyid &= 0xFFFFFFFF;
key.data = &keyid;
keyid &= 0xFFFFFFFF;
+ if (!intrans) {
+ starttrans();
+ }
+
ret = dbconn->get(dbconn,
ret = dbconn->get(dbconn,
&key,
&data,
0); /* flags*/
&key,
&data,
0); /* flags*/
dbconn->err(dbconn, ret, "Problem retrieving key");
}
dbconn->err(dbconn, ret, "Problem retrieving key");
}
+ if (!intrans) {
+ endtrans();
+ }
+
searchtext = strdup(search);
wordlist = makewordlist(wordlist, searchtext);
searchtext = strdup(search);
wordlist = makewordlist(wordlist, searchtext);
ret = worddb->cursor(worddb,
ret = worddb->cursor(worddb,
numkeys += fetch_key(keyid,
publickey,
numkeys += fetch_key(keyid,
publickey,
}
llfree(keylist, free);
keylist = NULL;
}
llfree(keylist, free);
keylist = NULL;
ret = cursor->c_close(cursor);
cursor = NULL;
ret = cursor->c_close(cursor);
cursor = NULL;
keyid = get_keyid(publickey);
keyid = get_keyid(publickey);
+ if (!intrans) {
+ starttrans();
+ }
+
/*
* Delete the key if we already have it.
*
/*
* Delete the key if we already have it.
*
data.data = storebuf.buffer;
ret = dbconn->put(dbconn,
data.data = storebuf.buffer;
ret = dbconn->put(dbconn,
&key,
&data,
0); /* flags*/
&key,
&data,
0); /* flags*/
worddb_data[10] = (keyid >> 8) & 0xFF;
worddb_data[11] = keyid & 0xFF;
ret = worddb->put(worddb,
worddb_data[10] = (keyid >> 8) & 0xFF;
worddb_data[11] = keyid & 0xFF;
ret = worddb->put(worddb,
+ if (!intrans) {
+ endtrans();
+ }
+
- fetch_key(keyid, &publickey, intrans);
+ if (!intrans) {
+ starttrans();
+ }
+
+ fetch_key(keyid, &publickey, true);
/*
* Walk through the uids removing the words from the worddb.
/*
* Walk through the uids removing the words from the worddb.
}
ret = worddb->cursor(worddb,
}
ret = worddb->cursor(worddb,
&key,
&data,
DB_GET_BOTH);
&key,
&data,
DB_GET_BOTH);
if (ret == 0) {
ret = cursor->c_del(cursor, 0);
if (ret == 0) {
ret = cursor->c_del(cursor, 0);
+ if (ret != 0) {
+ worddb->err(worddb, ret,
+ "Problem deleting word.");
+ }
key.size = sizeof(keyid);
dbconn->del(dbconn,
key.size = sizeof(keyid);
dbconn->del(dbconn,
+ if (!intrans) {
+ endtrans();
+ }
+
return (ret == DB_NOTFOUND);
}
return (ret == DB_NOTFOUND);
}