summaryrefslogtreecommitdiff
path: root/db/qam
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2004-10-16 01:31:54 +0000
committerjbj <devnull@localhost>2004-10-16 01:31:54 +0000
commitd03f220fde879509cab2ac1c73b71b7efb52b737 (patch)
tree1e34bfadac0a6618d0e9a7933bad90063a785acf /db/qam
parent2dc699bfe049b9319ea3719f604d25940ff52004 (diff)
downloadrpm-d03f220fde879509cab2ac1c73b71b7efb52b737.tar.gz
rpm-d03f220fde879509cab2ac1c73b71b7efb52b737.tar.bz2
rpm-d03f220fde879509cab2ac1c73b71b7efb52b737.zip
... and in with the New ...
CVS patchset: 7471 CVS date: 2004/10/16 01:31:54
Diffstat (limited to 'db/qam')
-rw-r--r--db/qam/qam.c306
-rw-r--r--db/qam/qam.src6
-rw-r--r--db/qam/qam_auto.c936
-rw-r--r--db/qam/qam_autop.c274
-rw-r--r--db/qam/qam_conv.c8
-rw-r--r--db/qam/qam_files.c150
-rw-r--r--db/qam/qam_method.c256
-rw-r--r--db/qam/qam_open.c11
-rw-r--r--db/qam/qam_rec.c63
-rw-r--r--db/qam/qam_stat.c109
-rw-r--r--db/qam/qam_stub.c36
-rw-r--r--db/qam/qam_upgrade.c10
-rw-r--r--db/qam/qam_verify.c54
13 files changed, 1083 insertions, 1136 deletions
diff --git a/db/qam/qam.c b/db/qam/qam.c
index f90ccce07..9c0b4812f 100644
--- a/db/qam/qam.c
+++ b/db/qam/qam.c
@@ -1,16 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999-2003
+ * Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam.c,v 11.186 2004/09/22 16:29:47 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam.c,v 11.159 2003/11/18 21:32:17 ubell Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
@@ -53,7 +51,7 @@ __qam_position(dbc, recnop, mode, exactp)
DB *dbp;
QAMDATA *qp;
db_pgno_t pg;
- int ret;
+ int ret, t_ret;
dbp = dbc->dbp;
cp = (QUEUE_CURSOR *)dbc->internal;
@@ -68,11 +66,13 @@ __qam_position(dbc, recnop, mode, exactp)
*exactp = 0;
if ((ret = __qam_fget(dbp, &pg,
mode == QAM_WRITE ? DB_MPOOL_CREATE : 0, &cp->page)) != 0) {
- /* We did not fetch it, we can release the lock. */
- (void)__LPUT(dbc, cp->lock);
if (mode != QAM_WRITE &&
(ret == DB_PAGE_NOTFOUND || ret == ENOENT))
- return (0);
+ ret = 0;
+
+ /* We did not fetch it, we can release the lock. */
+ if ((t_ret = __LPUT(dbc, cp->lock)) != 0 && ret == 0)
+ ret = t_ret;
return (ret);
}
cp->pgno = pg;
@@ -118,12 +118,12 @@ __qam_pitem(dbc, pagep, indx, recno, data)
QAMDATA *qp;
QUEUE *t;
u_int8_t *dest, *p;
- int alloced, ret;
+ int allocated, ret;
dbp = dbc->dbp;
dbenv = dbp->dbenv;
t = (QUEUE *)dbp->q_internal;
- alloced = ret = 0;
+ allocated = ret = 0;
if (data->size > t->re_len)
return (__db_rec_toobig(dbenv, data->size, t->re_len));
@@ -164,7 +164,7 @@ __qam_pitem(dbc, pagep, indx, recno, data)
if ((ret = __os_malloc(dbenv,
t->re_len, &datap->data)) != 0)
return (ret);
- alloced = 1;
+ allocated = 1;
datap->size = t->re_len;
/*
@@ -204,7 +204,7 @@ no_partial:
if (!F_ISSET(data, DB_DBT_PARTIAL))
memset(p + datap->size, t->re_pad, t->re_len - datap->size);
-err: if (alloced)
+err: if (allocated)
__os_free(dbenv, datap->data);
return (ret);
@@ -249,7 +249,7 @@ __qam_c_put(dbc, key, data, flags, pgnop)
default:
/* The interface shouldn't let anything else through. */
DB_ASSERT(0);
- return (__db_ferr(dbp->dbenv, "__qam_c_put", flags));
+ return (__db_ferr(dbp->dbenv, "DBC->put", 0));
}
/* Write lock the record. */
@@ -257,10 +257,9 @@ __qam_c_put(dbc, key, data, flags, pgnop)
0, cp->recno, DB_LOCK_WRITE, DB_LOCK_RECORD, &lock)) != 0)
return (ret);
- if ((ret = __qam_position(dbc,
- &cp->recno, QAM_WRITE, &exact)) != 0) {
+ if ((ret = __qam_position(dbc, &cp->recno, QAM_WRITE, &exact)) != 0) {
/* We could not get the page, we can release the record lock. */
- __LPUT(dbc, lock);
+ (void)__LPUT(dbc, lock);
return (ret);
}
@@ -403,8 +402,10 @@ __qam_append(dbc, key, data)
meta->cur_recno--;
if (meta->cur_recno == RECNO_OOB)
meta->cur_recno--;
- (void)__LPUT(dbc, lock);
- ret = EFBIG;
+ ret = __LPUT(dbc, lock);
+
+ if (ret == 0)
+ ret = EFBIG;
goto err;
}
@@ -462,8 +463,8 @@ __qam_append(dbc, key, data)
if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
ret = t_ret;
- if ((t_ret
- = __qam_fput(dbp, pg, page, DB_MPOOL_DIRTY)) != 0 && ret == 0)
+ if ((t_ret =
+ __qam_fput(dbp, pg, page, DB_MPOOL_DIRTY)) != 0 && ret == 0)
ret = t_ret;
/* Return the record number to the user. */
@@ -478,18 +479,18 @@ __qam_append(dbc, key, data)
qp = (QUEUE *) dbp->q_internal;
if (qp->page_ext != 0 &&
(recno % (qp->page_ext * qp->rec_page) == 0 ||
- recno == UINT32_T_MAX)) {
+ recno == UINT32_MAX)) {
if ((ret = __db_lget(dbc,
0, ((QUEUE *)dbp->q_internal)->q_meta,
DB_LOCK_WRITE, 0, &lock)) != 0)
goto err;
if (!QAM_AFTER_CURRENT(meta, recno))
ret = __qam_fclose(dbp, pg);
- (void)__LPUT(dbc, lock);
+ if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
+ ret = t_ret;
}
-err:
- /* Release the meta page. */
+err: /* Release the meta page. */
if ((t_ret = __memp_fput(mpf, meta, DB_MPOOL_DIRTY)) != 0 && ret == 0)
ret = t_ret;
@@ -543,22 +544,20 @@ __qam_c_del(dbc)
ret = t_ret;
if (ret != 0)
- goto err1;
+ goto err;
if ((ret = __db_lget(dbc,
0, cp->recno, DB_LOCK_WRITE, DB_LOCK_RECORD, &lock)) != 0)
- goto err1;
-
+ goto err;
cp->lock_mode = DB_LOCK_WRITE;
+
/* Find the record ; delete only deletes exact matches. */
- if ((ret = __qam_position(dbc,
- &cp->recno, QAM_WRITE, &exact)) != 0) {
- cp->lock = lock;
- goto err1;
- }
+ if ((ret = __qam_position(dbc, &cp->recno, QAM_WRITE, &exact)) != 0)
+ goto err;
+
if (!exact) {
ret = DB_NOTFOUND;
- goto err1;
+ goto err;
}
pagep = cp->page;
@@ -570,14 +569,14 @@ __qam_c_del(dbc)
if ((ret = __qam_del_log(dbp,
dbc->txn, &LSN(pagep), 0, &LSN(pagep),
pagep->pgno, cp->indx, cp->recno)) != 0)
- goto err1;
+ goto err;
} else {
data.size = ((QUEUE *)dbp->q_internal)->re_len;
data.data = qp->data;
if ((ret = __qam_delext_log(dbp,
dbc->txn, &LSN(pagep), 0, &LSN(pagep),
pagep->pgno, cp->indx, cp->recno, &data)) != 0)
- goto err1;
+ goto err;
}
}
@@ -587,14 +586,13 @@ __qam_c_del(dbc)
pg = ((QUEUE *)dbp->q_internal)->q_meta;
if ((ret =
__db_lget(dbc, 0, pg, DB_LOCK_WRITE, 0, &metalock)) != 0)
- goto err1;
+ goto err;
ret = __qam_consume(dbc, meta, first);
if ((t_ret = __LPUT(dbc, metalock)) != 0 && ret == 0)
ret = t_ret;
}
-err1:
- if ((t_ret = __memp_fput(mpf, meta, 0)) != 0 && ret == 0)
+err: if ((t_ret = __memp_fput(mpf, meta, 0)) != 0 && ret == 0)
ret = t_ret;
if (cp->page != NULL && (t_ret = __qam_fput(dbp, cp->pgno,
cp->page, ret == 0 ? DB_MPOOL_DIRTY : 0)) != 0 && ret == 0)
@@ -639,7 +637,7 @@ __qam_c_get(dbc, key, data, flags, pgnop)
db_pgno_t metapno;
db_recno_t first;
qam_position_mode mode;
- int exact, is_first, locked, ret, t_ret, wait, with_delete;
+ int exact, inorder, is_first, locked, ret, t_ret, wait, with_delete;
int put_mode, retrying;
dbp = dbc->dbp;
@@ -654,6 +652,7 @@ __qam_c_get(dbc, key, data, flags, pgnop)
retrying = 0;
lock_mode = DB_LOCK_READ;
meta = NULL;
+ inorder = F_ISSET(dbp, DB_AM_INORDER);
put_mode = 0;
t_ret = 0;
*pgnop = 0;
@@ -701,7 +700,8 @@ __qam_c_get(dbc, key, data, flags, pgnop)
first = 0;
/* Release any previous lock if not in a transaction. */
- (void)__TLPUT(dbc, cp->lock);
+ if ((ret = __TLPUT(dbc, cp->lock)) != 0)
+ goto err;
retry: /* Update the record number. */
switch (flags) {
@@ -713,7 +713,7 @@ retry: /* Update the record number. */
/* NOTREACHED */
case DB_NEXT:
case DB_NEXT_NODUP:
- if (cp->recno != RECNO_OOB) {
+get_next: if (cp->recno != RECNO_OOB) {
++cp->recno;
/* Wrap around, skipping zero. */
if (cp->recno == RECNO_OOB)
@@ -773,7 +773,8 @@ retry: /* Update the record number. */
lock_mode, 0, &metalock)) != 0)
goto err;
locked = 1;
- if (cp->recno != RECNO_OOB &&
+ if (cp->recno != meta->cur_recno &&
+ cp->recno != RECNO_OOB &&
!QAM_AFTER_CURRENT(meta, cp->recno))
goto retry;
}
@@ -791,11 +792,13 @@ retry: /* Update the record number. */
if ((ret = __memp_fget(
mpf, &metapno, 0, &meta)) != 0)
goto err;
- if ((ret = __lock_get(dbenv,
- dbc->locker, DB_LOCK_UPGRADE,
- &dbc->lock_dbt, DB_LOCK_WRITE,
- &metalock)) != 0)
+ if ((ret = __db_lget(dbc, 0,
+ PGNO_INVALID, DB_LOCK_WRITE,
+ DB_LOCK_UPGRADE, &metalock)) != 0) {
+ if (ret == DB_LOCK_DEADLOCK)
+ ret = DB_LOCK_NOTGRANTED;
goto err;
+ }
locked = 1;
goto retry;
}
@@ -838,8 +841,7 @@ retry: /* Update the record number. */
case DB_SET_RANGE:
case DB_GET_BOTH:
case DB_GET_BOTH_RANGE:
- if ((ret = __qam_getno(dbp,
- key, &cp->recno)) != 0)
+ if ((ret = __qam_getno(dbp, key, &cp->recno)) != 0)
goto err;
if (QAM_NOT_VALID(meta, cp->recno)) {
ret = DB_NOTFOUND;
@@ -884,13 +886,15 @@ retry: /* Update the record number. */
* since the first/last may have moved while we slept.
* We release our locks and try again.
*/
- if ((!with_delete && is_first) || flags == DB_LAST) {
+ if (((inorder || !with_delete) && is_first) || flags == DB_LAST) {
+get_first:
if ((ret =
__db_lget(dbc, 0, metapno, lock_mode, 0, &metalock)) != 0)
goto err;
if (cp->recno !=
(is_first ? meta->first_recno : (meta->cur_recno - 1))) {
- __LPUT(dbc, lock);
+ if ((ret = __LPUT(dbc, lock)) != 0)
+ goto err;
if (is_first)
flags = DB_FIRST;
locked = 1;
@@ -914,36 +918,44 @@ retry: /* Update the record number. */
cp->lock_mode = lock_mode;
if (!exact) {
- if (flags == DB_NEXT || flags == DB_NEXT_NODUP ||
- flags == DB_PREV || flags == DB_PREV_NODUP ||
- flags == DB_LAST) {
- /* Release locks and try again. */
- if (pg != NULL)
- (void)__qam_fput(dbp, cp->pgno, pg, 0);
- cp->page = pg = NULL;
- (void)__LPUT(dbc, pglock);
- (void)__LPUT(dbc, cp->lock);
- if (flags == DB_LAST)
- flags = DB_PREV;
+release_retry: /* Release locks and retry, if possible. */
+ if (pg != NULL)
+ (void)__qam_fput(dbp, cp->pgno, pg, 0);
+ cp->page = pg = NULL;
+ if ((ret = __LPUT(dbc, pglock)) != 0)
+ goto err1;
+
+ switch (flags) {
+ case DB_GET_BOTH_RANGE:
+ flags = DB_SET_RANGE;
+ /* FALLTHROUGH */
+ case DB_NEXT:
+ case DB_NEXT_NODUP:
+ case DB_SET_RANGE:
if (!with_delete)
is_first = 0;
+ /* Peek at the meta page unlocked. */
+ if (QAM_BEFORE_FIRST(meta, cp->recno))
+ goto get_first;
+ /* FALLTHROUGH */
+ case DB_PREV:
+ case DB_PREV_NODUP:
+ case DB_LAST:
+ if (flags == DB_LAST)
+ flags = DB_PREV;
retrying = 0;
- goto retry;
- }
- /* this is for the SET and SET_RANGE cases */
- ret = DB_KEYEMPTY;
- goto err1;
- }
+ if ((ret = __LPUT(dbc, cp->lock)) != 0)
+ goto err1;
+ if (flags == DB_SET_RANGE)
+ goto get_next;
+ else
+ goto retry;
- /* Return the key if the user didn't give us one. */
- if (key != NULL) {
- if (flags != DB_GET_BOTH && flags != DB_GET_BOTH_RANGE &&
- flags != DB_SET && flags != DB_SET_RANGE &&
- (ret = __db_retcopy(dbp->dbenv,
- key, &cp->recno, sizeof(cp->recno),
- &dbc->rkey->data, &dbc->rkey->ulen)) != 0)
+ default:
+ /* this is for the SET and GET_BOTH cases */
+ ret = DB_KEYEMPTY;
goto err1;
- F_SET(key, DB_DBT_ISSET);
+ }
}
qp = QAM_GET_RECORD(dbp, pg, cp->indx);
@@ -956,18 +968,30 @@ retry: /* Update the record number. */
tmp.data = qp->data;
tmp.size = t->re_len;
if ((ret = __bam_defcmp(dbp, data, &tmp)) != 0) {
+ if (flags == DB_GET_BOTH_RANGE)
+ goto release_retry;
ret = DB_NOTFOUND;
goto err1;
}
}
- if (data != NULL &&
- !F_ISSET(dbc, DBC_MULTIPLE|DBC_MULTIPLE_KEY) &&
- (ret = __db_retcopy(dbp->dbenv, data,
- qp->data, t->re_len, &dbc->rdata->data, &dbc->rdata->ulen)) != 0)
- goto err1;
- if (data != NULL)
+ /* Return the key if the user didn't give us one. */
+ if (key != NULL) {
+ if (flags != DB_GET_BOTH && flags != DB_SET &&
+ (ret = __db_retcopy(dbp->dbenv,
+ key, &cp->recno, sizeof(cp->recno),
+ &dbc->rkey->data, &dbc->rkey->ulen)) != 0)
+ goto err1;
+ F_SET(key, DB_DBT_ISSET);
+ }
+
+ if (data != NULL) {
+ if (!F_ISSET(dbc, DBC_MULTIPLE|DBC_MULTIPLE_KEY) &&
+ (ret = __db_retcopy(dbp->dbenv, data, qp->data, t->re_len,
+ &dbc->rdata->data, &dbc->rdata->ulen)) != 0)
+ goto err1;
F_SET(data, DB_DBT_ISSET);
+ }
/* Finally, if we are doing DB_CONSUME mark the record. */
if (with_delete) {
@@ -1068,41 +1092,28 @@ retry: /* Update the record number. */
done:
err1: if (cp->page != NULL) {
- t_ret = __qam_fput(dbp, cp->pgno, cp->page, put_mode);
-
- if (!ret)
+ if ((t_ret = __qam_fput(
+ dbp, cp->pgno, cp->page, put_mode)) != 0 && ret == 0)
ret = t_ret;
+
/* Doing record locking, release the page lock */
- t_ret = __LPUT(dbc, pglock);
+ if ((t_ret = __LPUT(dbc, pglock)) != 0 && ret == 0)
+ ret = t_ret;
cp->page = NULL;
}
-err: if (!ret)
- ret = t_ret;
- if (meta) {
-
- /* release the meta page */
- t_ret = __memp_fput(mpf, meta, 0);
-
- if (!ret)
+err: if (meta) {
+ /* Release the meta page. */
+ if ((t_ret = __memp_fput(mpf, meta, 0)) != 0 && ret == 0)
ret = t_ret;
/* Don't hold the meta page long term. */
if (locked)
- t_ret = __LPUT(dbc, metalock);
+ if ((t_ret = __LPUT(dbc, metalock)) != 0 && ret == 0)
+ ret = t_ret;
}
DB_ASSERT(!LOCK_ISSET(metalock));
- /*
- * There is no need to keep the record locked if we are
- * not in a transaction.
- */
- if (t_ret == 0)
- t_ret = __TLPUT(dbc, cp->lock);
-
- if (!ret)
- ret = t_ret;
-
return ((ret == DB_LOCK_NOTGRANTED &&
!F_ISSET(dbenv, DB_ENV_TIME_NOTGRANTED)) ?
DB_LOCK_DEADLOCK : ret);
@@ -1112,7 +1123,6 @@ err: if (!ret)
* __qam_consume -- try to reset the head of the queue.
*
*/
-
static int
__qam_consume(dbc, meta, first)
DBC *dbc;
@@ -1126,14 +1136,14 @@ __qam_consume(dbc, meta, first)
db_indx_t save_indx;
db_pgno_t save_page;
db_recno_t current, save_recno;
- u_int32_t rec_extent;
- int exact, put_mode, ret, t_ret, wrapped;
+ u_int32_t put_mode, rec_extent;
+ int exact, ret, t_ret, wrapped;
dbp = dbc->dbp;
mpf = dbp->mpf;
cp = (QUEUE_CURSOR *)dbc->internal;
put_mode = DB_MPOOL_DIRTY;
- ret = t_ret = 0;
+ ret = 0;
save_page = cp->pgno;
save_indx = cp->indx;
@@ -1189,7 +1199,7 @@ __qam_consume(dbc, meta, first)
if (cp->page != NULL && rec_extent != 0 &&
((exact = (first % rec_extent == 0)) ||
first % meta->rec_page == 0 ||
- first == UINT32_T_MAX)) {
+ first == UINT32_MAX)) {
if (exact == 1 && (ret = __db_lget(dbc,
0, cp->pgno, DB_LOCK_WRITE, 0, &cp->lock)) != 0)
break;
@@ -1207,14 +1217,12 @@ __qam_consume(dbc, meta, first)
if (exact == 1) {
ret = __qam_fremove(dbp, cp->pgno);
- t_ret = __LPUT(dbc, cp->lock);
+ if ((t_ret =
+ __LPUT(dbc, cp->lock)) != 0 && ret == 0)
+ ret = t_ret;
}
if (ret != 0)
break;
- if (t_ret != 0) {
- ret = t_ret;
- break;
- }
} else if (cp->page != NULL && (ret =
__qam_fput(dbp, cp->pgno, cp->page, put_mode)) != 0)
break;
@@ -1292,13 +1300,14 @@ __qam_bulk(dbc, data, flags)
u_int32_t flags;
{
DB *dbp;
- DB_LOCK metalock;
+ DB_LOCK metalock, rlock;
DB_MPOOLFILE *mpf;
PAGE *pg;
QMETA *meta;
QAMDATA *qp;
QUEUE_CURSOR *cp;
db_indx_t indx;
+ db_lockmode_t lkmode;
db_pgno_t metapno;
qam_position_mode mode;
int32_t *endp, *offp;
@@ -1311,8 +1320,11 @@ __qam_bulk(dbc, data, flags)
cp = (QUEUE_CURSOR *)dbc->internal;
mode = QAM_READ;
- if (F_ISSET(dbc, DBC_RMW))
+ lkmode = DB_LOCK_READ;
+ if (F_ISSET(dbc, DBC_RMW)) {
mode = QAM_WRITE;
+ lkmode = DB_LOCK_WRITE;
+ }
pagesize = dbp->pgsize;
re_len = ((QUEUE *)dbp->q_internal)->re_len;
@@ -1341,6 +1353,9 @@ __qam_bulk(dbc, data, flags)
endp = (int32_t *) ((u_int8_t *)dbuf + data->ulen);
endp--;
offp = endp;
+ /* Save the lock on the current position of the cursor. */
+ rlock = cp->lock;
+ LOCK_INIT(cp->lock);
next_pg:
/* Wrap around, skipping zero. */
@@ -1363,6 +1378,9 @@ next_pg:
valid = 0;
if (pg != NULL) {
+ if ((ret = __db_lget(dbc, LCK_COUPLE,
+ cp->recno, lkmode, DB_LOCK_RECORD, &rlock)) != 0)
+ goto done;
qp = QAM_GET_RECORD(dbp, pg, indx);
if (F_ISSET(qp, QAM_VALID)) {
valid = 1;
@@ -1375,11 +1393,11 @@ next_pg:
if (space < size) {
get_space:
if (offp == endp) {
- data->size =
- ALIGN(size +
+ data->size = (u_int32_t)
+ DB_ALIGN(size +
pagesize,
sizeof(u_int32_t));
- ret = ENOMEM;
+ ret = DB_BUFFER_SMALL;
break;
}
if (indx != 0)
@@ -1411,7 +1429,8 @@ get_space:
cp->recno != meta->cur_recno &&
!QAM_AFTER_CURRENT(meta, cp->recno));
- if ((t_ret = __TLPUT(dbc, cp->lock)) != 0 && ret == 0)
+ /* Drop the page lock. */
+ if ((t_ret = __LPUT(dbc, cp->lock)) != 0 && ret == 0)
ret = t_ret;
if (cp->page != NULL) {
@@ -1440,14 +1459,13 @@ get_space:
else
*offp = -1;
-done:
- /* release the meta page */
- t_ret = __memp_fput(mpf, meta, 0);
-
- if (!ret)
+done: /* Release the meta page. */
+ if ((t_ret = __memp_fput(mpf, meta, 0)) != 0 && ret == 0)
+ ret = t_ret;
+ if ((t_ret = __LPUT(dbc, metalock)) != 0 && ret == 0)
ret = t_ret;
- t_ret = __LPUT(dbc, metalock);
+ cp->lock = rlock;
return (ret);
}
@@ -1463,6 +1481,7 @@ __qam_c_close(dbc, root_pgno, rmroot)
int *rmroot;
{
QUEUE_CURSOR *cp;
+ int ret;
COMPQUIET(root_pgno, 0);
COMPQUIET(rmroot, NULL);
@@ -1470,9 +1489,9 @@ __qam_c_close(dbc, root_pgno, rmroot)
cp = (QUEUE_CURSOR *)dbc->internal;
/* Discard any locks not acquired inside of a transaction. */
- (void)__TLPUT(dbc, cp->lock);
- LOCK_INIT(cp->lock);
+ ret = __TLPUT(dbc, cp->lock);
+ LOCK_INIT(cp->lock);
cp->page = NULL;
cp->pgno = PGNO_INVALID;
cp->indx = 0;
@@ -1480,7 +1499,7 @@ __qam_c_close(dbc, root_pgno, rmroot)
cp->recno = RECNO_OOB;
cp->flags = 0;
- return (0);
+ return (ret);
}
/*
@@ -1495,19 +1514,20 @@ __qam_c_dup(orig_dbc, new_dbc)
DBC *orig_dbc, *new_dbc;
{
QUEUE_CURSOR *orig, *new;
+ int ret;
orig = (QUEUE_CURSOR *)orig_dbc->internal;
new = (QUEUE_CURSOR *)new_dbc->internal;
new->recno = orig->recno;
- /* reget the long term lock if we are not in a xact */
- if (orig_dbc->txn != NULL ||
- !STD_LOCKING(orig_dbc) || !LOCK_ISSET(orig->lock))
- return (0);
+ /* Acquire the long term lock if we are not in a transaction. */
+ if (orig_dbc->txn == NULL && LOCK_ISSET(orig->lock))
+ if ((ret = __db_lget(new_dbc, 0, new->recno,
+ new->lock_mode, DB_LOCK_RECORD, &new->lock)) != 0)
+ return (ret);
- return (__db_lget(new_dbc,
- 0, new->recno, new->lock_mode, DB_LOCK_RECORD, &new->lock));
+ return (0);
}
/*
@@ -1601,24 +1621,22 @@ __qam_truncate(dbc, countp)
QMETA *meta;
QUEUE_CURSOR *cp;
db_pgno_t metapno;
- int count, ret, t_ret;
+ u_int32_t count;
+ int ret, t_ret;
dbp = dbc->dbp;
/* Walk the queue, counting rows. */
- count = 0;
- while ((ret = __qam_c_get(dbc, NULL, NULL, DB_CONSUME, &metapno)) == 0)
+ for (count = 0;
+ (ret = __qam_c_get(dbc, NULL, NULL, DB_CONSUME, &metapno)) == 0;)
count++;
-
- if (ret == DB_NOTFOUND)
- ret = 0;
- else
+ if (ret != DB_NOTFOUND)
return (ret);
cp = (QUEUE_CURSOR *)dbc->internal;
/* Remove the last extent file. */
if (cp->pgno != 0 &&
- ((QUEUE *)dbp->q_internal)->page_ext != 0 &&
+ ((QUEUE *)dbp->q_internal)->page_ext != 0 &&
(ret = __qam_fremove(dbp, cp->pgno)) != 0)
return (ret);
diff --git a/db/qam/qam.src b/db/qam/qam.src
index 34eada651..71063f0b6 100644
--- a/db/qam/qam.src
+++ b/db/qam/qam.src
@@ -1,17 +1,15 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999-2003
+ * Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
*
- * $Id: qam.src,v 11.31 2003/11/14 05:32:38 ubell Exp $
+ * $Id: qam.src,v 11.33 2004/06/17 17:35:22 bostic Exp $
*/
PREFIX __qam
DBPRIVATE
-INCLUDE #include "db_config.h"
-INCLUDE
INCLUDE #ifndef NO_SYSTEM_INCLUDES
INCLUDE #include <sys/types.h>
INCLUDE
diff --git a/db/qam/qam_auto.c b/db/qam/qam_auto.c
index a108e347a..e20cbd934 100644
--- a/db/qam/qam_auto.c
+++ b/db/qam/qam_auto.c
@@ -1,4 +1,5 @@
/* Do not edit: automatically built by gen_rec.awk. */
+
#include "db_config.h"
#ifndef NO_SYSTEM_INCLUDES
@@ -33,33 +34,42 @@ __qam_incfirst_log(dbp, txnid, ret_lsnp, flags, recno, meta_pgno)
DBT logrec;
DB_ENV *dbenv;
DB_TXNLOGREC *lr;
- DB_LSN *lsnp, null_lsn;
+ DB_LSN *lsnp, null_lsn, *rlsnp;
u_int32_t uinttmp, rectype, txn_num;
u_int npad;
u_int8_t *bp;
int is_durable, ret;
dbenv = dbp->dbenv;
+ COMPQUIET(lr, NULL);
+
rectype = DB___qam_incfirst;
npad = 0;
+ rlsnp = ret_lsnp;
+
+ ret = 0;
- is_durable = 1;
if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
- F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) ||
F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
- if (F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) && txnid == NULL)
- return (0);
is_durable = 0;
- }
+ } else
+ is_durable = 1;
+
if (txnid == NULL) {
txn_num = 0;
- null_lsn.file = 0;
- null_lsn.offset = 0;
lsnp = &null_lsn;
+ null_lsn.file = null_lsn.offset = 0;
} else {
if (TAILQ_FIRST(&txnid->kids) != NULL &&
(ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
return (ret);
+ /*
+ * We need to assign begin_lsn while holding region mutex.
+ * That assignment is done inside the DbEnv->log_put call,
+ * so pass in the appropriate memory location to be filled
+ * in by the log_put code.
+ */
+ DB_SET_BEGIN_LSNP(txnid, &rlsnp);
txn_num = txnid->txnid;
lsnp = &txnid->last_lsn;
}
@@ -74,27 +84,23 @@ __qam_incfirst_log(dbp, txnid, ret_lsnp, flags, recno, meta_pgno)
logrec.size += npad;
}
- if (!is_durable && txnid != NULL) {
+ if (is_durable || txnid == NULL) {
+ if ((ret =
+ __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
+ return (ret);
+ } else {
if ((ret = __os_malloc(dbenv,
logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
return (ret);
#ifdef DIAGNOSTIC
- goto do_malloc;
-#else
- logrec.data = &lr->data;
-#endif
- } else {
-#ifdef DIAGNOSTIC
-do_malloc:
-#endif
if ((ret =
__os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
-#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL)
- (void)__os_free(dbenv, lr);
-#endif
+ __os_free(dbenv, lr);
return (ret);
}
+#else
+ logrec.data = lr->data;
+#endif
}
if (npad > 0)
memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
@@ -129,123 +135,47 @@ do_malloc:
DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
+ if (is_durable || txnid == NULL) {
+ if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
+ flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
+ txnid->last_lsn = *rlsnp;
+ if (rlsnp != ret_lsnp)
+ *ret_lsnp = *rlsnp;
+ }
+ } else {
#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL) {
- /*
- * We set the debug bit if we are going
- * to log non-durable transactions so
- * they will be ignored by recovery.
+ /*
+ * Set the debug bit if we are going to log non-durable
+ * transactions so they will be ignored by recovery.
*/
memcpy(lr->data, logrec.data, logrec.size);
rectype |= DB_debug_FLAG;
memcpy(logrec.data, &rectype, sizeof(rectype));
- }
-#endif
- if (!is_durable && txnid != NULL) {
+ ret = __log_put(dbenv,
+ rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
+#else
ret = 0;
- STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
-#ifdef DIAGNOSTIC
- goto do_put;
#endif
- } else{
-#ifdef DIAGNOSTIC
-do_put:
-#endif
- ret = __log_put(dbenv,
- ret_lsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
- if (ret == 0 && txnid != NULL)
- txnid->last_lsn = *ret_lsnp;
+ STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
+ LSN_NOT_LOGGED(*ret_lsnp);
}
- if (!is_durable)
- LSN_NOT_LOGGED(*ret_lsnp);
#ifdef LOG_DIAGNOSTIC
if (ret != 0)
(void)__qam_incfirst_print(dbenv,
(DBT *)&logrec, ret_lsnp, NULL, NULL);
#endif
-#ifndef DIAGNOSTIC
+
+#ifdef DIAGNOSTIC
+ __os_free(dbenv, logrec.data);
+#else
if (is_durable || txnid == NULL)
-#endif
__os_free(dbenv, logrec.data);
-
+#endif
return (ret);
}
-#ifdef HAVE_REPLICATION
-/*
- * PUBLIC: int __qam_incfirst_getpgnos __P((DB_ENV *, DBT *,
- * PUBLIC: DB_LSN *, db_recops, void *));
- */
-int
-__qam_incfirst_getpgnos(dbenv, rec, lsnp, notused1, summary)
- DB_ENV *dbenv;
- DBT *rec;
- DB_LSN *lsnp;
- db_recops notused1;
- void *summary;
-{
- TXN_RECS *t;
- int ret;
- COMPQUIET(rec, NULL);
- COMPQUIET(notused1, DB_TXN_ABORT);
-
- t = (TXN_RECS *)summary;
-
- if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0)
- return (ret);
-
- t->array[t->npages].flags = LSN_PAGE_NOLOCK;
- t->array[t->npages].lsn = *lsnp;
- t->array[t->npages].fid = DB_LOGFILEID_INVALID;
- memset(&t->array[t->npages].pgdesc, 0,
- sizeof(t->array[t->npages].pgdesc));
-
- t->npages++;
-
- return (0);
-}
-#endif /* HAVE_REPLICATION */
-
-/*
- * PUBLIC: int __qam_incfirst_print __P((DB_ENV *, DBT *, DB_LSN *,
- * PUBLIC: db_recops, void *));
- */
-int
-__qam_incfirst_print(dbenv, dbtp, lsnp, notused2, notused3)
- DB_ENV *dbenv;
- DBT *dbtp;
- DB_LSN *lsnp;
- db_recops notused2;
- void *notused3;
-{
- __qam_incfirst_args *argp;
- int ret;
-
- notused2 = DB_TXN_ABORT;
- notused3 = NULL;
-
- if ((ret = __qam_incfirst_read(dbenv, dbtp->data, &argp)) != 0)
- return (ret);
- (void)printf(
- "[%lu][%lu]__qam_incfirst%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
- (u_long)lsnp->file,
- (u_long)lsnp->offset,
- (argp->type & DB_debug_FLAG) ? "_debug" : "",
- (u_long)argp->type,
- (u_long)argp->txnid->txnid,
- (u_long)argp->prev_lsn.file,
- (u_long)argp->prev_lsn.offset);
- (void)printf("\tfileid: %ld\n", (long)argp->fileid);
- (void)printf("\trecno: %lu\n", (u_long)argp->recno);
- (void)printf("\tmeta_pgno: %lu\n", (u_long)argp->meta_pgno);
- (void)printf("\n");
- __os_free(dbenv, argp);
-
- return (0);
-}
-
/*
* PUBLIC: int __qam_incfirst_read __P((DB_ENV *, void *,
* PUBLIC: __qam_incfirst_args **));
@@ -264,9 +194,9 @@ __qam_incfirst_read(dbenv, recbuf, argpp)
if ((ret = __os_malloc(dbenv,
sizeof(__qam_incfirst_args) + sizeof(DB_TXN), &argp)) != 0)
return (ret);
+ bp = recbuf;
argp->txnid = (DB_TXN *)&argp[1];
- bp = recbuf;
memcpy(&argp->type, bp, sizeof(argp->type));
bp += sizeof(argp->type);
@@ -316,33 +246,42 @@ __qam_mvptr_log(dbp, txnid, ret_lsnp, flags,
DBT logrec;
DB_ENV *dbenv;
DB_TXNLOGREC *lr;
- DB_LSN *lsnp, null_lsn;
+ DB_LSN *lsnp, null_lsn, *rlsnp;
u_int32_t uinttmp, rectype, txn_num;
u_int npad;
u_int8_t *bp;
int is_durable, ret;
dbenv = dbp->dbenv;
+ COMPQUIET(lr, NULL);
+
rectype = DB___qam_mvptr;
npad = 0;
+ rlsnp = ret_lsnp;
+
+ ret = 0;
- is_durable = 1;
if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
- F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) ||
F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
- if (F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) && txnid == NULL)
- return (0);
is_durable = 0;
- }
+ } else
+ is_durable = 1;
+
if (txnid == NULL) {
txn_num = 0;
- null_lsn.file = 0;
- null_lsn.offset = 0;
lsnp = &null_lsn;
+ null_lsn.file = null_lsn.offset = 0;
} else {
if (TAILQ_FIRST(&txnid->kids) != NULL &&
(ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
return (ret);
+ /*
+ * We need to assign begin_lsn while holding region mutex.
+ * That assignment is done inside the DbEnv->log_put call,
+ * so pass in the appropriate memory location to be filled
+ * in by the log_put code.
+ */
+ DB_SET_BEGIN_LSNP(txnid, &rlsnp);
txn_num = txnid->txnid;
lsnp = &txnid->last_lsn;
}
@@ -362,27 +301,23 @@ __qam_mvptr_log(dbp, txnid, ret_lsnp, flags,
logrec.size += npad;
}
- if (!is_durable && txnid != NULL) {
+ if (is_durable || txnid == NULL) {
+ if ((ret =
+ __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
+ return (ret);
+ } else {
if ((ret = __os_malloc(dbenv,
logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
return (ret);
#ifdef DIAGNOSTIC
- goto do_malloc;
-#else
- logrec.data = &lr->data;
-#endif
- } else {
-#ifdef DIAGNOSTIC
-do_malloc:
-#endif
if ((ret =
__os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
-#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL)
- (void)__os_free(dbenv, lr);
-#endif
+ __os_free(dbenv, lr);
return (ret);
}
+#else
+ logrec.data = lr->data;
+#endif
}
if (npad > 0)
memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
@@ -439,129 +374,47 @@ do_malloc:
DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
+ if (is_durable || txnid == NULL) {
+ if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
+ flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
+ txnid->last_lsn = *rlsnp;
+ if (rlsnp != ret_lsnp)
+ *ret_lsnp = *rlsnp;
+ }
+ } else {
#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL) {
- /*
- * We set the debug bit if we are going
- * to log non-durable transactions so
- * they will be ignored by recovery.
+ /*
+ * Set the debug bit if we are going to log non-durable
+ * transactions so they will be ignored by recovery.
*/
memcpy(lr->data, logrec.data, logrec.size);
rectype |= DB_debug_FLAG;
memcpy(logrec.data, &rectype, sizeof(rectype));
- }
-#endif
- if (!is_durable && txnid != NULL) {
+ ret = __log_put(dbenv,
+ rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
+#else
ret = 0;
- STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
-#ifdef DIAGNOSTIC
- goto do_put;
-#endif
- } else{
-#ifdef DIAGNOSTIC
-do_put:
#endif
- ret = __log_put(dbenv,
- ret_lsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
- if (ret == 0 && txnid != NULL)
- txnid->last_lsn = *ret_lsnp;
+ STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
+ LSN_NOT_LOGGED(*ret_lsnp);
}
- if (!is_durable)
- LSN_NOT_LOGGED(*ret_lsnp);
#ifdef LOG_DIAGNOSTIC
if (ret != 0)
(void)__qam_mvptr_print(dbenv,
(DBT *)&logrec, ret_lsnp, NULL, NULL);
#endif
-#ifndef DIAGNOSTIC
+
+#ifdef DIAGNOSTIC
+ __os_free(dbenv, logrec.data);
+#else
if (is_durable || txnid == NULL)
-#endif
__os_free(dbenv, logrec.data);
-
+#endif
return (ret);
}
-#ifdef HAVE_REPLICATION
-/*
- * PUBLIC: int __qam_mvptr_getpgnos __P((DB_ENV *, DBT *, DB_LSN *,
- * PUBLIC: db_recops, void *));
- */
-int
-__qam_mvptr_getpgnos(dbenv, rec, lsnp, notused1, summary)
- DB_ENV *dbenv;
- DBT *rec;
- DB_LSN *lsnp;
- db_recops notused1;
- void *summary;
-{
- TXN_RECS *t;
- int ret;
- COMPQUIET(rec, NULL);
- COMPQUIET(notused1, DB_TXN_ABORT);
-
- t = (TXN_RECS *)summary;
-
- if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0)
- return (ret);
-
- t->array[t->npages].flags = LSN_PAGE_NOLOCK;
- t->array[t->npages].lsn = *lsnp;
- t->array[t->npages].fid = DB_LOGFILEID_INVALID;
- memset(&t->array[t->npages].pgdesc, 0,
- sizeof(t->array[t->npages].pgdesc));
-
- t->npages++;
-
- return (0);
-}
-#endif /* HAVE_REPLICATION */
-
-/*
- * PUBLIC: int __qam_mvptr_print __P((DB_ENV *, DBT *, DB_LSN *,
- * PUBLIC: db_recops, void *));
- */
-int
-__qam_mvptr_print(dbenv, dbtp, lsnp, notused2, notused3)
- DB_ENV *dbenv;
- DBT *dbtp;
- DB_LSN *lsnp;
- db_recops notused2;
- void *notused3;
-{
- __qam_mvptr_args *argp;
- int ret;
-
- notused2 = DB_TXN_ABORT;
- notused3 = NULL;
-
- if ((ret = __qam_mvptr_read(dbenv, dbtp->data, &argp)) != 0)
- return (ret);
- (void)printf(
- "[%lu][%lu]__qam_mvptr%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
- (u_long)lsnp->file,
- (u_long)lsnp->offset,
- (argp->type & DB_debug_FLAG) ? "_debug" : "",
- (u_long)argp->type,
- (u_long)argp->txnid->txnid,
- (u_long)argp->prev_lsn.file,
- (u_long)argp->prev_lsn.offset);
- (void)printf("\topcode: %lu\n", (u_long)argp->opcode);
- (void)printf("\tfileid: %ld\n", (long)argp->fileid);
- (void)printf("\told_first: %lu\n", (u_long)argp->old_first);
- (void)printf("\tnew_first: %lu\n", (u_long)argp->new_first);
- (void)printf("\told_cur: %lu\n", (u_long)argp->old_cur);
- (void)printf("\tnew_cur: %lu\n", (u_long)argp->new_cur);
- (void)printf("\tmetalsn: [%lu][%lu]\n",
- (u_long)argp->metalsn.file, (u_long)argp->metalsn.offset);
- (void)printf("\tmeta_pgno: %lu\n", (u_long)argp->meta_pgno);
- (void)printf("\n");
- __os_free(dbenv, argp);
-
- return (0);
-}
-
/*
* PUBLIC: int __qam_mvptr_read __P((DB_ENV *, void *, __qam_mvptr_args **));
*/
@@ -579,9 +432,9 @@ __qam_mvptr_read(dbenv, recbuf, argpp)
if ((ret = __os_malloc(dbenv,
sizeof(__qam_mvptr_args) + sizeof(DB_TXN), &argp)) != 0)
return (ret);
+ bp = recbuf;
argp->txnid = (DB_TXN *)&argp[1];
- bp = recbuf;
memcpy(&argp->type, bp, sizeof(argp->type));
bp += sizeof(argp->type);
@@ -644,33 +497,42 @@ __qam_del_log(dbp, txnid, ret_lsnp, flags, lsn, pgno, indx, recno)
DBT logrec;
DB_ENV *dbenv;
DB_TXNLOGREC *lr;
- DB_LSN *lsnp, null_lsn;
+ DB_LSN *lsnp, null_lsn, *rlsnp;
u_int32_t uinttmp, rectype, txn_num;
u_int npad;
u_int8_t *bp;
int is_durable, ret;
dbenv = dbp->dbenv;
+ COMPQUIET(lr, NULL);
+
rectype = DB___qam_del;
npad = 0;
+ rlsnp = ret_lsnp;
+
+ ret = 0;
- is_durable = 1;
if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
- F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) ||
F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
- if (F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) && txnid == NULL)
- return (0);
is_durable = 0;
- }
+ } else
+ is_durable = 1;
+
if (txnid == NULL) {
txn_num = 0;
- null_lsn.file = 0;
- null_lsn.offset = 0;
lsnp = &null_lsn;
+ null_lsn.file = null_lsn.offset = 0;
} else {
if (TAILQ_FIRST(&txnid->kids) != NULL &&
(ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
return (ret);
+ /*
+ * We need to assign begin_lsn while holding region mutex.
+ * That assignment is done inside the DbEnv->log_put call,
+ * so pass in the appropriate memory location to be filled
+ * in by the log_put code.
+ */
+ DB_SET_BEGIN_LSNP(txnid, &rlsnp);
txn_num = txnid->txnid;
lsnp = &txnid->last_lsn;
}
@@ -687,27 +549,23 @@ __qam_del_log(dbp, txnid, ret_lsnp, flags, lsn, pgno, indx, recno)
logrec.size += npad;
}
- if (!is_durable && txnid != NULL) {
+ if (is_durable || txnid == NULL) {
+ if ((ret =
+ __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
+ return (ret);
+ } else {
if ((ret = __os_malloc(dbenv,
logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
return (ret);
#ifdef DIAGNOSTIC
- goto do_malloc;
-#else
- logrec.data = &lr->data;
-#endif
- } else {
-#ifdef DIAGNOSTIC
-do_malloc:
-#endif
if ((ret =
__os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
-#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL)
- (void)__os_free(dbenv, lr);
-#endif
+ __os_free(dbenv, lr);
return (ret);
}
+#else
+ logrec.data = lr->data;
+#endif
}
if (npad > 0)
memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
@@ -752,126 +610,47 @@ do_malloc:
DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
+ if (is_durable || txnid == NULL) {
+ if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
+ flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
+ txnid->last_lsn = *rlsnp;
+ if (rlsnp != ret_lsnp)
+ *ret_lsnp = *rlsnp;
+ }
+ } else {
#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL) {
- /*
- * We set the debug bit if we are going
- * to log non-durable transactions so
- * they will be ignored by recovery.
+ /*
+ * Set the debug bit if we are going to log non-durable
+ * transactions so they will be ignored by recovery.
*/
memcpy(lr->data, logrec.data, logrec.size);
rectype |= DB_debug_FLAG;
memcpy(logrec.data, &rectype, sizeof(rectype));
- }
-#endif
- if (!is_durable && txnid != NULL) {
+ ret = __log_put(dbenv,
+ rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
+#else
ret = 0;
- STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
-#ifdef DIAGNOSTIC
- goto do_put;
-#endif
- } else{
-#ifdef DIAGNOSTIC
-do_put:
#endif
- ret = __log_put(dbenv,
- ret_lsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
- if (ret == 0 && txnid != NULL)
- txnid->last_lsn = *ret_lsnp;
+ STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
+ LSN_NOT_LOGGED(*ret_lsnp);
}
- if (!is_durable)
- LSN_NOT_LOGGED(*ret_lsnp);
#ifdef LOG_DIAGNOSTIC
if (ret != 0)
(void)__qam_del_print(dbenv,
(DBT *)&logrec, ret_lsnp, NULL, NULL);
#endif
-#ifndef DIAGNOSTIC
+
+#ifdef DIAGNOSTIC
+ __os_free(dbenv, logrec.data);
+#else
if (is_durable || txnid == NULL)
-#endif
__os_free(dbenv, logrec.data);
-
+#endif
return (ret);
}
-#ifdef HAVE_REPLICATION
-/*
- * PUBLIC: int __qam_del_getpgnos __P((DB_ENV *, DBT *, DB_LSN *,
- * PUBLIC: db_recops, void *));
- */
-int
-__qam_del_getpgnos(dbenv, rec, lsnp, notused1, summary)
- DB_ENV *dbenv;
- DBT *rec;
- DB_LSN *lsnp;
- db_recops notused1;
- void *summary;
-{
- TXN_RECS *t;
- int ret;
- COMPQUIET(rec, NULL);
- COMPQUIET(notused1, DB_TXN_ABORT);
-
- t = (TXN_RECS *)summary;
-
- if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0)
- return (ret);
-
- t->array[t->npages].flags = LSN_PAGE_NOLOCK;
- t->array[t->npages].lsn = *lsnp;
- t->array[t->npages].fid = DB_LOGFILEID_INVALID;
- memset(&t->array[t->npages].pgdesc, 0,
- sizeof(t->array[t->npages].pgdesc));
-
- t->npages++;
-
- return (0);
-}
-#endif /* HAVE_REPLICATION */
-
-/*
- * PUBLIC: int __qam_del_print __P((DB_ENV *, DBT *, DB_LSN *,
- * PUBLIC: db_recops, void *));
- */
-int
-__qam_del_print(dbenv, dbtp, lsnp, notused2, notused3)
- DB_ENV *dbenv;
- DBT *dbtp;
- DB_LSN *lsnp;
- db_recops notused2;
- void *notused3;
-{
- __qam_del_args *argp;
- int ret;
-
- notused2 = DB_TXN_ABORT;
- notused3 = NULL;
-
- if ((ret = __qam_del_read(dbenv, dbtp->data, &argp)) != 0)
- return (ret);
- (void)printf(
- "[%lu][%lu]__qam_del%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
- (u_long)lsnp->file,
- (u_long)lsnp->offset,
- (argp->type & DB_debug_FLAG) ? "_debug" : "",
- (u_long)argp->type,
- (u_long)argp->txnid->txnid,
- (u_long)argp->prev_lsn.file,
- (u_long)argp->prev_lsn.offset);
- (void)printf("\tfileid: %ld\n", (long)argp->fileid);
- (void)printf("\tlsn: [%lu][%lu]\n",
- (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
- (void)printf("\tpgno: %lu\n", (u_long)argp->pgno);
- (void)printf("\tindx: %lu\n", (u_long)argp->indx);
- (void)printf("\trecno: %lu\n", (u_long)argp->recno);
- (void)printf("\n");
- __os_free(dbenv, argp);
-
- return (0);
-}
-
/*
* PUBLIC: int __qam_del_read __P((DB_ENV *, void *, __qam_del_args **));
*/
@@ -889,9 +668,9 @@ __qam_del_read(dbenv, recbuf, argpp)
if ((ret = __os_malloc(dbenv,
sizeof(__qam_del_args) + sizeof(DB_TXN), &argp)) != 0)
return (ret);
+ bp = recbuf;
argp->txnid = (DB_TXN *)&argp[1];
- bp = recbuf;
memcpy(&argp->type, bp, sizeof(argp->type));
bp += sizeof(argp->type);
@@ -947,33 +726,42 @@ __qam_add_log(dbp, txnid, ret_lsnp, flags, lsn, pgno, indx, recno, data,
DBT logrec;
DB_ENV *dbenv;
DB_TXNLOGREC *lr;
- DB_LSN *lsnp, null_lsn;
+ DB_LSN *lsnp, null_lsn, *rlsnp;
u_int32_t zero, uinttmp, rectype, txn_num;
u_int npad;
u_int8_t *bp;
int is_durable, ret;
dbenv = dbp->dbenv;
+ COMPQUIET(lr, NULL);
+
rectype = DB___qam_add;
npad = 0;
+ rlsnp = ret_lsnp;
+
+ ret = 0;
- is_durable = 1;
if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
- F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) ||
F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
- if (F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) && txnid == NULL)
- return (0);
is_durable = 0;
- }
+ } else
+ is_durable = 1;
+
if (txnid == NULL) {
txn_num = 0;
- null_lsn.file = 0;
- null_lsn.offset = 0;
lsnp = &null_lsn;
+ null_lsn.file = null_lsn.offset = 0;
} else {
if (TAILQ_FIRST(&txnid->kids) != NULL &&
(ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
return (ret);
+ /*
+ * We need to assign begin_lsn while holding region mutex.
+ * That assignment is done inside the DbEnv->log_put call,
+ * so pass in the appropriate memory location to be filled
+ * in by the log_put code.
+ */
+ DB_SET_BEGIN_LSNP(txnid, &rlsnp);
txn_num = txnid->txnid;
lsnp = &txnid->last_lsn;
}
@@ -993,27 +781,23 @@ __qam_add_log(dbp, txnid, ret_lsnp, flags, lsn, pgno, indx, recno, data,
logrec.size += npad;
}
- if (!is_durable && txnid != NULL) {
+ if (is_durable || txnid == NULL) {
+ if ((ret =
+ __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
+ return (ret);
+ } else {
if ((ret = __os_malloc(dbenv,
logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
return (ret);
#ifdef DIAGNOSTIC
- goto do_malloc;
-#else
- logrec.data = &lr->data;
-#endif
- } else {
-#ifdef DIAGNOSTIC
-do_malloc:
-#endif
if ((ret =
__os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
-#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL)
- (void)__os_free(dbenv, lr);
-#endif
+ __os_free(dbenv, lr);
return (ret);
}
+#else
+ logrec.data = lr->data;
+#endif
}
if (npad > 0)
memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
@@ -1084,141 +868,47 @@ do_malloc:
DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
+ if (is_durable || txnid == NULL) {
+ if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
+ flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
+ txnid->last_lsn = *rlsnp;
+ if (rlsnp != ret_lsnp)
+ *ret_lsnp = *rlsnp;
+ }
+ } else {
#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL) {
- /*
- * We set the debug bit if we are going
- * to log non-durable transactions so
- * they will be ignored by recovery.
+ /*
+ * Set the debug bit if we are going to log non-durable
+ * transactions so they will be ignored by recovery.
*/
memcpy(lr->data, logrec.data, logrec.size);
rectype |= DB_debug_FLAG;
memcpy(logrec.data, &rectype, sizeof(rectype));
- }
-#endif
- if (!is_durable && txnid != NULL) {
+ ret = __log_put(dbenv,
+ rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
+#else
ret = 0;
- STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
-#ifdef DIAGNOSTIC
- goto do_put;
#endif
- } else{
-#ifdef DIAGNOSTIC
-do_put:
-#endif
- ret = __log_put(dbenv,
- ret_lsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
- if (ret == 0 && txnid != NULL)
- txnid->last_lsn = *ret_lsnp;
+ STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
+ LSN_NOT_LOGGED(*ret_lsnp);
}
- if (!is_durable)
- LSN_NOT_LOGGED(*ret_lsnp);
#ifdef LOG_DIAGNOSTIC
if (ret != 0)
(void)__qam_add_print(dbenv,
(DBT *)&logrec, ret_lsnp, NULL, NULL);
#endif
-#ifndef DIAGNOSTIC
+
+#ifdef DIAGNOSTIC
+ __os_free(dbenv, logrec.data);
+#else
if (is_durable || txnid == NULL)
-#endif
__os_free(dbenv, logrec.data);
-
+#endif
return (ret);
}
-#ifdef HAVE_REPLICATION
-/*
- * PUBLIC: int __qam_add_getpgnos __P((DB_ENV *, DBT *, DB_LSN *,
- * PUBLIC: db_recops, void *));
- */
-int
-__qam_add_getpgnos(dbenv, rec, lsnp, notused1, summary)
- DB_ENV *dbenv;
- DBT *rec;
- DB_LSN *lsnp;
- db_recops notused1;
- void *summary;
-{
- TXN_RECS *t;
- int ret;
- COMPQUIET(rec, NULL);
- COMPQUIET(notused1, DB_TXN_ABORT);
-
- t = (TXN_RECS *)summary;
-
- if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0)
- return (ret);
-
- t->array[t->npages].flags = LSN_PAGE_NOLOCK;
- t->array[t->npages].lsn = *lsnp;
- t->array[t->npages].fid = DB_LOGFILEID_INVALID;
- memset(&t->array[t->npages].pgdesc, 0,
- sizeof(t->array[t->npages].pgdesc));
-
- t->npages++;
-
- return (0);
-}
-#endif /* HAVE_REPLICATION */
-
-/*
- * PUBLIC: int __qam_add_print __P((DB_ENV *, DBT *, DB_LSN *,
- * PUBLIC: db_recops, void *));
- */
-int
-__qam_add_print(dbenv, dbtp, lsnp, notused2, notused3)
- DB_ENV *dbenv;
- DBT *dbtp;
- DB_LSN *lsnp;
- db_recops notused2;
- void *notused3;
-{
- __qam_add_args *argp;
- u_int32_t i;
- int ch;
- int ret;
-
- notused2 = DB_TXN_ABORT;
- notused3 = NULL;
-
- if ((ret = __qam_add_read(dbenv, dbtp->data, &argp)) != 0)
- return (ret);
- (void)printf(
- "[%lu][%lu]__qam_add%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
- (u_long)lsnp->file,
- (u_long)lsnp->offset,
- (argp->type & DB_debug_FLAG) ? "_debug" : "",
- (u_long)argp->type,
- (u_long)argp->txnid->txnid,
- (u_long)argp->prev_lsn.file,
- (u_long)argp->prev_lsn.offset);
- (void)printf("\tfileid: %ld\n", (long)argp->fileid);
- (void)printf("\tlsn: [%lu][%lu]\n",
- (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
- (void)printf("\tpgno: %lu\n", (u_long)argp->pgno);
- (void)printf("\tindx: %lu\n", (u_long)argp->indx);
- (void)printf("\trecno: %lu\n", (u_long)argp->recno);
- (void)printf("\tdata: ");
- for (i = 0; i < argp->data.size; i++) {
- ch = ((u_int8_t *)argp->data.data)[i];
- printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch);
- }
- (void)printf("\n");
- (void)printf("\tvflag: %lu\n", (u_long)argp->vflag);
- (void)printf("\tolddata: ");
- for (i = 0; i < argp->olddata.size; i++) {
- ch = ((u_int8_t *)argp->olddata.data)[i];
- printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch);
- }
- (void)printf("\n");
- (void)printf("\n");
- __os_free(dbenv, argp);
-
- return (0);
-}
-
/*
* PUBLIC: int __qam_add_read __P((DB_ENV *, void *, __qam_add_args **));
*/
@@ -1236,9 +926,9 @@ __qam_add_read(dbenv, recbuf, argpp)
if ((ret = __os_malloc(dbenv,
sizeof(__qam_add_args) + sizeof(DB_TXN), &argp)) != 0)
return (ret);
+ bp = recbuf;
argp->txnid = (DB_TXN *)&argp[1];
- bp = recbuf;
memcpy(&argp->type, bp, sizeof(argp->type));
bp += sizeof(argp->type);
@@ -1307,33 +997,42 @@ __qam_delext_log(dbp, txnid, ret_lsnp, flags, lsn, pgno, indx, recno, data)
DBT logrec;
DB_ENV *dbenv;
DB_TXNLOGREC *lr;
- DB_LSN *lsnp, null_lsn;
+ DB_LSN *lsnp, null_lsn, *rlsnp;
u_int32_t zero, uinttmp, rectype, txn_num;
u_int npad;
u_int8_t *bp;
int is_durable, ret;
dbenv = dbp->dbenv;
+ COMPQUIET(lr, NULL);
+
rectype = DB___qam_delext;
npad = 0;
+ rlsnp = ret_lsnp;
+
+ ret = 0;
- is_durable = 1;
if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
- F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) ||
F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
- if (F_ISSET(dbenv, DB_ENV_TXN_NOT_DURABLE) && txnid == NULL)
- return (0);
is_durable = 0;
- }
+ } else
+ is_durable = 1;
+
if (txnid == NULL) {
txn_num = 0;
- null_lsn.file = 0;
- null_lsn.offset = 0;
lsnp = &null_lsn;
+ null_lsn.file = null_lsn.offset = 0;
} else {
if (TAILQ_FIRST(&txnid->kids) != NULL &&
(ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
return (ret);
+ /*
+ * We need to assign begin_lsn while holding region mutex.
+ * That assignment is done inside the DbEnv->log_put call,
+ * so pass in the appropriate memory location to be filled
+ * in by the log_put code.
+ */
+ DB_SET_BEGIN_LSNP(txnid, &rlsnp);
txn_num = txnid->txnid;
lsnp = &txnid->last_lsn;
}
@@ -1351,27 +1050,23 @@ __qam_delext_log(dbp, txnid, ret_lsnp, flags, lsn, pgno, indx, recno, data)
logrec.size += npad;
}
- if (!is_durable && txnid != NULL) {
+ if (is_durable || txnid == NULL) {
+ if ((ret =
+ __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
+ return (ret);
+ } else {
if ((ret = __os_malloc(dbenv,
logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
return (ret);
#ifdef DIAGNOSTIC
- goto do_malloc;
-#else
- logrec.data = &lr->data;
-#endif
- } else {
-#ifdef DIAGNOSTIC
-do_malloc:
-#endif
if ((ret =
__os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
-#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL)
- (void)__os_free(dbenv, lr);
-#endif
+ __os_free(dbenv, lr);
return (ret);
}
+#else
+ logrec.data = lr->data;
+#endif
}
if (npad > 0)
memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
@@ -1427,134 +1122,47 @@ do_malloc:
DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
+ if (is_durable || txnid == NULL) {
+ if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
+ flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
+ txnid->last_lsn = *rlsnp;
+ if (rlsnp != ret_lsnp)
+ *ret_lsnp = *rlsnp;
+ }
+ } else {
#ifdef DIAGNOSTIC
- if (!is_durable && txnid != NULL) {
- /*
- * We set the debug bit if we are going
- * to log non-durable transactions so
- * they will be ignored by recovery.
+ /*
+ * Set the debug bit if we are going to log non-durable
+ * transactions so they will be ignored by recovery.
*/
memcpy(lr->data, logrec.data, logrec.size);
rectype |= DB_debug_FLAG;
memcpy(logrec.data, &rectype, sizeof(rectype));
- }
-#endif
- if (!is_durable && txnid != NULL) {
+ ret = __log_put(dbenv,
+ rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
+#else
ret = 0;
- STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
-#ifdef DIAGNOSTIC
- goto do_put;
#endif
- } else{
-#ifdef DIAGNOSTIC
-do_put:
-#endif
- ret = __log_put(dbenv,
- ret_lsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
- if (ret == 0 && txnid != NULL)
- txnid->last_lsn = *ret_lsnp;
+ STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
+ LSN_NOT_LOGGED(*ret_lsnp);
}
- if (!is_durable)
- LSN_NOT_LOGGED(*ret_lsnp);
#ifdef LOG_DIAGNOSTIC
if (ret != 0)
(void)__qam_delext_print(dbenv,
(DBT *)&logrec, ret_lsnp, NULL, NULL);
#endif
-#ifndef DIAGNOSTIC
+
+#ifdef DIAGNOSTIC
+ __os_free(dbenv, logrec.data);
+#else
if (is_durable || txnid == NULL)
-#endif
__os_free(dbenv, logrec.data);
-
+#endif
return (ret);
}
-#ifdef HAVE_REPLICATION
-/*
- * PUBLIC: int __qam_delext_getpgnos __P((DB_ENV *, DBT *, DB_LSN *,
- * PUBLIC: db_recops, void *));
- */
-int
-__qam_delext_getpgnos(dbenv, rec, lsnp, notused1, summary)
- DB_ENV *dbenv;
- DBT *rec;
- DB_LSN *lsnp;
- db_recops notused1;
- void *summary;
-{
- TXN_RECS *t;
- int ret;
- COMPQUIET(rec, NULL);
- COMPQUIET(notused1, DB_TXN_ABORT);
-
- t = (TXN_RECS *)summary;
-
- if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0)
- return (ret);
-
- t->array[t->npages].flags = LSN_PAGE_NOLOCK;
- t->array[t->npages].lsn = *lsnp;
- t->array[t->npages].fid = DB_LOGFILEID_INVALID;
- memset(&t->array[t->npages].pgdesc, 0,
- sizeof(t->array[t->npages].pgdesc));
-
- t->npages++;
-
- return (0);
-}
-#endif /* HAVE_REPLICATION */
-
-/*
- * PUBLIC: int __qam_delext_print __P((DB_ENV *, DBT *, DB_LSN *,
- * PUBLIC: db_recops, void *));
- */
-int
-__qam_delext_print(dbenv, dbtp, lsnp, notused2, notused3)
- DB_ENV *dbenv;
- DBT *dbtp;
- DB_LSN *lsnp;
- db_recops notused2;
- void *notused3;
-{
- __qam_delext_args *argp;
- u_int32_t i;
- int ch;
- int ret;
-
- notused2 = DB_TXN_ABORT;
- notused3 = NULL;
-
- if ((ret = __qam_delext_read(dbenv, dbtp->data, &argp)) != 0)
- return (ret);
- (void)printf(
- "[%lu][%lu]__qam_delext%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
- (u_long)lsnp->file,
- (u_long)lsnp->offset,
- (argp->type & DB_debug_FLAG) ? "_debug" : "",
- (u_long)argp->type,
- (u_long)argp->txnid->txnid,
- (u_long)argp->prev_lsn.file,
- (u_long)argp->prev_lsn.offset);
- (void)printf("\tfileid: %ld\n", (long)argp->fileid);
- (void)printf("\tlsn: [%lu][%lu]\n",
- (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
- (void)printf("\tpgno: %lu\n", (u_long)argp->pgno);
- (void)printf("\tindx: %lu\n", (u_long)argp->indx);
- (void)printf("\trecno: %lu\n", (u_long)argp->recno);
- (void)printf("\tdata: ");
- for (i = 0; i < argp->data.size; i++) {
- ch = ((u_int8_t *)argp->data.data)[i];
- printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch);
- }
- (void)printf("\n");
- (void)printf("\n");
- __os_free(dbenv, argp);
-
- return (0);
-}
-
/*
* PUBLIC: int __qam_delext_read __P((DB_ENV *, void *, __qam_delext_args **));
*/
@@ -1572,9 +1180,9 @@ __qam_delext_read(dbenv, recbuf, argpp)
if ((ret = __os_malloc(dbenv,
sizeof(__qam_delext_args) + sizeof(DB_TXN), &argp)) != 0)
return (ret);
+ bp = recbuf;
argp->txnid = (DB_TXN *)&argp[1];
- bp = recbuf;
memcpy(&argp->type, bp, sizeof(argp->type));
bp += sizeof(argp->type);
@@ -1614,68 +1222,6 @@ __qam_delext_read(dbenv, recbuf, argpp)
}
/*
- * PUBLIC: int __qam_init_print __P((DB_ENV *, int (***)(DB_ENV *,
- * PUBLIC: DBT *, DB_LSN *, db_recops, void *), size_t *));
- */
-int
-__qam_init_print(dbenv, dtabp, dtabsizep)
- DB_ENV *dbenv;
- int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
- size_t *dtabsizep;
-{
- int ret;
-
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_incfirst_print, DB___qam_incfirst)) != 0)
- return (ret);
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_mvptr_print, DB___qam_mvptr)) != 0)
- return (ret);
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_del_print, DB___qam_del)) != 0)
- return (ret);
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_add_print, DB___qam_add)) != 0)
- return (ret);
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_delext_print, DB___qam_delext)) != 0)
- return (ret);
- return (0);
-}
-
-#ifdef HAVE_REPLICATION
-/*
- * PUBLIC: int __qam_init_getpgnos __P((DB_ENV *, int (***)(DB_ENV *,
- * PUBLIC: DBT *, DB_LSN *, db_recops, void *), size_t *));
- */
-int
-__qam_init_getpgnos(dbenv, dtabp, dtabsizep)
- DB_ENV *dbenv;
- int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
- size_t *dtabsizep;
-{
- int ret;
-
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_incfirst_getpgnos, DB___qam_incfirst)) != 0)
- return (ret);
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_mvptr_getpgnos, DB___qam_mvptr)) != 0)
- return (ret);
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_del_getpgnos, DB___qam_del)) != 0)
- return (ret);
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_add_getpgnos, DB___qam_add)) != 0)
- return (ret);
- if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
- __qam_delext_getpgnos, DB___qam_delext)) != 0)
- return (ret);
- return (0);
-}
-#endif /* HAVE_REPLICATION */
-
-/*
* PUBLIC: int __qam_init_recover __P((DB_ENV *, int (***)(DB_ENV *,
* PUBLIC: DBT *, DB_LSN *, db_recops, void *), size_t *));
*/
diff --git a/db/qam/qam_autop.c b/db/qam/qam_autop.c
new file mode 100644
index 000000000..e9c122385
--- /dev/null
+++ b/db/qam/qam_autop.c
@@ -0,0 +1,274 @@
+/* Do not edit: automatically built by gen_rec.awk. */
+
+#include "db_config.h"
+
+#ifdef HAVE_QUEUE
+#ifndef NO_SYSTEM_INCLUDES
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <string.h>
+#endif
+
+#include "db_int.h"
+#include "dbinc/crypto.h"
+#include "dbinc/db_page.h"
+#include "dbinc/db_dispatch.h"
+#include "dbinc/db_am.h"
+#include "dbinc/log.h"
+#include "dbinc/qam.h"
+#include "dbinc/txn.h"
+
+/*
+ * PUBLIC: int __qam_incfirst_print __P((DB_ENV *, DBT *, DB_LSN *,
+ * PUBLIC: db_recops, void *));
+ */
+int
+__qam_incfirst_print(dbenv, dbtp, lsnp, notused2, notused3)
+ DB_ENV *dbenv;
+ DBT *dbtp;
+ DB_LSN *lsnp;
+ db_recops notused2;
+ void *notused3;
+{
+ __qam_incfirst_args *argp;
+ int ret;
+
+ notused2 = DB_TXN_ABORT;
+ notused3 = NULL;
+
+ if ((ret = __qam_incfirst_read(dbenv, dbtp->data, &argp)) != 0)
+ return (ret);
+ (void)printf(
+ "[%lu][%lu]__qam_incfirst%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
+ (u_long)lsnp->file,
+ (u_long)lsnp->offset,
+ (argp->type & DB_debug_FLAG) ? "_debug" : "",
+ (u_long)argp->type,
+ (u_long)argp->txnid->txnid,
+ (u_long)argp->prev_lsn.file,
+ (u_long)argp->prev_lsn.offset);
+ (void)printf("\tfileid: %ld\n", (long)argp->fileid);
+ (void)printf("\trecno: %lu\n", (u_long)argp->recno);
+ (void)printf("\tmeta_pgno: %lu\n", (u_long)argp->meta_pgno);
+ (void)printf("\n");
+ __os_free(dbenv, argp);
+ return (0);
+}
+
+/*
+ * PUBLIC: int __qam_mvptr_print __P((DB_ENV *, DBT *, DB_LSN *,
+ * PUBLIC: db_recops, void *));
+ */
+int
+__qam_mvptr_print(dbenv, dbtp, lsnp, notused2, notused3)
+ DB_ENV *dbenv;
+ DBT *dbtp;
+ DB_LSN *lsnp;
+ db_recops notused2;
+ void *notused3;
+{
+ __qam_mvptr_args *argp;
+ int ret;
+
+ notused2 = DB_TXN_ABORT;
+ notused3 = NULL;
+
+ if ((ret = __qam_mvptr_read(dbenv, dbtp->data, &argp)) != 0)
+ return (ret);
+ (void)printf(
+ "[%lu][%lu]__qam_mvptr%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
+ (u_long)lsnp->file,
+ (u_long)lsnp->offset,
+ (argp->type & DB_debug_FLAG) ? "_debug" : "",
+ (u_long)argp->type,
+ (u_long)argp->txnid->txnid,
+ (u_long)argp->prev_lsn.file,
+ (u_long)argp->prev_lsn.offset);
+ (void)printf("\topcode: %lu\n", (u_long)argp->opcode);
+ (void)printf("\tfileid: %ld\n", (long)argp->fileid);
+ (void)printf("\told_first: %lu\n", (u_long)argp->old_first);
+ (void)printf("\tnew_first: %lu\n", (u_long)argp->new_first);
+ (void)printf("\told_cur: %lu\n", (u_long)argp->old_cur);
+ (void)printf("\tnew_cur: %lu\n", (u_long)argp->new_cur);
+ (void)printf("\tmetalsn: [%lu][%lu]\n",
+ (u_long)argp->metalsn.file, (u_long)argp->metalsn.offset);
+ (void)printf("\tmeta_pgno: %lu\n", (u_long)argp->meta_pgno);
+ (void)printf("\n");
+ __os_free(dbenv, argp);
+ return (0);
+}
+
+/*
+ * PUBLIC: int __qam_del_print __P((DB_ENV *, DBT *, DB_LSN *,
+ * PUBLIC: db_recops, void *));
+ */
+int
+__qam_del_print(dbenv, dbtp, lsnp, notused2, notused3)
+ DB_ENV *dbenv;
+ DBT *dbtp;
+ DB_LSN *lsnp;
+ db_recops notused2;
+ void *notused3;
+{
+ __qam_del_args *argp;
+ int ret;
+
+ notused2 = DB_TXN_ABORT;
+ notused3 = NULL;
+
+ if ((ret = __qam_del_read(dbenv, dbtp->data, &argp)) != 0)
+ return (ret);
+ (void)printf(
+ "[%lu][%lu]__qam_del%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
+ (u_long)lsnp->file,
+ (u_long)lsnp->offset,
+ (argp->type & DB_debug_FLAG) ? "_debug" : "",
+ (u_long)argp->type,
+ (u_long)argp->txnid->txnid,
+ (u_long)argp->prev_lsn.file,
+ (u_long)argp->prev_lsn.offset);
+ (void)printf("\tfileid: %ld\n", (long)argp->fileid);
+ (void)printf("\tlsn: [%lu][%lu]\n",
+ (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
+ (void)printf("\tpgno: %lu\n", (u_long)argp->pgno);
+ (void)printf("\tindx: %lu\n", (u_long)argp->indx);
+ (void)printf("\trecno: %lu\n", (u_long)argp->recno);
+ (void)printf("\n");
+ __os_free(dbenv, argp);
+ return (0);
+}
+
+/*
+ * PUBLIC: int __qam_add_print __P((DB_ENV *, DBT *, DB_LSN *,
+ * PUBLIC: db_recops, void *));
+ */
+int
+__qam_add_print(dbenv, dbtp, lsnp, notused2, notused3)
+ DB_ENV *dbenv;
+ DBT *dbtp;
+ DB_LSN *lsnp;
+ db_recops notused2;
+ void *notused3;
+{
+ __qam_add_args *argp;
+ u_int32_t i;
+ int ch;
+ int ret;
+
+ notused2 = DB_TXN_ABORT;
+ notused3 = NULL;
+
+ if ((ret = __qam_add_read(dbenv, dbtp->data, &argp)) != 0)
+ return (ret);
+ (void)printf(
+ "[%lu][%lu]__qam_add%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
+ (u_long)lsnp->file,
+ (u_long)lsnp->offset,
+ (argp->type & DB_debug_FLAG) ? "_debug" : "",
+ (u_long)argp->type,
+ (u_long)argp->txnid->txnid,
+ (u_long)argp->prev_lsn.file,
+ (u_long)argp->prev_lsn.offset);
+ (void)printf("\tfileid: %ld\n", (long)argp->fileid);
+ (void)printf("\tlsn: [%lu][%lu]\n",
+ (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
+ (void)printf("\tpgno: %lu\n", (u_long)argp->pgno);
+ (void)printf("\tindx: %lu\n", (u_long)argp->indx);
+ (void)printf("\trecno: %lu\n", (u_long)argp->recno);
+ (void)printf("\tdata: ");
+ for (i = 0; i < argp->data.size; i++) {
+ ch = ((u_int8_t *)argp->data.data)[i];
+ printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch);
+ }
+ (void)printf("\n");
+ (void)printf("\tvflag: %lu\n", (u_long)argp->vflag);
+ (void)printf("\tolddata: ");
+ for (i = 0; i < argp->olddata.size; i++) {
+ ch = ((u_int8_t *)argp->olddata.data)[i];
+ printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch);
+ }
+ (void)printf("\n");
+ (void)printf("\n");
+ __os_free(dbenv, argp);
+ return (0);
+}
+
+/*
+ * PUBLIC: int __qam_delext_print __P((DB_ENV *, DBT *, DB_LSN *,
+ * PUBLIC: db_recops, void *));
+ */
+int
+__qam_delext_print(dbenv, dbtp, lsnp, notused2, notused3)
+ DB_ENV *dbenv;
+ DBT *dbtp;
+ DB_LSN *lsnp;
+ db_recops notused2;
+ void *notused3;
+{
+ __qam_delext_args *argp;
+ u_int32_t i;
+ int ch;
+ int ret;
+
+ notused2 = DB_TXN_ABORT;
+ notused3 = NULL;
+
+ if ((ret = __qam_delext_read(dbenv, dbtp->data, &argp)) != 0)
+ return (ret);
+ (void)printf(
+ "[%lu][%lu]__qam_delext%s: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
+ (u_long)lsnp->file,
+ (u_long)lsnp->offset,
+ (argp->type & DB_debug_FLAG) ? "_debug" : "",
+ (u_long)argp->type,
+ (u_long)argp->txnid->txnid,
+ (u_long)argp->prev_lsn.file,
+ (u_long)argp->prev_lsn.offset);
+ (void)printf("\tfileid: %ld\n", (long)argp->fileid);
+ (void)printf("\tlsn: [%lu][%lu]\n",
+ (u_long)argp->lsn.file, (u_long)argp->lsn.offset);
+ (void)printf("\tpgno: %lu\n", (u_long)argp->pgno);
+ (void)printf("\tindx: %lu\n", (u_long)argp->indx);
+ (void)printf("\trecno: %lu\n", (u_long)argp->recno);
+ (void)printf("\tdata: ");
+ for (i = 0; i < argp->data.size; i++) {
+ ch = ((u_int8_t *)argp->data.data)[i];
+ printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch);
+ }
+ (void)printf("\n");
+ (void)printf("\n");
+ __os_free(dbenv, argp);
+ return (0);
+}
+
+/*
+ * PUBLIC: int __qam_init_print __P((DB_ENV *, int (***)(DB_ENV *,
+ * PUBLIC: DBT *, DB_LSN *, db_recops, void *), size_t *));
+ */
+int
+__qam_init_print(dbenv, dtabp, dtabsizep)
+ DB_ENV *dbenv;
+ int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
+ size_t *dtabsizep;
+{
+ int ret;
+
+ if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
+ __qam_incfirst_print, DB___qam_incfirst)) != 0)
+ return (ret);
+ if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
+ __qam_mvptr_print, DB___qam_mvptr)) != 0)
+ return (ret);
+ if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
+ __qam_del_print, DB___qam_del)) != 0)
+ return (ret);
+ if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
+ __qam_add_print, DB___qam_add)) != 0)
+ return (ret);
+ if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
+ __qam_delext_print, DB___qam_delext)) != 0)
+ return (ret);
+ return (0);
+}
+#endif /* HAVE_QUEUE */
diff --git a/db/qam/qam_conv.c b/db/qam/qam_conv.c
index ee5f23b50..c2b7d53a4 100644
--- a/db/qam/qam_conv.c
+++ b/db/qam/qam_conv.c
@@ -1,16 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999-2003
+ * Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam_conv.c,v 11.17 2004/01/28 03:36:19 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam_conv.c,v 11.16 2003/01/08 05:37:19 bostic Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif
diff --git a/db/qam/qam_files.c b/db/qam/qam_files.c
index b6fd42dd0..fe0b01da5 100644
--- a/db/qam/qam_files.c
+++ b/db/qam/qam_files.c
@@ -1,16 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999-2003
+ * Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam_files.c,v 1.86 2004/10/12 22:53:44 ubell Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam_files.c,v 1.72 2003/10/03 21:21:54 ubell Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <stdlib.h>
@@ -28,8 +26,8 @@ static const char revid[] = "$Id: qam_files.c,v 1.72 2003/10/03 21:21:54 ubell E
#include "dbinc/mp.h"
#include "dbinc/qam.h"
-#define QAM_EXNAME(Q, I, B, L) \
- snprintf((B), (L), \
+#define QAM_EXNAME(Q, I, B, L) \
+ snprintf((B), (L), \
QUEUE_EXTENT, (Q)->dir, PATH_SEPARATOR[0], (Q)->name, (I))
/*
@@ -53,9 +51,9 @@ __qam_fprobe(dbp, pgno, addrp, mode, flags)
MPFARRAY *array;
QUEUE *qp;
u_int8_t fid[DB_FILE_ID_LEN];
- u_int32_t extid, maxext, openflags;
+ u_int32_t extid, maxext, numext, offset, oldext, openflags;
char buf[MAXPATHLEN];
- int ftype, numext, offset, oldext, ret;
+ int ftype, less, ret, t_ret;
dbenv = dbp->dbenv;
qp = (QUEUE *)dbp->q_internal;
@@ -82,19 +80,32 @@ __qam_fprobe(dbp, pgno, addrp, mode, flags)
array = &qp->array1;
if (array->n_extent == 0) {
/* Start with 4 extents */
- oldext = 0;
array->n_extent = 4;
array->low_extent = extid;
- offset = 0;
- numext = 0;
+ numext = offset = oldext = 0;
+ less = 0;
goto alloc;
}
- offset = extid - qp->array1.low_extent;
+ if (extid < array->low_extent) {
+ less = 1;
+ offset = array->low_extent - extid;
+ } else {
+ less = 0;
+ offset = extid - array->low_extent;
+ }
if (qp->array2.n_extent != 0 &&
- abs(offset) > abs(extid - qp->array2.low_extent)) {
+ (extid >= qp->array2.low_extent ?
+ offset > extid - qp->array2.low_extent :
+ offset > qp->array2.low_extent - extid)) {
array = &qp->array2;
- offset = extid - array->low_extent;
+ if (extid < array->low_extent) {
+ less = 1;
+ offset = array->low_extent - extid;
+ } else {
+ less = 0;
+ offset = extid - array->low_extent;
+ }
}
/*
@@ -102,27 +113,26 @@ __qam_fprobe(dbp, pgno, addrp, mode, flags)
* extents in the array. This is true by default if there are
* no extents here yet.
*/
- if (offset < 0 || (unsigned) offset >= array->n_extent) {
+ if (less == 1 || offset >= array->n_extent) {
oldext = array->n_extent;
- numext = array->hi_extent - array->low_extent + 1;
- if (offset < 0 &&
- (unsigned) -offset + numext <= array->n_extent) {
+ numext = (array->hi_extent - array->low_extent) + 1;
+ if (less == 1 && offset + numext <= array->n_extent) {
/*
* If we can fit this one into the existing array by
* shifting the existing entries then we do not have
* to allocate.
*/
- memmove(&array->mpfarray[-offset],
+ memmove(&array->mpfarray[offset],
array->mpfarray, numext
* sizeof(array->mpfarray[0]));
- memset(array->mpfarray, 0, -offset
+ memset(array->mpfarray, 0, offset
* sizeof(array->mpfarray[0]));
offset = 0;
- } else if ((u_int32_t)offset == array->n_extent &&
+ } else if (less == 0 && offset == array->n_extent &&
mode != QAM_PROBE_MPF && array->mpfarray[0].pinref == 0) {
/*
* If this is at the end of the array and the file at
- * the begining has a zero pin count we can close
+ * the beginning has a zero pin count we can close
* the bottom extent and put this one at the end.
* TODO: If this process is "slow" then it might be
* appending but miss one or more extents.
@@ -146,9 +156,9 @@ __qam_fprobe(dbp, pgno, addrp, mode, flags)
* If it has then allocate the second array.
* Otherwise just expand the one we are using.
*/
- maxext = (u_int32_t) UINT32_T_MAX
+ maxext = (u_int32_t) UINT32_MAX
/ (qp->page_ext * qp->rec_page);
- if ((u_int32_t) abs(offset) >= maxext/2) {
+ if (offset >= maxext/2) {
array = &qp->array2;
DB_ASSERT(array->n_extent == 0);
oldext = 0;
@@ -161,21 +171,19 @@ __qam_fprobe(dbp, pgno, addrp, mode, flags)
* Increase the size to at least include
* the new one and double it.
*/
- array->n_extent += abs(offset);
+ array->n_extent += offset;
array->n_extent <<= 2;
}
- alloc:
- if ((ret = __os_realloc(dbenv,
+alloc: if ((ret = __os_realloc(dbenv,
array->n_extent * sizeof(struct __qmpf),
&array->mpfarray)) != 0)
goto err;
- if (offset < 0) {
+ if (less == 1) {
/*
* Move the array up and put the new one
* in the first slot.
*/
- offset = -offset;
memmove(&array->mpfarray[offset],
array->mpfarray,
numext * sizeof(array->mpfarray[0]));
@@ -256,14 +264,27 @@ err:
}
pgno--;
pgno %= qp->page_ext;
- if (mode == QAM_PROBE_GET)
- return (__memp_fget(mpf, &pgno, flags, addrp));
- ret = __memp_fput(mpf, addrp, flags);
+ if (mode == QAM_PROBE_GET) {
+ if ((ret = __memp_fget(mpf, &pgno, flags, addrp)) == 0)
+ return (ret);
+ } else
+ ret = __memp_fput(mpf, addrp, flags);
+
MUTEX_THREAD_LOCK(dbenv, dbp->mutexp);
/* Recalculate because we dropped the lock. */
offset = extid - array->low_extent;
DB_ASSERT(array->mpfarray[offset].pinref > 0);
- array->mpfarray[offset].pinref--;
+ if (--array->mpfarray[offset].pinref == 0 &&
+ (mode == QAM_PROBE_GET || ret == 0)) {
+ /* Check to see if this file will be unlinked. */
+ (void)__memp_get_flags(mpf, &flags);
+ if (LF_ISSET(DB_MPOOL_UNLINK)) {
+ array->mpfarray[offset].mpf = NULL;
+ if ((t_ret =
+ __memp_fclose(mpf, 0)) != 0 && ret == 0)
+ ret = t_ret;
+ }
+ }
MUTEX_THREAD_UNLOCK(dbenv, dbp->mutexp);
}
return (ret);
@@ -286,8 +307,8 @@ __qam_fclose(dbp, pgnoaddr)
DB_MPOOLFILE *mpf;
MPFARRAY *array;
QUEUE *qp;
- u_int32_t extid;
- int offset, ret;
+ u_int32_t extid, offset;
+ int ret;
ret = 0;
dbenv = dbp->dbenv;
@@ -301,7 +322,7 @@ __qam_fclose(dbp, pgnoaddr)
array = &qp->array2;
offset = extid - array->low_extent;
- DB_ASSERT(offset >= 0 && (unsigned) offset < array->n_extent);
+ DB_ASSERT(extid >= array->low_extent && offset < array->n_extent);
/* If other threads are still using this file, leave it. */
if (array->mpfarray[offset].pinref != 0)
@@ -334,11 +355,11 @@ __qam_fremove(dbp, pgnoaddr)
DB_MPOOLFILE *mpf;
MPFARRAY *array;
QUEUE *qp;
- u_int32_t extid;
-#if CONFIG_TEST
+ u_int32_t extid, offset;
+#ifdef CONFIG_TEST
char buf[MAXPATHLEN], *real_name;
#endif
- int offset, ret;
+ int ret;
qp = (QUEUE *)dbp->q_internal;
dbenv = dbp->dbenv;
@@ -352,9 +373,9 @@ __qam_fremove(dbp, pgnoaddr)
array = &qp->array2;
offset = extid - array->low_extent;
- DB_ASSERT(offset >= 0 && (unsigned) offset < array->n_extent);
+ DB_ASSERT(extid >= array->low_extent && offset < array->n_extent);
-#if CONFIG_TEST
+#ifdef CONFIG_TEST
real_name = NULL;
/* Find the real name of the file. */
QAM_EXNAME(qp, extid, buf, sizeof(buf));
@@ -370,8 +391,11 @@ __qam_fremove(dbp, pgnoaddr)
goto err;
mpf = array->mpfarray[offset].mpf;
- array->mpfarray[offset].mpf = NULL;
(void)__memp_set_flags(mpf, DB_MPOOL_UNLINK, 1);
+ /* Someone could be real slow, let them close it down. */
+ if (array->mpfarray[offset].pinref != 0)
+ goto err;
+ array->mpfarray[offset].mpf = NULL;
if ((ret = __memp_fclose(mpf, 0)) != 0)
goto err;
@@ -394,7 +418,7 @@ __qam_fremove(dbp, pgnoaddr)
err:
MUTEX_THREAD_UNLOCK(dbenv, dbp->mutexp);
-#if CONFIG_TEST
+#ifdef CONFIG_TEST
if (real_name != NULL)
__os_free(dbenv, real_name);
#endif
@@ -483,14 +507,14 @@ __qam_gen_filelist(dbp, filelistp)
* roundoff at first (e.g., current record in extent);
* roundoff at current (e.g., first record in extent);
* NULL termination; and
- * UINT32_T_MAX wraparound (the last extent can be small).
+ * UINT32_MAX wraparound (the last extent can be small).
*/
rec_extent = qp->rec_page * qp->page_ext;
if (current >= first)
extent_cnt = (current - first) / rec_extent + 3;
else
extent_cnt =
- (current + (UINT32_T_MAX - first)) / rec_extent + 4;
+ (current + (UINT32_MAX - first)) / rec_extent + 4;
if ((ret = __os_calloc(dbenv,
extent_cnt, sizeof(QUEUE_FILELIST), filelistp)) != 0)
return (ret);
@@ -500,7 +524,7 @@ again:
if (current >= first)
stop = current;
else
- stop = UINT32_T_MAX;
+ stop = UINT32_MAX;
/*
* Make sure that first is at the same offset in the extent as stop.
@@ -545,8 +569,9 @@ __qam_extent_names(dbenv, name, namelistp)
DB *dbp;
QUEUE *qp;
QUEUE_FILELIST *filelist, *fp;
+ size_t len;
+ int cnt, ret, t_ret;
char buf[MAXPATHLEN], **cp, *freep;
- int cnt, len, ret;
*namelistp = NULL;
filelist = NULL;
@@ -570,19 +595,18 @@ __qam_extent_names(dbenv, name, namelistp)
cnt++;
/* QUEUE_EXTENT contains extra chars, but add 6 anyway for the int. */
- len = (u_int32_t)(cnt * (sizeof(**namelistp)
- + strlen(QUEUE_EXTENT) + strlen(qp->dir) + strlen(qp->name) + 6));
+ len = (size_t)cnt * (sizeof(**namelistp) +
+ strlen(QUEUE_EXTENT) + strlen(qp->dir) + strlen(qp->name) + 6);
- if ((ret =
- __os_malloc(dbp->dbenv, len, namelistp)) != 0)
+ if ((ret = __os_malloc(dbp->dbenv, len, namelistp)) != 0)
goto done;
cp = *namelistp;
freep = (char *)(cp + cnt + 1);
for (fp = filelist; fp->mpf != NULL; fp++) {
QAM_EXNAME(qp, fp->id, buf, sizeof(buf));
- len = (u_int32_t)strlen(buf);
+ len = strlen(buf);
*cp++ = freep;
- strcpy(freep, buf);
+ (void)strcpy(freep, buf);
freep += len + 1;
}
*cp = NULL;
@@ -590,7 +614,8 @@ __qam_extent_names(dbenv, name, namelistp)
done:
if (filelist != NULL)
__os_free(dbp->dbenv, filelist);
- (void)__db_close(dbp, NULL, DB_NOSYNC);
+ if ((t_ret = __db_close(dbp, NULL, DB_NOSYNC)) != 0 && ret == 0)
+ ret = t_ret;
return (ret);
}
@@ -632,7 +657,7 @@ __qam_exid(dbp, fidp, exnum)
/*
* __qam_nameop --
- * Remove or rename extent files associated with a particular file.
+ * Remove or rename extent files associated with a particular file.
* This is to remove or rename (both in mpool and the file system) any
* extent files associated with the given dbp.
* This is either called from the QUEUE remove or rename methods or
@@ -648,17 +673,19 @@ int __qam_nameop(dbp, txn, newname, op)
{
DB_ENV *dbenv;
QUEUE *qp;
+ size_t exlen, fulllen, len;
+ u_int8_t fid[DB_FILE_ID_LEN];
+ u_int32_t exid;
+ int cnt, i, ret, t_ret;
char buf[MAXPATHLEN], nbuf[MAXPATHLEN], sepsave;
char *endname, *endpath, *exname, *fullname, **names;
char *ndir, *namep, *new, *cp;
- int cnt, exlen, fulllen, i, len, ret, t_ret;
- u_int8_t fid[DB_FILE_ID_LEN];
- u_int32_t exid;
ret = t_ret = 0;
dbenv = dbp->dbenv;
qp = (QUEUE *)dbp->q_internal;
namep = exname = fullname = NULL;
+ names = NULL;
/* If this isn't a queue with extents, we're done. */
if (qp->page_ext == 0)
@@ -753,8 +780,7 @@ int __qam_nameop(dbp, txn, newname, op)
* We have a queue extent file. We need to generate its
* name and its fileid.
*/
-
- exid = atol(names[i] + len);
+ exid = (u_int32_t)strtoul(names[i] + len, NULL, 10);
__qam_exid(dbp, fid, exid);
switch (op) {
@@ -793,5 +819,7 @@ err: if (fullname != NULL)
__os_free(dbenv, exname);
if (namep != NULL)
__os_free(dbenv, namep);
+ if (names != NULL)
+ __os_free(dbenv, names);
return (ret);
}
diff --git a/db/qam/qam_method.c b/db/qam/qam_method.c
index b0270f767..737ced0d2 100644
--- a/db/qam/qam_method.c
+++ b/db/qam/qam_method.c
@@ -1,40 +1,31 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999-2003
+ * Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam_method.c,v 11.83 2004/10/05 16:59:26 sue Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam_method.c,v 11.64 2003/10/01 20:03:43 ubell Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
-
-#include <string.h>
#endif
#include "db_int.h"
#include "dbinc/db_page.h"
#include "dbinc/db_shash.h"
#include "dbinc/db_am.h"
-#include "dbinc/fop.h"
#include "dbinc/lock.h"
#include "dbinc/mp.h"
#include "dbinc/qam.h"
#include "dbinc/txn.h"
-static int __qam_get_extentsize __P((DB *, u_int32_t *));
+static int __qam_rr __P((DB *, DB_TXN *,
+ const char *, const char *, const char *, qam_name_op));
static int __qam_set_extentsize __P((DB *, u_int32_t));
-struct __qam_cookie {
- DB_LSN lsn;
- QUEUE_FILELIST *filelist;
-};
-
/*
* __qam_db_create --
* Queue specific initialization of the DB structure.
@@ -116,7 +107,13 @@ again:
return (ret);
}
-static int
+/*
+ * __qam_get_extentsize --
+ * The DB->q_get_extentsize method.
+ *
+ * PUBLIC: int __qam_get_extentsize __P((DB *, u_int32_t *));
+ */
+int
__qam_get_extentsize(dbp, q_extentsizep)
DB *dbp;
u_int32_t *q_extentsizep;
@@ -143,22 +140,24 @@ __qam_set_extentsize(dbp, extentsize)
}
/*
- * __db_prqueue --
- * Print out a queue
+ * __queue_pageinfo -
+ * Given a dbp, get first/last page information about a queue.
*
- * PUBLIC: int __db_prqueue __P((DB *, FILE *, u_int32_t));
+ * PUBLIC: int __queue_pageinfo __P((DB *, db_pgno_t *, db_pgno_t *,
+ * PUBLIC: int *, int, u_int32_t));
*/
int
-__db_prqueue(dbp, fp, flags)
+__queue_pageinfo(dbp, firstp, lastp, emptyp, prpage, flags)
DB *dbp;
- FILE *fp;
+ db_pgno_t *firstp, *lastp;
+ int *emptyp;
+ int prpage;
u_int32_t flags;
{
DB_MPOOLFILE *mpf;
- PAGE *h;
QMETA *meta;
- db_pgno_t first, i, last, pg_ext, stop;
- int ret, t_ret;
+ db_pgno_t first, i, last;
+ int empty, ret, t_ret;
mpf = dbp->mpf;
@@ -168,18 +167,55 @@ __db_prqueue(dbp, fp, flags)
return (ret);
first = QAM_RECNO_PAGE(dbp, meta->first_recno);
- last = QAM_RECNO_PAGE(dbp, meta->cur_recno);
+ last = QAM_RECNO_PAGE(
+ dbp, meta->cur_recno == 1 ? 1 : meta->cur_recno - 1);
+
+ empty = meta->cur_recno == meta->first_recno;
+ if (firstp != NULL)
+ *firstp = first;
+ if (lastp != NULL)
+ *lastp = last;
+ if (emptyp != NULL)
+ *emptyp = empty;
+#ifdef HAVE_STATISTICS
+ if (prpage)
+ ret = __db_prpage(dbp, (PAGE *)meta, flags);
+#else
+ COMPQUIET(prpage, 0);
+ COMPQUIET(flags, 0);
+#endif
- ret = __db_prpage(dbp, (PAGE *)meta, fp, flags);
if ((t_ret = __memp_fput(mpf, meta, 0)) != 0 && ret == 0)
ret = t_ret;
- if (ret != 0)
+ return (ret);
+}
+
+#ifdef HAVE_STATISTICS
+/*
+ * __db_prqueue --
+ * Print out a queue
+ *
+ * PUBLIC: int __db_prqueue __P((DB *, u_int32_t));
+ */
+int
+__db_prqueue(dbp, flags)
+ DB *dbp;
+ u_int32_t flags;
+{
+ PAGE *h;
+ db_pgno_t first, i, last, pg_ext, stop;
+ int empty, ret;
+
+ if ((ret = __queue_pageinfo(dbp, &first, &last, &empty, 1, flags)) != 0)
+ return (ret);
+
+ if (empty || ret != 0)
return (ret);
i = first;
if (first > last)
- stop = QAM_RECNO_PAGE(dbp, UINT32_T_MAX);
+ stop = QAM_RECNO_PAGE(dbp, UINT32_MAX);
else
stop = last;
@@ -194,12 +230,12 @@ begin:
return (ret);
}
if (ret == ENOENT || ret == DB_PAGE_NOTFOUND) {
- i += pg_ext - ((i - 1) % pg_ext) - 1;
+ i += (pg_ext - ((i - 1) % pg_ext)) - 1;
continue;
}
return (ret);
}
- (void)__db_prpage(dbp, h, fp, flags);
+ (void)__db_prpage(dbp, h, flags);
if ((ret = __qam_fput(dbp, i, h, 0)) != 0)
return (ret);
}
@@ -212,46 +248,68 @@ begin:
}
return (0);
}
+#endif
/*
- * __qam_remove
+ * __qam_remove --
* Remove method for a Queue.
*
- * PUBLIC: int __qam_remove __P((DB *,
- * PUBLIC: DB_TXN *, const char *, const char *, DB_LSN *));
+ * PUBLIC: int __qam_remove __P((DB *, DB_TXN *, const char *, const char *));
*/
int
-__qam_remove(dbp, txn, name, subdb, lsnp)
+__qam_remove(dbp, txn, name, subdb)
DB *dbp;
DB_TXN *txn;
const char *name, *subdb;
- DB_LSN *lsnp;
+{
+ return (__qam_rr(dbp, txn, name, subdb, NULL, QAM_NAME_REMOVE));
+}
+
+/*
+ * __qam_rename --
+ * Rename method for a Queue.
+ *
+ * PUBLIC: int __qam_rename __P((DB *,
+ * PUBLIC: DB_TXN *, const char *, const char *, const char *));
+ */
+int
+__qam_rename(dbp, txn, name, subdb, newname)
+ DB *dbp;
+ DB_TXN *txn;
+ const char *name, *subdb, *newname;
+{
+ return (__qam_rr(dbp, txn, name, subdb, newname, QAM_NAME_RENAME));
+}
+
+/*
+ * __qam_rr --
+ * Remove/Rename method for a Queue.
+ */
+static int
+__qam_rr(dbp, txn, name, subdb, newname, op)
+ DB *dbp;
+ DB_TXN *txn;
+ const char *name, *subdb, *newname;
+ qam_name_op op;
{
DB_ENV *dbenv;
DB *tmpdbp;
QUEUE *qp;
- int ret, needclose, t_ret;
-
- COMPQUIET(lsnp, NULL);
+ int ret, t_ret;
dbenv = dbp->dbenv;
ret = 0;
- needclose = 0;
PANIC_CHECK(dbenv);
- /*
- * Subdatabases.
- */
if (subdb != NULL) {
__db_err(dbenv,
"Queue does not support multiple databases per file");
- ret = EINVAL;
- goto err;
+ return (EINVAL);
}
/*
- * Since regular remove no longer opens the database, we may have
+ * Since regular rename no longer opens the database, we may have
* to do it here.
*/
if (F_ISSET(dbp, DB_AM_OPEN_CALLED))
@@ -259,40 +317,29 @@ __qam_remove(dbp, txn, name, subdb, lsnp)
else {
if ((ret = db_create(&tmpdbp, dbenv, 0)) != 0)
return (ret);
+
/*
* We need to make sure we don't self-deadlock, so give
* this dbp the same locker as the incoming one.
*/
tmpdbp->lid = dbp->lid;
-
- /*
- * If this is a transactional dbp and the open fails, then
- * the transactional abort will close the dbp. If it's not
- * a transactional open, then we always have to close it
- * even if the open fails. Once the open has succeeded,
- * then we will always want to close it.
- */
- if (txn == NULL)
- needclose = 1;
- if ((ret = __db_open(tmpdbp,
- txn, name, NULL, DB_QUEUE, 0, 0, PGNO_BASE_MD)) != 0)
+ if ((ret = __db_open(tmpdbp, txn,
+ name, NULL, DB_QUEUE, DB_RDONLY, 0, PGNO_BASE_MD)) != 0)
goto err;
- needclose = 1;
}
qp = (QUEUE *)tmpdbp->q_internal;
+ if (qp->page_ext != 0)
+ ret = __qam_nameop(tmpdbp, txn, newname, op);
- if (qp->page_ext != 0)
- ret = __qam_nameop(tmpdbp, txn, NULL, QAM_NAME_REMOVE);
-
-err: if (needclose) {
- /*
- * Since we copied the lid from the dbp, we'd better not
+ if (!F_ISSET(dbp, DB_AM_OPEN_CALLED)) {
+err: /*
+ * Since we copied the locker ID from the dbp, we'd better not
* free it here.
*/
tmpdbp->lid = DB_LOCK_INVALIDID;
- /* We need to remove the lockevent we associated with this. */
+ /* We need to remove the lock event we associated with this. */
if (txn != NULL)
__txn_remlock(dbenv,
txn, &tmpdbp->handle_lock, DB_LOCK_INVALIDID);
@@ -301,73 +348,40 @@ err: if (needclose) {
__db_close(tmpdbp, txn, DB_NOSYNC)) != 0 && ret == 0)
ret = t_ret;
}
-
return (ret);
}
/*
- * __qam_rename
- * Rename method for Queue.
+ * __qam_map_flags --
+ * Map queue-specific flags from public to the internal values.
*
- * PUBLIC: int __qam_rename __P((DB *, DB_TXN *,
- * PUBLIC: const char *, const char *, const char *));
+ * PUBLIC: void __qam_map_flags __P((DB *, u_int32_t *, u_int32_t *));
*/
-int
-__qam_rename(dbp, txn, filename, subdb, newname)
+void
+__qam_map_flags(dbp, inflagsp, outflagsp)
DB *dbp;
- DB_TXN *txn;
- const char *filename, *subdb, *newname;
+ u_int32_t *inflagsp, *outflagsp;
{
- DB_ENV *dbenv;
- DB *tmpdbp;
- QUEUE *qp;
- int ret, needclose, t_ret;
+ COMPQUIET(dbp, NULL);
- dbenv = dbp->dbenv;
- ret = 0;
- needclose = 0;
-
- if (subdb != NULL) {
- __db_err(dbenv,
- "Queue does not support multiple databases per file");
- ret = EINVAL;
- goto err;
+ if (FLD_ISSET(*inflagsp, DB_INORDER)) {
+ FLD_SET(*outflagsp, DB_AM_INORDER);
+ FLD_CLR(*inflagsp, DB_INORDER);
}
+}
- /*
- * Since regular rename no longer opens the database, we may have
- * to do it here.
- */
- if (F_ISSET(dbp, DB_AM_OPEN_CALLED))
- tmpdbp = dbp;
- else {
- if ((ret = db_create(&tmpdbp, dbenv, 0)) != 0)
- return (ret);
- /* Copy the incoming locker so we don't self-deadlock. */
- tmpdbp->lid = dbp->lid;
- needclose = 1;
- if ((ret = __db_open(tmpdbp,
- txn, filename, NULL, DB_QUEUE, 0, 0, PGNO_BASE_MD)) != 0)
- goto err;
- }
-
- qp = (QUEUE *)tmpdbp->q_internal;
-
- if (qp->page_ext != 0)
- ret = __qam_nameop(tmpdbp, txn, newname, QAM_NAME_RENAME);
-
-err: if (needclose) {
- /* We copied this, so we mustn't free it. */
- tmpdbp->lid = DB_LOCK_INVALIDID;
-
- /* We need to remove the lockevent we associated with this. */
- if (txn != NULL)
- __txn_remlock(dbenv,
- txn, &tmpdbp->handle_lock, DB_LOCK_INVALIDID);
+/*
+ * __qam_set_flags --
+ * Set queue-specific flags.
+ *
+ * PUBLIC: int __qam_set_flags __P((DB *, u_int32_t *flagsp));
+ */
+int
+__qam_set_flags(dbp, flagsp)
+ DB *dbp;
+ u_int32_t *flagsp;
+{
- if ((t_ret =
- __db_close(tmpdbp, txn, DB_NOSYNC)) != 0 && ret == 0)
- ret = t_ret;
- }
- return (ret);
+ __qam_map_flags(dbp, flagsp, &dbp->flags);
+ return (0);
}
diff --git a/db/qam/qam_open.c b/db/qam/qam_open.c
index 53b9e17a1..595d74dac 100644
--- a/db/qam/qam_open.c
+++ b/db/qam/qam_open.c
@@ -1,16 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999-2003
+ * Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam_open.c,v 11.68 2004/02/27 12:38:31 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam_open.c,v 11.66 2003/09/25 01:35:38 margo Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
@@ -119,7 +117,8 @@ err: if (qmeta != NULL &&
ret = t_ret;
/* Don't hold the meta page long term. */
- (void)__LPUT(dbc, metalock);
+ if ((t_ret = __LPUT(dbc, metalock)) != 0 && ret == 0)
+ ret = t_ret;
if ((t_ret = __db_c_close(dbc)) != 0 && ret == 0)
ret = t_ret;
diff --git a/db/qam/qam_rec.c b/db/qam/qam_rec.c
index d846118ac..e92141ddd 100644
--- a/db/qam/qam_rec.c
+++ b/db/qam/qam_rec.c
@@ -1,16 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999-2003
+ * Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam_rec.c,v 11.78 2004/05/11 14:04:51 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam_rec.c,v 11.75 2003/08/17 23:38:14 ubell Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
@@ -50,7 +48,8 @@ __qam_incfirst_recover(dbenv, dbtp, lsnp, op, info)
QMETA *meta;
QUEUE_CURSOR *cp;
db_pgno_t metapg;
- int exact, modified, ret, rec_ext;
+ u_int32_t rec_ext;
+ int exact, modified, ret, t_ret;
REC_PRINT(__qam_incfirst_print);
REC_INTRO(__qam_incfirst_read, 1);
@@ -71,8 +70,7 @@ __qam_incfirst_recover(dbenv, dbtp, lsnp, op, info)
meta->dbmeta.type = P_QAMMETA;
} else {
*lsnp = argp->prev_lsn;
- ret = 0;
- (void)__LPUT(dbc, lock);
+ ret = __LPUT(dbc, lock);
goto out;
}
}
@@ -102,8 +100,9 @@ __qam_incfirst_recover(dbenv, dbtp, lsnp, op, info)
LSN(meta) = *lsnp;
modified = 1;
}
- rec_ext = 0;
- if (meta->page_ext != 0)
+ if (meta->page_ext == 0)
+ rec_ext = 0;
+ else
rec_ext = meta->page_ext * meta->rec_page;
cp = (QUEUE_CURSOR *)dbc->internal;
if (meta->first_recno == RECNO_OOB)
@@ -113,8 +112,9 @@ __qam_incfirst_recover(dbenv, dbtp, lsnp, op, info)
if ((ret = __qam_position(dbc,
&meta->first_recno, QAM_READ, &exact)) != 0)
goto err;
- if (cp->page != NULL)
- __qam_fput(file_dbp, cp->pgno, cp->page, 0);
+ if (cp->page != NULL && (ret =
+ __qam_fput(file_dbp, cp->pgno, cp->page, 0)) != 0)
+ goto err;
if (exact == 1)
break;
@@ -130,17 +130,18 @@ __qam_incfirst_recover(dbenv, dbtp, lsnp, op, info)
}
}
- if ((ret = __memp_fput(mpf, meta, modified ? DB_MPOOL_DIRTY : 0)) != 0)
- goto err1;
-
- (void)__LPUT(dbc, lock);
+ ret = __memp_fput(mpf, meta, modified ? DB_MPOOL_DIRTY : 0);
+ if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
+ ret = t_ret;
+ if (ret != 0)
+ goto out;
done: *lsnp = argp->prev_lsn;
ret = 0;
if (0) {
err: (void)__memp_fput(mpf, meta, 0);
-err1: (void)__LPUT(dbc, lock);
+ (void)__LPUT(dbc, lock);
}
out: REC_CLOSE;
@@ -190,8 +191,7 @@ __qam_mvptr_recover(dbenv, dbtp, lsnp, op, info)
meta->dbmeta.type = P_QAMMETA;
} else {
*lsnp = argp->prev_lsn;
- ret = 0;
- (void)__LPUT(dbc, lock);
+ ret = __LPUT(dbc, lock);
goto out;
}
}
@@ -235,7 +235,8 @@ __qam_mvptr_recover(dbenv, dbtp, lsnp, op, info)
if ((ret = __memp_fput(mpf, meta, modified ? DB_MPOOL_DIRTY : 0)) != 0)
goto out;
- (void)__LPUT(dbc, lock);
+ if ((ret = __LPUT(dbc, lock)) != 0)
+ goto out;
done: *lsnp = argp->prev_lsn;
ret = 0;
@@ -268,7 +269,7 @@ __qam_del_recover(dbenv, dbtp, lsnp, op, info)
QMETA *meta;
QPAGE *pagep;
db_pgno_t metapg;
- int cmp_n, modified, ret;
+ int cmp_n, modified, ret, t_ret;
COMPQUIET(info, NULL);
REC_PRINT(__qam_del_print);
@@ -303,10 +304,13 @@ __qam_del_recover(dbenv, dbtp, lsnp, op, info)
meta->first_recno -
argp->recno < argp->recno - meta->cur_recno))) {
meta->first_recno = argp->recno;
- (void)__memp_fput(mpf, meta, DB_MPOOL_DIRTY);
+ ret = __memp_fput(mpf, meta, DB_MPOOL_DIRTY);
} else
- (void)__memp_fput(mpf, meta, 0);
- (void)__LPUT(dbc, lock);
+ ret = __memp_fput(mpf, meta, 0);
+ if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
+ ret = t_ret;
+ if (ret != 0)
+ goto err;
/* Need to undo delete - mark the record as present */
qp = QAM_GET_RECORD(file_dbp, pagep, argp->indx);
@@ -367,7 +371,7 @@ __qam_delext_recover(dbenv, dbtp, lsnp, op, info)
QMETA *meta;
QPAGE *pagep;
db_pgno_t metapg;
- int cmp_n, modified, ret;
+ int cmp_n, modified, ret, t_ret;
COMPQUIET(info, NULL);
REC_PRINT(__qam_delext_print);
@@ -412,10 +416,13 @@ __qam_delext_recover(dbenv, dbtp, lsnp, op, info)
meta->first_recno -
argp->recno < argp->recno - meta->cur_recno))) {
meta->first_recno = argp->recno;
- (void)__memp_fput(mpf, meta, DB_MPOOL_DIRTY);
+ ret = __memp_fput(mpf, meta, DB_MPOOL_DIRTY);
} else
- (void)__memp_fput(mpf, meta, 0);
- (void)__LPUT(dbc, lock);
+ ret = __memp_fput(mpf, meta, 0);
+ if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
+ ret = t_ret;
+ if (ret != 0)
+ goto err;
if ((ret = __qam_pitem(dbc, pagep,
argp->indx, argp->recno, &argp->data)) != 0)
diff --git a/db/qam/qam_stat.c b/db/qam/qam_stat.c
index bc6409e2f..c5264bd01 100644
--- a/db/qam/qam_stat.c
+++ b/db/qam/qam_stat.c
@@ -1,19 +1,18 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999-2003
+ * Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam_stat.c,v 11.47 2004/09/22 16:29:47 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam_stat.c,v 11.38 2003/09/04 18:06:48 bostic Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
+#include <ctype.h>
#include <string.h>
#endif
@@ -25,6 +24,7 @@ static const char revid[] = "$Id: qam_stat.c,v 11.38 2003/09/04 18:06:48 bostic
#include "dbinc/mp.h"
#include "dbinc/qam.h"
+#ifdef HAVE_STATISTICS
/*
* __qam_stat --
* Gather/print the qam statistics
@@ -48,7 +48,7 @@ __qam_stat(dbc, spp, flags)
db_indx_t indx;
db_pgno_t first, last, pgno, pg_ext, stop;
u_int32_t re_len;
- int ret;
+ int ret, t_ret;
dbp = dbc->dbp;
@@ -82,13 +82,15 @@ __qam_stat(dbc, spp, flags)
first = QAM_RECNO_PAGE(dbp, meta->first_recno);
last = QAM_RECNO_PAGE(dbp, meta->cur_recno);
- if ((ret = __memp_fput(mpf, meta, 0)) != 0)
+ ret = __memp_fput(mpf, meta, 0);
+ if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
+ ret = t_ret;
+ if (ret != 0)
goto err;
- (void)__LPUT(dbc, lock);
pgno = first;
if (first > last)
- stop = QAM_RECNO_PAGE(dbp, UINT32_T_MAX);
+ stop = QAM_RECNO_PAGE(dbp, UINT32_MAX);
else
stop = last;
@@ -112,7 +114,7 @@ begin:
ret = 0;
break;
}
- pgno += pg_ext - ((pgno - 1) % pg_ext) - 1;
+ pgno += (pg_ext - ((pgno - 1) % pg_ext)) - 1;
continue;
}
if (ret != 0)
@@ -130,12 +132,15 @@ begin:
sp->qs_pgfree += re_len;
}
- if ((ret = __qam_fput(dbp, pgno, h, 0)) != 0)
+ ret = __qam_fput(dbp, pgno, h, 0);
+ if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
+ ret = t_ret;
+ if (ret != 0)
goto err;
- (void)__LPUT(dbc, lock);
}
- (void)__LPUT(dbc, lock);
+ if ((ret = __LPUT(dbc, lock)) != 0)
+ goto err;
if (first > last) {
pgno = 1;
stop = last;
@@ -169,20 +174,88 @@ meta_only:
sp->qs_cur_recno = meta->cur_recno;
/* Discard the meta-data page. */
- if ((ret = __memp_fput(mpf,
- meta, F_ISSET(dbp, DB_AM_RDONLY) ? 0 : DB_MPOOL_DIRTY)) != 0)
+ ret = __memp_fput(mpf,
+ meta, F_ISSET(dbp, DB_AM_RDONLY) ? 0 : DB_MPOOL_DIRTY);
+ if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
+ ret = t_ret;
+ if (ret != 0)
goto err;
- (void)__LPUT(dbc, lock);
*(DB_QUEUE_STAT **)spp = sp;
- ret = 0;
if (0) {
err: if (sp != NULL)
__os_ufree(dbp->dbenv, sp);
}
- (void)__LPUT(dbc, lock);
+ if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
+ ret = t_ret;
return (ret);
}
+
+/*
+ * __qam_stat_print --
+ * Display queue statistics.
+ *
+ * PUBLIC: int __qam_stat_print __P((DBC *, u_int32_t));
+ */
+int
+__qam_stat_print(dbc, flags)
+ DBC *dbc;
+ u_int32_t flags;
+{
+ DB *dbp;
+ DB_ENV *dbenv;
+ DB_QUEUE_STAT *sp;
+ int ret;
+
+ dbp = dbc->dbp;
+ dbenv = dbp->dbenv;
+
+ if ((ret = __qam_stat(dbc, &sp, 0)) != 0)
+ return (ret);
+
+ if (LF_ISSET(DB_STAT_ALL)) {
+ __db_msg(dbenv, "%s", DB_GLOBAL(db_line));
+ __db_msg(dbenv, "Default Queue database information:");
+ }
+ __db_msg(dbenv, "%lx\tQueue magic number", (u_long)sp->qs_magic);
+ __db_msg(dbenv, "%lu\tQueue version number", (u_long)sp->qs_version);
+ __db_dl(dbenv, "Fixed-length record size", (u_long)sp->qs_re_len);
+ __db_msg(dbenv, "%#x\tFixed-length record pad", (int)sp->qs_re_pad);
+ __db_dl(dbenv,
+ "Underlying database page size", (u_long)sp->qs_pagesize);
+ __db_dl(dbenv,
+ "Underlying database extent size", (u_long)sp->qs_extentsize);
+ __db_dl(dbenv,
+ "Number of records in the database", (u_long)sp->qs_nkeys);
+ __db_dl(dbenv, "Number of database pages", (u_long)sp->qs_pages);
+ __db_dl_pct(dbenv,
+ "Number of bytes free in database pages",
+ (u_long)sp->qs_pgfree,
+ DB_PCT_PG(sp->qs_pgfree, sp->qs_pages, sp->qs_pagesize), "ff");
+ __db_msg(dbenv,
+ "%lu\tFirst undeleted record", (u_long)sp->qs_first_recno);
+ __db_msg(dbenv,
+ "%lu\tNext available record number", (u_long)sp->qs_cur_recno);
+
+ __os_ufree(dbenv, sp);
+
+ return (0);
+}
+
+#else /* !HAVE_STATISTICS */
+
+int
+__qam_stat(dbc, spp, flags)
+ DBC *dbc;
+ void *spp;
+ u_int32_t flags;
+{
+ COMPQUIET(spp, NULL);
+ COMPQUIET(flags, 0);
+
+ return (__db_stat_not_built(dbc->dbp->dbenv));
+}
+#endif
diff --git a/db/qam/qam_stub.c b/db/qam/qam_stub.c
index 941aacfb4..1c22aaa52 100644
--- a/db/qam/qam_stub.c
+++ b/db/qam/qam_stub.c
@@ -1,15 +1,15 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996-2003
+ * Copyright (c) 1996-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam_stub.c,v 1.12 2004/06/14 15:23:33 bostic Exp $
*/
-#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam_stub.c,v 1.7 2003/10/28 18:52:34 bostic Exp $";
-#endif /* not lint */
+#include "db_config.h"
+#ifndef HAVE_QUEUE
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif
@@ -40,12 +40,10 @@ __db_no_queue_am(dbenv)
}
int
-__db_prqueue(dbp, fp, flags)
+__db_prqueue(dbp, flags)
DB *dbp;
- FILE *fp;
u_int32_t flags;
{
- COMPQUIET(fp, NULL);
COMPQUIET(flags, 0);
return (__db_no_queue_am(dbp->dbenv));
}
@@ -136,18 +134,6 @@ __qam_gen_filelist(dbp, filelistp)
}
int
-__qam_init_getpgnos(dbenv, dtabp, dtabsizep)
- DB_ENV *dbenv;
- int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
- size_t *dtabsizep;
-{
- COMPQUIET(dbenv, NULL);
- COMPQUIET(dtabp, NULL);
- COMPQUIET(dtabsizep, NULL);
- return (0);
-}
-
-int
__qam_init_print(dbenv, dtabp, dtabsizep)
DB_ENV *dbenv;
int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
@@ -265,6 +251,15 @@ __qam_stat(dbc, spp, flags)
}
int
+__qam_stat_print(dbc, flags)
+ DBC *dbc;
+ u_int32_t flags;
+{
+ COMPQUIET(flags, 0);
+ return (__db_no_queue_am(dbc->dbp->dbenv));
+}
+
+int
__qam_sync(dbp)
DB *dbp;
{
@@ -336,3 +331,4 @@ __qam_vrfy_walkqueue(dbp, vdp, handle, callback, flags)
COMPQUIET(flags, 0);
return (__db_no_queue_am(dbp->dbenv));
}
+#endif /* !HAVE_QUEUE */
diff --git a/db/qam/qam_upgrade.c b/db/qam/qam_upgrade.c
index b10b4696a..dff82404a 100644
--- a/db/qam/qam_upgrade.c
+++ b/db/qam/qam_upgrade.c
@@ -1,19 +1,17 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996-2003
+ * Copyright (c) 1996-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam_upgrade.c,v 11.16 2004/05/10 21:29:43 bostic Exp $
*/
-#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam_upgrade.c,v 11.14 2003/01/08 05:37:44 bostic Exp $";
-#endif /* not lint */
+#include "db_config.h"
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
-#include <limits.h>
#include <string.h>
#endif
diff --git a/db/qam/qam_verify.c b/db/qam/qam_verify.c
index ddbc9525f..571157b8f 100644
--- a/db/qam/qam_verify.c
+++ b/db/qam/qam_verify.c
@@ -1,16 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999-2003
+ * Copyright (c) 1999-2004
* Sleepycat Software. All rights reserved.
+ *
+ * $Id: qam_verify.c,v 1.51 2004/10/11 18:47:51 bostic Exp $
*/
#include "db_config.h"
-#ifndef lint
-static const char revid[] = "$Id: qam_verify.c,v 1.45 2003/08/12 19:51:55 ubell Exp $";
-#endif /* not lint */
-
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
@@ -49,11 +47,14 @@ __qam_vrfy_meta(dbp, vdp, meta, pgno, flags)
int count, i, isbad, nextents, ret, t_ret;
char *buf, **names;
+ COMPQUIET(count, 0);
+
dbenv = dbp->dbenv;
+ qp = (QUEUE *)dbp->q_internal;
+ extents = NULL;
first = last = 0;
buf = NULL;
names = NULL;
- qp = (QUEUE *)dbp->q_internal;
if ((ret = __db_vrfy_getpageinfo(vdp, pgno, &pip)) != 0)
return (ret);
@@ -79,7 +80,7 @@ __qam_vrfy_meta(dbp, vdp, meta, pgno, flags)
* re_len: If this is bad, we can't safely verify queue data pages, so
* return DB_VERIFY_FATAL
*/
- if (ALIGN(meta->re_len + sizeof(QAMDATA) - 1, sizeof(u_int32_t)) *
+ if (DB_ALIGN(meta->re_len + sizeof(QAMDATA) - 1, sizeof(u_int32_t)) *
meta->rec_page + QPAGE_SZ(dbp) > dbp->pgsize) {
EPRINT((dbenv,
"Page %lu: queue record length %lu too high for page size and recs/page",
@@ -145,21 +146,19 @@ __qam_vrfy_meta(dbp, vdp, meta, pgno, flags)
len = strlen(QUEUE_EXTENT_HEAD) + strlen(qp->name) + 1;
if ((ret = __os_malloc(dbenv, len, &buf)) != 0)
goto err;
- len = snprintf(buf, len, QUEUE_EXTENT_HEAD, qp->name);
- nextents = 0;
- extents = NULL;
- for (i = 0; i < count; i++) {
+ len = (size_t)snprintf(buf, len, QUEUE_EXTENT_HEAD, qp->name);
+ for (i = nextents = 0; i < count; i++) {
if (strncmp(names[i], buf, len) == 0) {
/* Only save extents out of bounds. */
- extid = atoi(&names[i][len]);
+ extid = (db_pgno_t)strtoul(&names[i][len], NULL, 10);
if (qp->page_ext != 0 &&
(last > first ?
(extid >= first && extid <= last) :
(extid >= first || extid <= last)))
continue;
- if (extents == NULL &&
- (ret = __os_malloc(dbenv,
- (count - i) * sizeof(extid), &extents)) != 0)
+ if (extents == NULL && (ret = __os_malloc(
+ dbenv, (size_t)(count - i) * sizeof(extid),
+ &extents)) != 0)
goto err;
extents[nextents] = extid;
nextents++;
@@ -179,6 +178,9 @@ err: if ((t_ret = __db_vrfy_putpageinfo(dbenv, vdp, pip)) != 0 && ret == 0)
__os_free(dbenv, buf);
if (ret != 0 && extents != NULL)
__os_free(dbenv, extents);
+ if (LF_ISSET(DB_SALVAGE) &&
+ (t_ret = __db_salvage_markdone(vdp, pgno)) != 0 && ret == 0)
+ ret = t_ret;
return (ret == 0 && isbad == 1 ? DB_VERIFY_BAD : ret);
}
@@ -312,13 +314,13 @@ __qam_vrfy_walkqueue(dbp, vdp, handle, callback, flags)
db_pgno_t first, i, last, pg_ext, stop;
int isbad, nextents, ret, t_ret;
- isbad = ret = t_ret = 0;
+ COMPQUIET(h, NULL);
- pip = NULL;
dbenv = dbp->dbenv;
qp = dbp->q_internal;
-
+ pip = NULL;
pg_ext = qp->page_ext;
+ isbad = ret = t_ret = 0;
/* If this database has no extents, we've seen all the pages already. */
if (pg_ext == 0)
@@ -329,14 +331,13 @@ __qam_vrfy_walkqueue(dbp, vdp, handle, callback, flags)
i = first;
if (first > last)
- stop = QAM_RECNO_PAGE(dbp, UINT32_T_MAX);
+ stop = QAM_RECNO_PAGE(dbp, UINT32_MAX);
else
stop = last;
nextents = vdp->nextents;
/* Verify/salvage each page. */
-begin:
- for (; i <= stop; i++) {
+begin: for (; i <= stop; i++) {
/*
* If DB_SALVAGE is set, we inspect our database of completed
* pages, and skip any we've already printed in the subdb pass.
@@ -345,7 +346,7 @@ begin:
continue;
if ((t_ret = __qam_fget(dbp, &i, 0, &h)) != 0) {
if (t_ret == ENOENT || t_ret == DB_PAGE_NOTFOUND) {
- i += pg_ext - ((i - 1) % pg_ext) - 1;
+ i += (pg_ext - ((i - 1) % pg_ext)) - 1;
continue;
}
@@ -382,7 +383,6 @@ begin:
* may make it easier to diagnose problems and
* determine the magnitude of the corruption.
*/
-
if ((ret = __db_vrfy_common(dbp,
vdp, h, i, flags)) == DB_VERIFY_BAD)
isbad = 1;
@@ -402,8 +402,7 @@ begin:
isbad = 1;
goto err;
}
- if ((ret =
- __db_vrfy_pgset_inc(vdp->pgset, i)) != 0)
+ if ((ret = __db_vrfy_pgset_inc(vdp->pgset, i)) != 0)
goto err;
if ((ret = __qam_vrfy_data(dbp, vdp,
(QPAGE *)h, i, flags)) == DB_VERIFY_BAD)
@@ -438,7 +437,6 @@ put: if ((ret = __db_vrfy_putpageinfo(dbenv, vdp, pip)) != 0)
* Now check to see if there were any lingering
* extents and dump their data.
*/
-
if (LF_ISSET(DB_SALVAGE) && nextents != 0) {
nextents--;
i = 1 +
@@ -505,11 +503,11 @@ __qam_salvage(dbp, vdp, pgno, h, handle, callback, flags)
continue;
dbt.data = qp->data;
- if ((ret = __db_prdbt(&key,
+ if ((ret = __db_vrfy_prdbt(&key,
0, " ", handle, callback, 1, vdp)) != 0)
err_ret = ret;
- if ((ret = __db_prdbt(&dbt,
+ if ((ret = __db_vrfy_prdbt(&dbt,
0, " ", handle, callback, 0, vdp)) != 0)
err_ret = ret;
}