projects
/
citadel.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8df8fc3
)
berkeley_db.c: prefixed all module-local functions with bdb_ to avoid namespace colli...
author
Art Cancro
<ajc@citadel.org>
Wed, 9 Aug 2023 15:47:02 +0000
(11:47 -0400)
committer
Art Cancro
<ajc@citadel.org>
Wed, 9 Aug 2023 15:47:02 +0000
(11:47 -0400)
citadel/server/backends/berkeley_db/berkeley_db.c
patch
|
blob
|
history
diff --git
a/citadel/server/backends/berkeley_db/berkeley_db.c
b/citadel/server/backends/berkeley_db/berkeley_db.c
index edf7a902c63119fb66ecbe25cd186b05a00e47ed..b16c0e57d3f0ed73b1d1de0f2798265fbe097ebf 100644
(file)
--- a/
citadel/server/backends/berkeley_db/berkeley_db.c
+++ b/
citadel/server/backends/berkeley_db/berkeley_db.c
@@
-35,6
+35,7
@@
static DB *dbp[MAXCDB]; // One DB handle for each Citadel database
static DB_ENV *dbenv; // The DB environment (global)
static DB_ENV *dbenv; // The DB environment (global)
+// Called by other functions in this module to GTFO quickly if we need to. Not part of the backend API.
void bdb_abort(void) {
syslog(LOG_DEBUG, "bdb: citserver is stopping in order to prevent data loss. uid=%d gid=%d euid=%d egid=%d",
getuid(), getgid(), geteuid(), getegid()
void bdb_abort(void) {
syslog(LOG_DEBUG, "bdb: citserver is stopping in order to prevent data loss. uid=%d gid=%d euid=%d egid=%d",
getuid(), getgid(), geteuid(), getegid()
@@
-44,7
+45,7
@@
void bdb_abort(void) {
}
}
-// Verbose logging callback
+// Verbose logging callback
for Berkeley DB. Not part of the backend API.
void bdb_verbose_log(const DB_ENV *dbenv, const char *msg, const char *foo) {
if (!IsEmptyStr(msg)) {
syslog(LOG_DEBUG, "bdb: %s %s", msg, foo);
void bdb_verbose_log(const DB_ENV *dbenv, const char *msg, const char *foo) {
if (!IsEmptyStr(msg)) {
syslog(LOG_DEBUG, "bdb: %s %s", msg, foo);
@@
-52,14
+53,14
@@
void bdb_verbose_log(const DB_ENV *dbenv, const char *msg, const char *foo) {
}
}
-// Verbose
logging callback
+// Verbose
error logging callback for Berkeley DB. Not part of the backend API.
void bdb_verbose_err(const DB_ENV *dbenv, const char *errpfx, const char *msg) {
syslog(LOG_ERR, "bdb: %s", msg);
}
// wrapper for txn_abort() that logs/aborts on error
void bdb_verbose_err(const DB_ENV *dbenv, const char *errpfx, const char *msg) {
syslog(LOG_ERR, "bdb: %s", msg);
}
// wrapper for txn_abort() that logs/aborts on error
-static void txabort(DB_TXN *tid) {
+static void
bdb_
txabort(DB_TXN *tid) {
int ret;
ret = tid->abort(tid);
int ret;
ret = tid->abort(tid);
@@
-72,7
+73,7
@@
static void txabort(DB_TXN *tid) {
// wrapper for txn_commit() that logs/aborts on error
// wrapper for txn_commit() that logs/aborts on error
-static void txcommit(DB_TXN *tid) {
+static void
bdb_
txcommit(DB_TXN *tid) {
int ret;
ret = tid->commit(tid, 0);
int ret;
ret = tid->commit(tid, 0);
@@
-85,7
+86,7
@@
static void txcommit(DB_TXN *tid) {
// wrapper for txn_begin() that logs/aborts on error
// wrapper for txn_begin() that logs/aborts on error
-static void txbegin(DB_TXN **tid) {
+static void
bdb_
txbegin(DB_TXN **tid) {
int ret;
ret = dbenv->txn_begin(dbenv, NULL, tid, 0);
int ret;
ret = dbenv->txn_begin(dbenv, NULL, tid, 0);
@@
-98,13
+99,13
@@
static void txbegin(DB_TXN **tid) {
// panic callback
// panic callback
-static void dbpanic(DB_ENV *env, int errval) {
+static void
bdb_
dbpanic(DB_ENV *env, int errval) {
syslog(LOG_ERR, "bdb: PANIC: %s", db_strerror(errval));
bdb_abort();
}
syslog(LOG_ERR, "bdb: PANIC: %s", db_strerror(errval));
bdb_abort();
}
-static void cclose(DBC *cursor) {
+static void
bdb_
cclose(DBC *cursor) {
int ret;
if ((ret = cursor->c_close(cursor))) {
int ret;
if ((ret = cursor->c_close(cursor))) {
@@
-114,7
+115,7
@@
static void cclose(DBC *cursor) {
}
}
-static void bailIfCursor(DBC **cursors, const char *msg) {
+static void b
db_b
ailIfCursor(DBC **cursors, const char *msg) {
int i;
for (i = 0; i < MAXCDB; i++)
int i;
for (i = 0; i < MAXCDB; i++)
@@
-126,7
+127,7
@@
static void bailIfCursor(DBC **cursors, const char *msg) {
void bdb_check_handles(void) {
void bdb_check_handles(void) {
- bailIfCursor(TSD->cursors, "in check_handles");
+ b
db_b
ailIfCursor(TSD->cursors, "in check_handles");
if (TSD->tid != NULL) {
syslog(LOG_ERR, "bdb: transaction still in progress!");
if (TSD->tid != NULL) {
syslog(LOG_ERR, "bdb: transaction still in progress!");
@@
-204,7
+205,7
@@
void bdb_open_databases(void) {
exit(CTDLEXIT_DB);
}
dbenv->set_errpfx(dbenv, "citserver");
exit(CTDLEXIT_DB);
}
dbenv->set_errpfx(dbenv, "citserver");
- dbenv->set_paniccall(dbenv, dbpanic);
+ dbenv->set_paniccall(dbenv,
bdb_
dbpanic);
dbenv->set_errcall(dbenv, bdb_verbose_err);
dbenv->set_msgcall(dbenv, bdb_verbose_log);
dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, 1);
dbenv->set_errcall(dbenv, bdb_verbose_err);
dbenv->set_msgcall(dbenv, bdb_verbose_log);
dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, 1);
@@
-429,10
+430,10
@@
int bdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
return ret;
}
else {
return ret;
}
else {
- bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
+ b
db_b
ailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
retry:
retry:
- txbegin(&tid);
+
bdb_
txbegin(&tid);
if ((ret = dbp[cdb]->put(dbp[cdb], // db
tid, // transaction ID
if ((ret = dbp[cdb]->put(dbp[cdb], // db
tid, // transaction ID
@@
-440,7
+441,7
@@
int bdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
&ddata, // data
0))) { // flags
if (ret == DB_LOCK_DEADLOCK) {
&ddata, // data
0))) { // flags
if (ret == DB_LOCK_DEADLOCK) {
- txabort(tid);
+
bdb_
txabort(tid);
goto retry;
}
else {
goto retry;
}
else {
@@
-449,7
+450,7
@@
int bdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
}
}
else {
}
}
else {
- txcommit(tid);
+
bdb_
txcommit(tid);
if (compressing) {
free(compressed_data);
}
if (compressing) {
free(compressed_data);
}
@@
-480,14
+481,14
@@
int bdb_delete(int cdb, void *key, int keylen) {
}
}
else {
}
}
else {
- bailIfCursor(TSD->cursors, "attempt to delete during r/o cursor");
+ b
db_b
ailIfCursor(TSD->cursors, "attempt to delete during r/o cursor");
retry:
retry:
- txbegin(&tid);
+
bdb_
txbegin(&tid);
if ((ret = dbp[cdb]->del(dbp[cdb], tid, &dkey, 0)) && ret != DB_NOTFOUND) {
if (ret == DB_LOCK_DEADLOCK) {
if ((ret = dbp[cdb]->del(dbp[cdb], tid, &dkey, 0)) && ret != DB_NOTFOUND) {
if (ret == DB_LOCK_DEADLOCK) {
- txabort(tid);
+
bdb_
txabort(tid);
goto retry;
}
else {
goto retry;
}
else {
@@
-496,14
+497,14
@@
int bdb_delete(int cdb, void *key, int keylen) {
}
}
else {
}
}
else {
- txcommit(tid);
+
bdb_
txcommit(tid);
}
}
return ret;
}
}
}
return ret;
}
-static DBC *localcursor(int cdb) {
+static DBC *
bdb_
localcursor(int cdb) {
int ret;
DBC *curs;
int ret;
DBC *curs;
@@
-515,7
+516,7
@@
static DBC *localcursor(int cdb) {
}
if (ret) {
}
if (ret) {
- syslog(LOG_ERR, "bdb: localcursor: %s", db_strerror(ret));
+ syslog(LOG_ERR, "bdb:
bdb_
localcursor: %s", db_strerror(ret));
bdb_abort();
}
bdb_abort();
}
@@
-551,9
+552,9
@@
struct cdbdata *bdb_fetch(int cdb, const void *key, int keylen) {
do {
memset(&dret, 0, sizeof(DBT));
dret.flags = DB_DBT_MALLOC;
do {
memset(&dret, 0, sizeof(DBT));
dret.flags = DB_DBT_MALLOC;
- curs = localcursor(cdb);
+ curs =
bdb_
localcursor(cdb);
ret = curs->c_get(curs, &dkey, &dret, DB_SET);
ret = curs->c_get(curs, &dkey, &dret, DB_SET);
- cclose(curs);
+
bdb_
cclose(curs);
} while (ret == DB_LOCK_DEADLOCK);
}
} while (ret == DB_LOCK_DEADLOCK);
}
@@
-596,7
+597,7
@@
void bdb_free(struct cdbdata *cdb) {
void bdb_close_cursor(int cdb) {
if (TSD->cursors[cdb] != NULL) {
void bdb_close_cursor(int cdb) {
if (TSD->cursors[cdb] != NULL) {
- cclose(TSD->cursors[cdb]);
+
bdb_
cclose(TSD->cursors[cdb]);
}
TSD->cursors[cdb] = NULL;
}
TSD->cursors[cdb] = NULL;
@@
-612,7
+613,7
@@
void bdb_rewind(int cdb) {
if (TSD->cursors[cdb] != NULL) {
syslog(LOG_ERR, "bdb: bdb_rewind: must close cursor on database %d before reopening", cdb);
bdb_abort();
if (TSD->cursors[cdb] != NULL) {
syslog(LOG_ERR, "bdb: bdb_rewind: must close cursor on database %d before reopening", cdb);
bdb_abort();
- // cclose(TSD->cursors[cdb]);
+ //
bdb_
cclose(TSD->cursors[cdb]);
}
// Now initialize the cursor
}
// Now initialize the cursor
@@
-658,14
+659,14
@@
struct cdbdata *bdb_next_item(int cdb) {
// Transaction-based stuff. I'm writing this as I bake cookies...
void bdb_begin_transaction(void) {
// Transaction-based stuff. I'm writing this as I bake cookies...
void bdb_begin_transaction(void) {
- bailIfCursor(TSD->cursors, "can't begin transaction during r/o cursor");
+ b
db_b
ailIfCursor(TSD->cursors, "can't begin transaction during r/o cursor");
if (TSD->tid != NULL) {
syslog(LOG_ERR, "bdb: bdb_begin_transaction: ERROR: nested transaction");
bdb_abort();
}
if (TSD->tid != NULL) {
syslog(LOG_ERR, "bdb: bdb_begin_transaction: ERROR: nested transaction");
bdb_abort();
}
- txbegin(&TSD->tid);
+
bdb_
txbegin(&TSD->tid);
}
}
@@
-675,17
+676,17
@@
void bdb_end_transaction(void) {
for (i = 0; i < MAXCDB; i++) {
if (TSD->cursors[i] != NULL) {
syslog(LOG_WARNING, "bdb: bdb_end_transaction: WARNING: cursor %d still open at transaction end", i);
for (i = 0; i < MAXCDB; i++) {
if (TSD->cursors[i] != NULL) {
syslog(LOG_WARNING, "bdb: bdb_end_transaction: WARNING: cursor %d still open at transaction end", i);
- cclose(TSD->cursors[i]);
+
bdb_
cclose(TSD->cursors[i]);
TSD->cursors[i] = NULL;
}
}
if (TSD->tid == NULL) {
TSD->cursors[i] = NULL;
}
}
if (TSD->tid == NULL) {
- syslog(LOG_ERR, "bdb: bdb_end_transaction: ERROR: txcommit(NULL) !!");
+ syslog(LOG_ERR, "bdb: bdb_end_transaction: ERROR:
bdb_
txcommit(NULL) !!");
bdb_abort();
}
else {
bdb_abort();
}
else {
- txcommit(TSD->tid);
+
bdb_
txcommit(TSD->tid);
}
TSD->tid = NULL;
}
TSD->tid = NULL;
@@
-702,7
+703,7
@@
void bdb_trunc(int cdb) {
bdb_abort();
}
else {
bdb_abort();
}
else {
- bailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
+ b
db_b
ailIfCursor(TSD->cursors, "attempt to write during r/o cursor");
retry:
retry: