diff options
Diffstat (limited to 'db2/txn')
-rw-r--r-- | db2/txn/txn.c | 1046 | ||||
-rw-r--r-- | db2/txn/txn.src | 55 | ||||
-rw-r--r-- | db2/txn/txn_auto.c | 621 | ||||
-rw-r--r-- | db2/txn/txn_rec.c | 296 |
4 files changed, 0 insertions, 2018 deletions
diff --git a/db2/txn/txn.c b/db2/txn/txn.c deleted file mode 100644 index aa0b3652ce..0000000000 --- a/db2/txn/txn.c +++ /dev/null @@ -1,1046 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ -/* - * Copyright (c) 1995, 1996 - * The President and Fellows of Harvard University. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Margo Seltzer. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)txn.c 10.66 (Sleepycat) 1/3/99"; -#endif /* not lint */ - - -#ifndef NO_SYSTEM_INCLUDES -#include <sys/types.h> - -#include <errno.h> -#include <string.h> -#include <time.h> -#endif - -#include "db_int.h" -#include "shqueue.h" -#include "db_page.h" -#include "db_shash.h" -#include "txn.h" -#include "db_dispatch.h" -#include "lock.h" -#include "log.h" -#include "db_am.h" -#include "common_ext.h" - -static int __txn_begin __P((DB_TXN *)); -static int __txn_check_running __P((const DB_TXN *, TXN_DETAIL **)); -static int __txn_end __P((DB_TXN *, int)); -static void __txn_freekids __P((DB_TXN *)); -static int __txn_grow_region __P((DB_TXNMGR *)); -static int __txn_init __P((DB_TXNREGION *)); -static int __txn_undo __P((DB_TXN *)); -static int __txn_validate_region __P((DB_TXNMGR *)); - -/* - * This file contains the top level routines of the transaction library. - * It assumes that a lock manager and log manager that conform to the db_log(3) - * and db_lock(3) interfaces exist. - * - * Initialize a transaction region in shared memory. - * Return 0 on success, errno on failure. - */ -static int -__txn_init(txn_region) - DB_TXNREGION *txn_region; -{ - time_t now; - - (void)time(&now); - - /* maxtxns is already initialized. */ - txn_region->magic = DB_TXNMAGIC; - txn_region->version = DB_TXNVERSION; - txn_region->last_txnid = TXN_MINIMUM; - /* - * XXX - * If we ever do more types of locking and logging, this changes. - */ - txn_region->logtype = 0; - txn_region->locktype = 0; - txn_region->time_ckp = now; - ZERO_LSN(txn_region->last_ckp); - ZERO_LSN(txn_region->pending_ckp); - SH_TAILQ_INIT(&txn_region->active_txn); - __db_shalloc_init((void *)&txn_region[1], - TXN_REGION_SIZE(txn_region->maxtxns) - sizeof(DB_TXNREGION)); - - return (0); -} - -int -txn_open(path, flags, mode, dbenv, mgrpp) - const char *path; - u_int32_t flags; - int mode; - DB_ENV *dbenv; - DB_TXNMGR **mgrpp; -{ - DB_TXNMGR *tmgrp; - u_int32_t maxtxns; - int ret; - - /* Validate arguments. */ - if (dbenv == NULL) - return (EINVAL); -#ifdef HAVE_SPINLOCKS -#define OKFLAGS (DB_CREATE | DB_THREAD | DB_TXN_NOSYNC) -#else -#define OKFLAGS (DB_CREATE | DB_TXN_NOSYNC) -#endif - if ((ret = __db_fchk(dbenv, "txn_open", flags, OKFLAGS)) != 0) - return (ret); - - maxtxns = dbenv->tx_max != 0 ? dbenv->tx_max : 20; - - /* Now, create the transaction manager structure and set its fields. */ - if ((ret = __os_calloc(1, sizeof(DB_TXNMGR), &tmgrp)) != 0) - return (ret); - - /* Initialize the transaction manager structure. */ - tmgrp->mutexp = NULL; - tmgrp->dbenv = dbenv; - tmgrp->recover = - dbenv->tx_recover == NULL ? __db_dispatch : dbenv->tx_recover; - tmgrp->flags = LF_ISSET(DB_TXN_NOSYNC | DB_THREAD); - TAILQ_INIT(&tmgrp->txn_chain); - - /* Join/create the txn region. */ - tmgrp->reginfo.dbenv = dbenv; - tmgrp->reginfo.appname = DB_APP_NONE; - if (path == NULL) - tmgrp->reginfo.path = NULL; - else - if ((ret = __os_strdup(path, &tmgrp->reginfo.path)) != 0) - goto err; - tmgrp->reginfo.file = DEFAULT_TXN_FILE; - tmgrp->reginfo.mode = mode; - tmgrp->reginfo.size = TXN_REGION_SIZE(maxtxns); - tmgrp->reginfo.dbflags = flags; - tmgrp->reginfo.addr = NULL; - tmgrp->reginfo.fd = -1; - tmgrp->reginfo.flags = dbenv->tx_max == 0 ? REGION_SIZEDEF : 0; - if ((ret = __db_rattach(&tmgrp->reginfo)) != 0) - goto err; - - /* Fill in region-related fields. */ - tmgrp->region = tmgrp->reginfo.addr; - tmgrp->mem = &tmgrp->region[1]; - - if (F_ISSET(&tmgrp->reginfo, REGION_CREATED)) { - tmgrp->region->maxtxns = maxtxns; - if ((ret = __txn_init(tmgrp->region)) != 0) - goto err; - - } else if (tmgrp->region->magic != DB_TXNMAGIC) { - /* Check if valid region. */ - __db_err(dbenv, "txn_open: Bad magic number"); - ret = EINVAL; - goto err; - } - - if (LF_ISSET(DB_THREAD)) { - if ((ret = __db_shalloc(tmgrp->mem, sizeof(db_mutex_t), - MUTEX_ALIGNMENT, &tmgrp->mutexp)) == 0) - /* - * Since we only get here if threading is turned on, we - * know that we have spinlocks, so the offset is going - * to be ignored. We put 0 here as a valid placeholder. - */ - __db_mutex_init(tmgrp->mutexp, 0); - if (ret != 0) - goto err; - } - - UNLOCK_TXNREGION(tmgrp); - *mgrpp = tmgrp; - return (0); - -err: if (tmgrp->reginfo.addr != NULL) { - if (tmgrp->mutexp != NULL) - __db_shalloc_free(tmgrp->mem, tmgrp->mutexp); - - UNLOCK_TXNREGION(tmgrp); - (void)__db_rdetach(&tmgrp->reginfo); - if (F_ISSET(&tmgrp->reginfo, REGION_CREATED)) - (void)txn_unlink(path, 1, dbenv); - } - - if (tmgrp->reginfo.path != NULL) - __os_freestr(tmgrp->reginfo.path); - __os_free(tmgrp, sizeof(*tmgrp)); - return (ret); -} - -/* - * __txn_panic -- - * Panic a transaction region. - * - * PUBLIC: void __txn_panic __P((DB_ENV *)); - */ -void -__txn_panic(dbenv) - DB_ENV *dbenv; -{ - if (dbenv->tx_info != NULL) - dbenv->tx_info->region->hdr.panic = 1; -} - -/* - * txn_begin -- - * This is a wrapper to the actual begin process. Normal txn_begin() - * allocates a DB_TXN structure for the caller, while txn_xa_begin() does - * not. Other than that, both call into the common __txn_begin code(). - * - * Internally, we use TXN_DETAIL structures, but the DB_TXN structure - * provides access to the transaction ID and the offset in the transaction - * region of the TXN_DETAIL structure. - */ -int -txn_begin(tmgrp, parent, txnpp) - DB_TXNMGR *tmgrp; - DB_TXN *parent, **txnpp; -{ - DB_TXN *txn; - int ret; - - TXN_PANIC_CHECK(tmgrp); - - if ((ret = __os_calloc(1, sizeof(DB_TXN), &txn)) != 0) - return (ret); - - txn->parent = parent; - TAILQ_INIT(&txn->kids); - txn->mgrp = tmgrp; - txn->flags = TXN_MALLOC; - if ((ret = __txn_begin(txn)) != 0) { - __os_free(txn, sizeof(DB_TXN)); - txn = NULL; - } - if (txn != NULL && parent != NULL) - TAILQ_INSERT_HEAD(&parent->kids, txn, klinks); - *txnpp = txn; - return (ret); -} - -/* - * __txn_xa_begin -- - * XA version of txn_begin. - * - * PUBLIC: int __txn_xa_begin __P((DB_ENV *, DB_TXN *)); - */ -int -__txn_xa_begin(dbenv, txn) - DB_ENV *dbenv; - DB_TXN *txn; -{ - TXN_PANIC_CHECK(dbenv->tx_info); - - memset(txn, 0, sizeof(DB_TXN)); - - txn->mgrp = dbenv->tx_info; - - return (__txn_begin(txn)); -} - -/* - * __txn_begin -- - * Normal DB version of txn_begin. - */ -static int -__txn_begin(txn) - DB_TXN *txn; -{ - DB_LSN begin_lsn; - DB_TXNMGR *mgr; - TXN_DETAIL *td; - size_t off; - u_int32_t id; - int ret; - - /* - * We do not have to write begin records (and if we do not, then we - * need never write records for read-only transactions). However, - * we do need to find the current LSN so that we can store it in the - * transaction structure, so we can know where to take checkpoints. - */ - mgr = txn->mgrp; - if (mgr->dbenv->lg_info != NULL && (ret = - log_put(mgr->dbenv->lg_info, &begin_lsn, NULL, DB_CURLSN)) != 0) - goto err2; - - LOCK_TXNREGION(mgr); - - /* Make sure that last_txnid is not going to wrap around. */ - if (mgr->region->last_txnid == TXN_INVALID) { - __db_err(mgr->dbenv, "txn_begin: %s %s", - "Transaction ID wrapping.", - "Snapshot your database and start a new log."); - ret = EINVAL; - goto err1; - } - - if ((ret = __txn_validate_region(mgr)) != 0) - goto err1; - - /* Allocate a new transaction detail structure. */ - if ((ret = __db_shalloc(mgr->mem, sizeof(TXN_DETAIL), 0, &td)) != 0 - && ret == ENOMEM && (ret = __txn_grow_region(mgr)) == 0) - ret = __db_shalloc(mgr->mem, sizeof(TXN_DETAIL), 0, &td); - if (ret != 0) - goto err1; - - /* Place transaction on active transaction list. */ - SH_TAILQ_INSERT_HEAD(&mgr->region->active_txn, td, links, __txn_detail); - - id = ++mgr->region->last_txnid; - ++mgr->region->nbegins; - - td->txnid = id; - td->begin_lsn = begin_lsn; - ZERO_LSN(td->last_lsn); - td->last_lock = 0; - td->status = TXN_RUNNING; - if (txn->parent != NULL) - td->parent = txn->parent->off; - else - td->parent = 0; - - off = (u_int8_t *)td - (u_int8_t *)mgr->region; - UNLOCK_TXNREGION(mgr); - - ZERO_LSN(txn->last_lsn); - txn->txnid = id; - txn->off = off; - - if (F_ISSET(txn, TXN_MALLOC)) { - LOCK_TXNTHREAD(mgr); - TAILQ_INSERT_TAIL(&mgr->txn_chain, txn, links); - UNLOCK_TXNTHREAD(mgr); - } - - return (0); - -err1: UNLOCK_TXNREGION(mgr); - -err2: return (ret); -} -/* - * txn_commit -- - * Commit a transaction. - */ -int -txn_commit(txnp) - DB_TXN *txnp; -{ - DB_LOG *logp; - DB_TXNMGR *mgr; - int ret; - - mgr = txnp->mgrp; - - TXN_PANIC_CHECK(mgr); - if ((ret = __txn_check_running(txnp, NULL)) != 0) - return (ret); - - /* - * If there are any log records, write a log record and sync - * the log, else do no log writes. If the commit is for a child - * transaction, we do not need to commit the child synchronously - * since if its parent aborts, it will abort too and its parent - * (or ultimate ancestor) will write synchronously. - */ - if ((logp = mgr->dbenv->lg_info) != NULL && - !IS_ZERO_LSN(txnp->last_lsn)) { - if (txnp->parent == NULL) - ret = __txn_regop_log(logp, txnp, &txnp->last_lsn, - F_ISSET(mgr, DB_TXN_NOSYNC) ? 0 : DB_FLUSH, - TXN_COMMIT); - else - ret = __txn_child_log(logp, txnp, &txnp->last_lsn, 0, - TXN_COMMIT, txnp->parent->txnid); - if (ret != 0) - return (ret); - } - - /* - * If this is the senior ancestor (i.e., it has no children), then we - * can release all the child transactions since everyone is committing. - * Then we can release this transaction. If this is not the ultimate - * ancestor, then we can neither free it or its children. - */ - if (txnp->parent == NULL) - __txn_freekids(txnp); - - return (__txn_end(txnp, 1)); -} - -/* - * txn_abort -- - * Abort a transcation. - */ -int -txn_abort(txnp) - DB_TXN *txnp; -{ - int ret; - DB_TXN *kids; - - TXN_PANIC_CHECK(txnp->mgrp); - if ((ret = __txn_check_running(txnp, NULL)) != 0) - return (ret); - - for (kids = TAILQ_FIRST(&txnp->kids); - kids != NULL; - kids = TAILQ_FIRST(&txnp->kids)) - txn_abort(kids); - - if ((ret = __txn_undo(txnp)) != 0) { - __db_err(txnp->mgrp->dbenv, - "txn_abort: Log undo failed %s", strerror(ret)); - return (ret); - } - return (__txn_end(txnp, 0)); -} - -/* - * txn_prepare -- - * Flush the log so a future commit is guaranteed to succeed. - */ -int -txn_prepare(txnp) - DB_TXN *txnp; -{ - DBT xid; - DB_ENV *dbenv; - TXN_DETAIL *td; - int ret; - - if ((ret = __txn_check_running(txnp, &td)) != 0) - return (ret); - - dbenv = txnp->mgrp->dbenv; - memset(&xid, 0, sizeof(xid)); - xid.data = td->xid; - /* - * We indicate that a transaction is an XA transaction by putting - * a valid size in the xid.size fiels. XA requires that the transaction - * be either ENDED or SUSPENDED when prepare is called, so we know - * that if the xa_status isn't in one of those states, but we are - * calling prepare that we are not an XA transaction. - */ - xid.size = - td->xa_status != TXN_XA_ENDED && td->xa_status != TXN_XA_SUSPENDED ? - 0 : sizeof(td->xid); - if (dbenv->lg_info != NULL && - (ret = __txn_xa_regop_log(dbenv->lg_info, txnp, &txnp->last_lsn, - F_ISSET(txnp->mgrp, DB_TXN_NOSYNC) ? 0 : DB_FLUSH, TXN_PREPARE, - &xid, td->format, td->gtrid, td->bqual, &td->begin_lsn)) != 0) { - __db_err(dbenv, - "txn_prepare: log_write failed %s\n", strerror(ret)); - return (ret); - } - - LOCK_TXNTHREAD(txnp->mgrp); - td->status = TXN_PREPARED; - UNLOCK_TXNTHREAD(txnp->mgrp); - return (ret); -} - -/* - * Return the transaction ID associated with a particular transaction - */ -u_int32_t -txn_id(txnp) - DB_TXN *txnp; -{ - return (txnp->txnid); -} - -/* - * txn_close -- - * Close the transaction region, does not imply a checkpoint. - */ -int -txn_close(tmgrp) - DB_TXNMGR *tmgrp; -{ - DB_TXN *txnp; - int ret, t_ret; - - TXN_PANIC_CHECK(tmgrp); - - ret = 0; - - /* - * This function had better only be called once per process - * (i.e., not per thread), so there should be no synchronization - * required. - */ - while ((txnp = - TAILQ_FIRST(&tmgrp->txn_chain)) != TAILQ_END(&tmgrp->txn_chain)) - if ((t_ret = txn_abort(txnp)) != 0) { - __txn_end(txnp, 0); - if (ret == 0) - ret = t_ret; - } - - if (tmgrp->dbenv->lg_info && - (t_ret = log_flush(tmgrp->dbenv->lg_info, NULL)) != 0 && ret == 0) - ret = t_ret; - - if (tmgrp->mutexp != NULL) { - LOCK_TXNREGION(tmgrp); - __db_shalloc_free(tmgrp->mem, tmgrp->mutexp); - UNLOCK_TXNREGION(tmgrp); - } - - if ((t_ret = __db_rdetach(&tmgrp->reginfo)) != 0 && ret == 0) - ret = t_ret; - - if (tmgrp->reginfo.path != NULL) - __os_freestr(tmgrp->reginfo.path); - __os_free(tmgrp, sizeof(*tmgrp)); - - return (ret); -} - -/* - * txn_unlink -- - * Remove the transaction region. - */ -int -txn_unlink(path, force, dbenv) - const char *path; - int force; - DB_ENV *dbenv; -{ - REGINFO reginfo; - int ret; - - memset(®info, 0, sizeof(reginfo)); - reginfo.dbenv = dbenv; - reginfo.appname = DB_APP_NONE; - if (path != NULL && (ret = __os_strdup(path, ®info.path)) != 0) - return (ret); - reginfo.file = DEFAULT_TXN_FILE; - ret = __db_runlink(®info, force); - if (reginfo.path != NULL) - __os_freestr(reginfo.path); - return (ret); -} - -/* Internal routines. */ - -/* - * Return 0 if the txnp is reasonable, otherwise returns EINVAL. - */ -static int -__txn_check_running(txnp, tdp) - const DB_TXN *txnp; - TXN_DETAIL **tdp; -{ - TXN_DETAIL *tp; - - tp = NULL; - if (txnp != NULL && txnp->mgrp != NULL && txnp->mgrp->region != NULL) { - tp = (TXN_DETAIL *)((u_int8_t *)txnp->mgrp->region + txnp->off); - /* - * Child transactions could be marked committed which is OK. - */ - if (tp->status != TXN_RUNNING && - tp->status != TXN_PREPARED && tp->status != TXN_COMMITTED) - tp = NULL; - if (tdp != NULL) - *tdp = tp; - } - - return (tp == NULL ? EINVAL : 0); -} - -static int -__txn_end(txnp, is_commit) - DB_TXN *txnp; - int is_commit; -{ - DB_LOCKREQ request; - DB_TXNMGR *mgr; - TXN_DETAIL *tp; - u_int32_t locker; - int ret; - - mgr = txnp->mgrp; - - /* Release the locks. */ - locker = txnp->txnid; - request.op = txnp->parent == NULL || - is_commit == 0 ? DB_LOCK_PUT_ALL : DB_LOCK_INHERIT; - - if (mgr->dbenv->lk_info) { - ret = - lock_tvec(mgr->dbenv->lk_info, txnp, 0, &request, 1, NULL); - if (ret != 0 && (ret != DB_LOCK_DEADLOCK || is_commit)) { - __db_err(mgr->dbenv, "%s: release locks failed %s", - is_commit ? "txn_commit" : "txn_abort", - strerror(ret)); - return (ret); - } - } - - /* End the transaction. */ - LOCK_TXNREGION(mgr); - - /* - * Child transactions that are committing cannot be released until - * the parent commits, since the parent may abort, causing the child - * to abort as well. - */ - tp = (TXN_DETAIL *)((u_int8_t *)mgr->region + txnp->off); - if (txnp->parent == NULL || !is_commit) { - SH_TAILQ_REMOVE(&mgr->region->active_txn, - tp, links, __txn_detail); - - __db_shalloc_free(mgr->mem, tp); - } else - tp->status = is_commit ? TXN_COMMITTED : TXN_ABORTED; - - if (is_commit) - mgr->region->ncommits++; - else - mgr->region->naborts++; - - UNLOCK_TXNREGION(mgr); - - /* - * If the transaction aborted, we can remove it from its parent links. - * If it committed, then we need to leave it on, since the parent can - * still abort. - */ - if (txnp->parent != NULL && !is_commit) - TAILQ_REMOVE(&txnp->parent->kids, txnp, klinks); - - /* Free the space. */ - if (F_ISSET(txnp, TXN_MALLOC) && (txnp->parent == NULL || !is_commit)) { - LOCK_TXNTHREAD(mgr); - TAILQ_REMOVE(&mgr->txn_chain, txnp, links); - UNLOCK_TXNTHREAD(mgr); - - __os_free(txnp, sizeof(*txnp)); - } - - return (0); -} - - -/* - * __txn_undo -- - * Undo the transaction with id txnid. Returns 0 on success and - * errno on failure. - */ -static int -__txn_undo(txnp) - DB_TXN *txnp; -{ - DBT rdbt; - DB_LOG *logp; - DB_LSN key_lsn; - DB_TXNMGR *mgr; - int ret; - - mgr = txnp->mgrp; - logp = mgr->dbenv->lg_info; - if (logp == NULL) - return (0); - - /* - * This is the simplest way to code this, but if the mallocs during - * recovery turn out to be a performance issue, we can do the - * allocation here and use DB_DBT_USERMEM. - */ - memset(&rdbt, 0, sizeof(rdbt)); - if (F_ISSET(logp, DB_AM_THREAD)) - F_SET(&rdbt, DB_DBT_MALLOC); - - key_lsn = txnp->last_lsn; /* structure assignment */ - for (ret = 0; ret == 0 && !IS_ZERO_LSN(key_lsn);) { - /* - * The dispatch routine returns the lsn of the record - * before the current one in the key_lsn argument. - */ - if ((ret = log_get(logp, &key_lsn, &rdbt, DB_SET)) == 0) { - ret = - mgr->recover(logp, &rdbt, &key_lsn, TXN_UNDO, NULL); - if (F_ISSET(logp, DB_AM_THREAD) && rdbt.data != NULL) { - __os_free(rdbt.data, rdbt.size); - rdbt.data = NULL; - } - } - if (ret != 0) - return (ret); - } - - return (ret); -} - -/* - * Transaction checkpoint. - * If either kbytes or minutes is non-zero, then we only take the checkpoint - * more than "minutes" minutes have passed since the last checkpoint or if - * more than "kbytes" of log data have been written since the last checkpoint. - * When taking a checkpoint, find the oldest active transaction and figure out - * its first LSN. This is the lowest LSN we can checkpoint, since any record - * written after since that point may be involved in a transaction and may - * therefore need to be undone in the case of an abort. - */ -int -txn_checkpoint(mgr, kbytes, minutes) - const DB_TXNMGR *mgr; - u_int32_t kbytes, minutes; -{ - DB_LOG *dblp; - DB_LSN ckp_lsn, sync_lsn, last_ckp; - TXN_DETAIL *txnp; - time_t last_ckp_time, now; - u_int32_t kbytes_written; - int ret; - - TXN_PANIC_CHECK(mgr); - - /* - * Check if we need to run recovery. - */ - ZERO_LSN(ckp_lsn); - if (minutes != 0) { - (void)time(&now); - - LOCK_TXNREGION(mgr); - last_ckp_time = mgr->region->time_ckp; - UNLOCK_TXNREGION(mgr); - - if (now - last_ckp_time >= (time_t)(minutes * 60)) - goto do_ckp; - } - - if (kbytes != 0) { - dblp = mgr->dbenv->lg_info; - LOCK_LOGREGION(dblp); - kbytes_written = - dblp->lp->stat.st_wc_mbytes * 1024 + - dblp->lp->stat.st_wc_bytes / 1024; - ckp_lsn = dblp->lp->lsn; - UNLOCK_LOGREGION(dblp); - if (kbytes_written >= (u_int32_t)kbytes) - goto do_ckp; - } - - /* - * If we checked time and data and didn't go to checkpoint, - * we're done. - */ - if (minutes != 0 || kbytes != 0) - return (0); - -do_ckp: - if (IS_ZERO_LSN(ckp_lsn)) { - dblp = mgr->dbenv->lg_info; - LOCK_LOGREGION(dblp); - ckp_lsn = dblp->lp->lsn; - UNLOCK_LOGREGION(dblp); - } - - /* - * We have to find an LSN such that all transactions begun - * before that LSN are complete. - */ - LOCK_TXNREGION(mgr); - - if (!IS_ZERO_LSN(mgr->region->pending_ckp)) - ckp_lsn = mgr->region->pending_ckp; - else - for (txnp = - SH_TAILQ_FIRST(&mgr->region->active_txn, __txn_detail); - txnp != NULL; - txnp = SH_TAILQ_NEXT(txnp, links, __txn_detail)) { - - /* - * Look through the active transactions for the - * lowest begin lsn. - */ - if (!IS_ZERO_LSN(txnp->begin_lsn) && - log_compare(&txnp->begin_lsn, &ckp_lsn) < 0) - ckp_lsn = txnp->begin_lsn; - } - - mgr->region->pending_ckp = ckp_lsn; - UNLOCK_TXNREGION(mgr); - - /* - * memp_sync may change the lsn you pass it, so don't pass it - * the actual ckp_lsn, pass it a temp instead. - */ - sync_lsn = ckp_lsn; - if (mgr->dbenv->mp_info != NULL && - (ret = memp_sync(mgr->dbenv->mp_info, &sync_lsn)) != 0) { - /* - * ret == DB_INCOMPLETE means that there are still buffers to - * flush, the checkpoint is not complete. Wait and try again. - */ - if (ret > 0) - __db_err(mgr->dbenv, - "txn_checkpoint: system failure in memp_sync %s\n", - strerror(ret)); - return (ret); - } - if (mgr->dbenv->lg_info != NULL) { - LOCK_TXNREGION(mgr); - last_ckp = mgr->region->last_ckp; - ZERO_LSN(mgr->region->pending_ckp); - UNLOCK_TXNREGION(mgr); - - if ((ret = __txn_ckp_log(mgr->dbenv->lg_info, - NULL, &ckp_lsn, DB_CHECKPOINT, &ckp_lsn, &last_ckp)) != 0) { - __db_err(mgr->dbenv, - "txn_checkpoint: log failed at LSN [%ld %ld] %s\n", - (long)ckp_lsn.file, (long)ckp_lsn.offset, - strerror(ret)); - return (ret); - } - - LOCK_TXNREGION(mgr); - mgr->region->last_ckp = ckp_lsn; - (void)time(&mgr->region->time_ckp); - UNLOCK_TXNREGION(mgr); - } - return (0); -} - -/* - * __txn_validate_region -- - * Called at every interface to verify if the region has changed size, - * and if so, to remap the region in and reset the process' pointers. - */ -static int -__txn_validate_region(tp) - DB_TXNMGR *tp; -{ - int ret; - - if (tp->reginfo.size == tp->region->hdr.size) - return (0); - - /* Detach/reattach the region. */ - if ((ret = __db_rreattach(&tp->reginfo, tp->region->hdr.size)) != 0) - return (ret); - - /* Reset region information. */ - tp->region = tp->reginfo.addr; - tp->mem = &tp->region[1]; - - return (0); -} - -static int -__txn_grow_region(tp) - DB_TXNMGR *tp; -{ - size_t incr, oldsize; - u_int32_t mutex_offset, oldmax; - u_int8_t *curaddr; - int ret; - - oldmax = tp->region->maxtxns; - incr = oldmax * sizeof(DB_TXN); - mutex_offset = tp->mutexp != NULL ? - (u_int8_t *)tp->mutexp - (u_int8_t *)tp->region : 0; - - oldsize = tp->reginfo.size; - if ((ret = __db_rgrow(&tp->reginfo, oldsize + incr)) != 0) - return (ret); - tp->region = tp->reginfo.addr; - - /* Throw the new space on the free list. */ - curaddr = (u_int8_t *)tp->region + oldsize; - tp->mem = &tp->region[1]; - tp->mutexp = mutex_offset != 0 ? - (db_mutex_t *)((u_int8_t *)tp->region + mutex_offset) : NULL; - - *((size_t *)curaddr) = incr - sizeof(size_t); - curaddr += sizeof(size_t); - __db_shalloc_free(tp->mem, curaddr); - - tp->region->maxtxns = 2 * oldmax; - - return (0); -} - -int -txn_stat(mgr, statp, db_malloc) - DB_TXNMGR *mgr; - DB_TXN_STAT **statp; - void *(*db_malloc) __P((size_t)); -{ - DB_TXN_STAT *stats; - TXN_DETAIL *txnp; - size_t nbytes; - u_int32_t nactive, ndx; - int ret; - - TXN_PANIC_CHECK(mgr); - - LOCK_TXNREGION(mgr); - nactive = mgr->region->nbegins - - mgr->region->naborts - mgr->region->ncommits; - UNLOCK_TXNREGION(mgr); - - /* - * Allocate a bunch of extra active structures to handle any - * that have been created since we unlocked the region. - */ - nbytes = sizeof(DB_TXN_STAT) + sizeof(DB_TXN_ACTIVE) * (nactive + 200); - if ((ret = __os_malloc(nbytes, db_malloc, &stats)) != 0) - return (ret); - - LOCK_TXNREGION(mgr); - stats->st_last_txnid = mgr->region->last_txnid; - stats->st_last_ckp = mgr->region->last_ckp; - stats->st_maxtxns = mgr->region->maxtxns; - stats->st_naborts = mgr->region->naborts; - stats->st_nbegins = mgr->region->nbegins; - stats->st_ncommits = mgr->region->ncommits; - stats->st_pending_ckp = mgr->region->pending_ckp; - stats->st_time_ckp = mgr->region->time_ckp; - stats->st_nactive = stats->st_nbegins - - stats->st_naborts - stats->st_ncommits; - if (stats->st_nactive > nactive + 200) - stats->st_nactive = nactive + 200; - stats->st_txnarray = (DB_TXN_ACTIVE *)&stats[1]; - - ndx = 0; - for (txnp = SH_TAILQ_FIRST(&mgr->region->active_txn, __txn_detail); - txnp != NULL; - txnp = SH_TAILQ_NEXT(txnp, links, __txn_detail)) { - stats->st_txnarray[ndx].txnid = txnp->txnid; - stats->st_txnarray[ndx].lsn = txnp->begin_lsn; - ndx++; - - if (ndx >= stats->st_nactive) - break; - } - - stats->st_region_wait = mgr->region->hdr.lock.mutex_set_wait; - stats->st_region_nowait = mgr->region->hdr.lock.mutex_set_nowait; - stats->st_refcnt = mgr->region->hdr.refcnt; - stats->st_regsize = mgr->region->hdr.size; - - UNLOCK_TXNREGION(mgr); - *statp = stats; - return (0); -} - -static void -__txn_freekids(txnp) - DB_TXN *txnp; -{ - DB_TXNMGR *mgr; - TXN_DETAIL *tp; - DB_TXN *kids; - - mgr = txnp->mgrp; - - for (kids = TAILQ_FIRST(&txnp->kids); - kids != NULL; - kids = TAILQ_FIRST(&txnp->kids)) { - /* Free any children of this transaction. */ - __txn_freekids(kids); - - /* Free the transaction detail in the region. */ - LOCK_TXNREGION(mgr); - tp = (TXN_DETAIL *)((u_int8_t *)mgr->region + kids->off); - SH_TAILQ_REMOVE(&mgr->region->active_txn, - tp, links, __txn_detail); - - __db_shalloc_free(mgr->mem, tp); - UNLOCK_TXNREGION(mgr); - - /* Now remove from its parent. */ - TAILQ_REMOVE(&txnp->kids, kids, klinks); - if (F_ISSET(txnp, TXN_MALLOC)) { - LOCK_TXNTHREAD(mgr); - TAILQ_REMOVE(&mgr->txn_chain, kids, links); - UNLOCK_TXNTHREAD(mgr); - __os_free(kids, sizeof(*kids)); - } - } -} - -/* - * __txn_is_ancestor -- - * Determine if a transaction is an ancestor of another transaction. - * This is used during lock promotion when we do not have the per-process - * data structures that link parents together. Instead, we'll have to - * follow the links in the transaction region. - * - * PUBLIC: int __txn_is_ancestor __P((DB_TXNMGR *, size_t, size_t)); - */ -int -__txn_is_ancestor(mgr, hold_off, req_off) - DB_TXNMGR *mgr; - size_t hold_off, req_off; -{ - TXN_DETAIL *hold_tp, *req_tp; - - hold_tp = (TXN_DETAIL *)((u_int8_t *)mgr->region + hold_off); - req_tp = (TXN_DETAIL *)((u_int8_t *)mgr->region + req_off); - - while (req_tp->parent != 0) { - req_tp = - (TXN_DETAIL *)((u_int8_t *)mgr->region + req_tp->parent); - if (req_tp->txnid == hold_tp->txnid) - return (1); - } - - return (0); -} diff --git a/db2/txn/txn.src b/db2/txn/txn.src deleted file mode 100644 index c9614f6d6b..0000000000 --- a/db2/txn/txn.src +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - * - * @(#)txn.src 10.6 (Sleepycat) 1/3/99 - */ - -PREFIX txn - -/* - * This is the standard log operation for commit. - */ -BEGIN regop -ARG opcode u_int32_t lu -END - -/* - * This is the checkpoint record. It contains the lsn that the checkpoint - * guarantees and a pointer to the last checkpoint so we can walk backwards - * by checkpoint. - * - * ckp_lsn: - * The lsn in the log of the most recent point at which all begun - * transactions have been aborted. This is the point for which - * the checkpoint is relevant. - * last_ckp: - * The previous checkpoint. - */ -BEGIN ckp -POINTER ckp_lsn DB_LSN * lu -POINTER last_ckp DB_LSN * lu -END - -/* - * This is the standard log operation for prepare (since right now - * we only use prepare in an XA environment). - */ -BEGIN xa_regop -ARG opcode u_int32_t lu -DBT xid DBT s -ARG formatID int32_t ld -ARG gtrid u_int32_t u -ARG bqual u_int32_t u -POINTER begin_lsn DB_LSN * lu -END - -/* - * This is the log operation for a child commit. - */ -BEGIN child -ARG opcode u_int32_t lu -ARG parent u_int32_t lu -END diff --git a/db2/txn/txn_auto.c b/db2/txn/txn_auto.c deleted file mode 100644 index e6d431f089..0000000000 --- a/db2/txn/txn_auto.c +++ /dev/null @@ -1,621 +0,0 @@ -/* Do not edit: automatically built by dist/db_gen.sh. */ -#include "config.h" - -#ifndef NO_SYSTEM_INCLUDES -#include <ctype.h> -#include <errno.h> -#include <stddef.h> -#include <stdlib.h> -#include <string.h> -#endif - -#include "db_int.h" -#include "db_page.h" -#include "db_dispatch.h" -#include "txn.h" -#include "db_am.h" -/* - * PUBLIC: int __txn_regop_log - * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t, - * PUBLIC: u_int32_t)); - */ -int __txn_regop_log(logp, txnid, ret_lsnp, flags, - opcode) - DB_LOG *logp; - DB_TXN *txnid; - DB_LSN *ret_lsnp; - u_int32_t flags; - u_int32_t opcode; -{ - DBT logrec; - DB_LSN *lsnp, null_lsn; - u_int32_t rectype, txn_num; - int ret; - u_int8_t *bp; - - rectype = DB_txn_regop; - txn_num = txnid == NULL ? 0 : txnid->txnid; - if (txnid == NULL) { - ZERO_LSN(null_lsn); - lsnp = &null_lsn; - } else - lsnp = &txnid->last_lsn; - logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) - + sizeof(opcode); - if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0) - return (ret); - - bp = logrec.data; - memcpy(bp, &rectype, sizeof(rectype)); - bp += sizeof(rectype); - memcpy(bp, &txn_num, sizeof(txn_num)); - bp += sizeof(txn_num); - memcpy(bp, lsnp, sizeof(DB_LSN)); - bp += sizeof(DB_LSN); - memcpy(bp, &opcode, sizeof(opcode)); - bp += sizeof(opcode); -#ifdef DIAGNOSTIC - if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size) - fprintf(stderr, "Error in log record length"); -#endif - ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags); - if (txnid != NULL) - txnid->last_lsn = *ret_lsnp; - __os_free(logrec.data, 0); - return (ret); -} - -/* - * PUBLIC: int __txn_regop_print - * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); - */ -int -__txn_regop_print(notused1, dbtp, lsnp, notused2, notused3) - DB_LOG *notused1; - DBT *dbtp; - DB_LSN *lsnp; - int notused2; - void *notused3; -{ - __txn_regop_args *argp; - u_int32_t i; - u_int ch; - int ret; - - i = 0; - ch = 0; - notused1 = NULL; - notused2 = 0; - notused3 = NULL; - - if ((ret = __txn_regop_read(dbtp->data, &argp)) != 0) - return (ret); - printf("[%lu][%lu]txn_regop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", - (u_long)lsnp->file, - (u_long)lsnp->offset, - (u_long)argp->type, - (u_long)argp->txnid->txnid, - (u_long)argp->prev_lsn.file, - (u_long)argp->prev_lsn.offset); - printf("\topcode: %lu\n", (u_long)argp->opcode); - printf("\n"); - __os_free(argp, 0); - return (0); -} - -/* - * PUBLIC: int __txn_regop_read __P((void *, __txn_regop_args **)); - */ -int -__txn_regop_read(recbuf, argpp) - void *recbuf; - __txn_regop_args **argpp; -{ - __txn_regop_args *argp; - u_int8_t *bp; - int ret; - - ret = __os_malloc(sizeof(__txn_regop_args) + - sizeof(DB_TXN), NULL, &argp); - if (ret != 0) - return (ret); - argp->txnid = (DB_TXN *)&argp[1]; - bp = recbuf; - memcpy(&argp->type, bp, sizeof(argp->type)); - bp += sizeof(argp->type); - memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); - bp += sizeof(argp->txnid->txnid); - memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); - bp += sizeof(DB_LSN); - memcpy(&argp->opcode, bp, sizeof(argp->opcode)); - bp += sizeof(argp->opcode); - *argpp = argp; - return (0); -} - -/* - * PUBLIC: int __txn_ckp_log - * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t, - * PUBLIC: DB_LSN *, DB_LSN *)); - */ -int __txn_ckp_log(logp, txnid, ret_lsnp, flags, - ckp_lsn, last_ckp) - DB_LOG *logp; - DB_TXN *txnid; - DB_LSN *ret_lsnp; - u_int32_t flags; - DB_LSN * ckp_lsn; - DB_LSN * last_ckp; -{ - DBT logrec; - DB_LSN *lsnp, null_lsn; - u_int32_t rectype, txn_num; - int ret; - u_int8_t *bp; - - rectype = DB_txn_ckp; - txn_num = txnid == NULL ? 0 : txnid->txnid; - if (txnid == NULL) { - ZERO_LSN(null_lsn); - lsnp = &null_lsn; - } else - lsnp = &txnid->last_lsn; - logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) - + sizeof(*ckp_lsn) - + sizeof(*last_ckp); - if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0) - return (ret); - - bp = logrec.data; - memcpy(bp, &rectype, sizeof(rectype)); - bp += sizeof(rectype); - memcpy(bp, &txn_num, sizeof(txn_num)); - bp += sizeof(txn_num); - memcpy(bp, lsnp, sizeof(DB_LSN)); - bp += sizeof(DB_LSN); - if (ckp_lsn != NULL) - memcpy(bp, ckp_lsn, sizeof(*ckp_lsn)); - else - memset(bp, 0, sizeof(*ckp_lsn)); - bp += sizeof(*ckp_lsn); - if (last_ckp != NULL) - memcpy(bp, last_ckp, sizeof(*last_ckp)); - else - memset(bp, 0, sizeof(*last_ckp)); - bp += sizeof(*last_ckp); -#ifdef DIAGNOSTIC - if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size) - fprintf(stderr, "Error in log record length"); -#endif - ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags); - if (txnid != NULL) - txnid->last_lsn = *ret_lsnp; - __os_free(logrec.data, 0); - return (ret); -} - -/* - * PUBLIC: int __txn_ckp_print - * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); - */ -int -__txn_ckp_print(notused1, dbtp, lsnp, notused2, notused3) - DB_LOG *notused1; - DBT *dbtp; - DB_LSN *lsnp; - int notused2; - void *notused3; -{ - __txn_ckp_args *argp; - u_int32_t i; - u_int ch; - int ret; - - i = 0; - ch = 0; - notused1 = NULL; - notused2 = 0; - notused3 = NULL; - - if ((ret = __txn_ckp_read(dbtp->data, &argp)) != 0) - return (ret); - printf("[%lu][%lu]txn_ckp: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", - (u_long)lsnp->file, - (u_long)lsnp->offset, - (u_long)argp->type, - (u_long)argp->txnid->txnid, - (u_long)argp->prev_lsn.file, - (u_long)argp->prev_lsn.offset); - printf("\tckp_lsn: [%lu][%lu]\n", - (u_long)argp->ckp_lsn.file, (u_long)argp->ckp_lsn.offset); - printf("\tlast_ckp: [%lu][%lu]\n", - (u_long)argp->last_ckp.file, (u_long)argp->last_ckp.offset); - printf("\n"); - __os_free(argp, 0); - return (0); -} - -/* - * PUBLIC: int __txn_ckp_read __P((void *, __txn_ckp_args **)); - */ -int -__txn_ckp_read(recbuf, argpp) - void *recbuf; - __txn_ckp_args **argpp; -{ - __txn_ckp_args *argp; - u_int8_t *bp; - int ret; - - ret = __os_malloc(sizeof(__txn_ckp_args) + - sizeof(DB_TXN), NULL, &argp); - if (ret != 0) - return (ret); - argp->txnid = (DB_TXN *)&argp[1]; - bp = recbuf; - memcpy(&argp->type, bp, sizeof(argp->type)); - bp += sizeof(argp->type); - memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); - bp += sizeof(argp->txnid->txnid); - memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); - bp += sizeof(DB_LSN); - memcpy(&argp->ckp_lsn, bp, sizeof(argp->ckp_lsn)); - bp += sizeof(argp->ckp_lsn); - memcpy(&argp->last_ckp, bp, sizeof(argp->last_ckp)); - bp += sizeof(argp->last_ckp); - *argpp = argp; - return (0); -} - -/* - * PUBLIC: int __txn_xa_regop_log - * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t, - * PUBLIC: u_int32_t, const DBT *, int32_t, u_int32_t, - * PUBLIC: u_int32_t, DB_LSN *)); - */ -int __txn_xa_regop_log(logp, txnid, ret_lsnp, flags, - opcode, xid, formatID, gtrid, bqual, begin_lsn) - DB_LOG *logp; - DB_TXN *txnid; - DB_LSN *ret_lsnp; - u_int32_t flags; - u_int32_t opcode; - const DBT *xid; - int32_t formatID; - u_int32_t gtrid; - u_int32_t bqual; - DB_LSN * begin_lsn; -{ - DBT logrec; - DB_LSN *lsnp, null_lsn; - u_int32_t zero; - u_int32_t rectype, txn_num; - int ret; - u_int8_t *bp; - - rectype = DB_txn_xa_regop; - txn_num = txnid == NULL ? 0 : txnid->txnid; - if (txnid == NULL) { - ZERO_LSN(null_lsn); - lsnp = &null_lsn; - } else - lsnp = &txnid->last_lsn; - logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) - + sizeof(opcode) - + sizeof(u_int32_t) + (xid == NULL ? 0 : xid->size) - + sizeof(formatID) - + sizeof(gtrid) - + sizeof(bqual) - + sizeof(*begin_lsn); - if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0) - return (ret); - - bp = logrec.data; - memcpy(bp, &rectype, sizeof(rectype)); - bp += sizeof(rectype); - memcpy(bp, &txn_num, sizeof(txn_num)); - bp += sizeof(txn_num); - memcpy(bp, lsnp, sizeof(DB_LSN)); - bp += sizeof(DB_LSN); - memcpy(bp, &opcode, sizeof(opcode)); - bp += sizeof(opcode); - if (xid == NULL) { - zero = 0; - memcpy(bp, &zero, sizeof(u_int32_t)); - bp += sizeof(u_int32_t); - } else { - memcpy(bp, &xid->size, sizeof(xid->size)); - bp += sizeof(xid->size); - memcpy(bp, xid->data, xid->size); - bp += xid->size; - } - memcpy(bp, &formatID, sizeof(formatID)); - bp += sizeof(formatID); - memcpy(bp, >rid, sizeof(gtrid)); - bp += sizeof(gtrid); - memcpy(bp, &bqual, sizeof(bqual)); - bp += sizeof(bqual); - if (begin_lsn != NULL) - memcpy(bp, begin_lsn, sizeof(*begin_lsn)); - else - memset(bp, 0, sizeof(*begin_lsn)); - bp += sizeof(*begin_lsn); -#ifdef DIAGNOSTIC - if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size) - fprintf(stderr, "Error in log record length"); -#endif - ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags); - if (txnid != NULL) - txnid->last_lsn = *ret_lsnp; - __os_free(logrec.data, 0); - return (ret); -} - -/* - * PUBLIC: int __txn_xa_regop_print - * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); - */ -int -__txn_xa_regop_print(notused1, dbtp, lsnp, notused2, notused3) - DB_LOG *notused1; - DBT *dbtp; - DB_LSN *lsnp; - int notused2; - void *notused3; -{ - __txn_xa_regop_args *argp; - u_int32_t i; - u_int ch; - int ret; - - i = 0; - ch = 0; - notused1 = NULL; - notused2 = 0; - notused3 = NULL; - - if ((ret = __txn_xa_regop_read(dbtp->data, &argp)) != 0) - return (ret); - printf("[%lu][%lu]txn_xa_regop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", - (u_long)lsnp->file, - (u_long)lsnp->offset, - (u_long)argp->type, - (u_long)argp->txnid->txnid, - (u_long)argp->prev_lsn.file, - (u_long)argp->prev_lsn.offset); - printf("\topcode: %lu\n", (u_long)argp->opcode); - printf("\txid: "); - for (i = 0; i < argp->xid.size; i++) { - ch = ((u_int8_t *)argp->xid.data)[i]; - if (isprint(ch) || ch == 0xa) - putchar(ch); - else - printf("%#x ", ch); - } - printf("\n"); - printf("\tformatID: %ld\n", (long)argp->formatID); - printf("\tgtrid: %u\n", argp->gtrid); - printf("\tbqual: %u\n", argp->bqual); - printf("\tbegin_lsn: [%lu][%lu]\n", - (u_long)argp->begin_lsn.file, (u_long)argp->begin_lsn.offset); - printf("\n"); - __os_free(argp, 0); - return (0); -} - -/* - * PUBLIC: int __txn_xa_regop_read __P((void *, __txn_xa_regop_args **)); - */ -int -__txn_xa_regop_read(recbuf, argpp) - void *recbuf; - __txn_xa_regop_args **argpp; -{ - __txn_xa_regop_args *argp; - u_int8_t *bp; - int ret; - - ret = __os_malloc(sizeof(__txn_xa_regop_args) + - sizeof(DB_TXN), NULL, &argp); - if (ret != 0) - return (ret); - argp->txnid = (DB_TXN *)&argp[1]; - bp = recbuf; - memcpy(&argp->type, bp, sizeof(argp->type)); - bp += sizeof(argp->type); - memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); - bp += sizeof(argp->txnid->txnid); - memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); - bp += sizeof(DB_LSN); - memcpy(&argp->opcode, bp, sizeof(argp->opcode)); - bp += sizeof(argp->opcode); - memcpy(&argp->xid.size, bp, sizeof(u_int32_t)); - bp += sizeof(u_int32_t); - argp->xid.data = bp; - bp += argp->xid.size; - memcpy(&argp->formatID, bp, sizeof(argp->formatID)); - bp += sizeof(argp->formatID); - memcpy(&argp->gtrid, bp, sizeof(argp->gtrid)); - bp += sizeof(argp->gtrid); - memcpy(&argp->bqual, bp, sizeof(argp->bqual)); - bp += sizeof(argp->bqual); - memcpy(&argp->begin_lsn, bp, sizeof(argp->begin_lsn)); - bp += sizeof(argp->begin_lsn); - *argpp = argp; - return (0); -} - -/* - * PUBLIC: int __txn_child_log - * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t, - * PUBLIC: u_int32_t, u_int32_t)); - */ -int __txn_child_log(logp, txnid, ret_lsnp, flags, - opcode, parent) - DB_LOG *logp; - DB_TXN *txnid; - DB_LSN *ret_lsnp; - u_int32_t flags; - u_int32_t opcode; - u_int32_t parent; -{ - DBT logrec; - DB_LSN *lsnp, null_lsn; - u_int32_t rectype, txn_num; - int ret; - u_int8_t *bp; - - rectype = DB_txn_child; - txn_num = txnid == NULL ? 0 : txnid->txnid; - if (txnid == NULL) { - ZERO_LSN(null_lsn); - lsnp = &null_lsn; - } else - lsnp = &txnid->last_lsn; - logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) - + sizeof(opcode) - + sizeof(parent); - if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0) - return (ret); - - bp = logrec.data; - memcpy(bp, &rectype, sizeof(rectype)); - bp += sizeof(rectype); - memcpy(bp, &txn_num, sizeof(txn_num)); - bp += sizeof(txn_num); - memcpy(bp, lsnp, sizeof(DB_LSN)); - bp += sizeof(DB_LSN); - memcpy(bp, &opcode, sizeof(opcode)); - bp += sizeof(opcode); - memcpy(bp, &parent, sizeof(parent)); - bp += sizeof(parent); -#ifdef DIAGNOSTIC - if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size) - fprintf(stderr, "Error in log record length"); -#endif - ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags); - if (txnid != NULL) - txnid->last_lsn = *ret_lsnp; - __os_free(logrec.data, 0); - return (ret); -} - -/* - * PUBLIC: int __txn_child_print - * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); - */ -int -__txn_child_print(notused1, dbtp, lsnp, notused2, notused3) - DB_LOG *notused1; - DBT *dbtp; - DB_LSN *lsnp; - int notused2; - void *notused3; -{ - __txn_child_args *argp; - u_int32_t i; - u_int ch; - int ret; - - i = 0; - ch = 0; - notused1 = NULL; - notused2 = 0; - notused3 = NULL; - - if ((ret = __txn_child_read(dbtp->data, &argp)) != 0) - return (ret); - printf("[%lu][%lu]txn_child: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", - (u_long)lsnp->file, - (u_long)lsnp->offset, - (u_long)argp->type, - (u_long)argp->txnid->txnid, - (u_long)argp->prev_lsn.file, - (u_long)argp->prev_lsn.offset); - printf("\topcode: %lu\n", (u_long)argp->opcode); - printf("\tparent: %lu\n", (u_long)argp->parent); - printf("\n"); - __os_free(argp, 0); - return (0); -} - -/* - * PUBLIC: int __txn_child_read __P((void *, __txn_child_args **)); - */ -int -__txn_child_read(recbuf, argpp) - void *recbuf; - __txn_child_args **argpp; -{ - __txn_child_args *argp; - u_int8_t *bp; - int ret; - - ret = __os_malloc(sizeof(__txn_child_args) + - sizeof(DB_TXN), NULL, &argp); - if (ret != 0) - return (ret); - argp->txnid = (DB_TXN *)&argp[1]; - bp = recbuf; - memcpy(&argp->type, bp, sizeof(argp->type)); - bp += sizeof(argp->type); - memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); - bp += sizeof(argp->txnid->txnid); - memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); - bp += sizeof(DB_LSN); - memcpy(&argp->opcode, bp, sizeof(argp->opcode)); - bp += sizeof(argp->opcode); - memcpy(&argp->parent, bp, sizeof(argp->parent)); - bp += sizeof(argp->parent); - *argpp = argp; - return (0); -} - -/* - * PUBLIC: int __txn_init_print __P((DB_ENV *)); - */ -int -__txn_init_print(dbenv) - DB_ENV *dbenv; -{ - int ret; - - if ((ret = __db_add_recovery(dbenv, - __txn_regop_print, DB_txn_regop)) != 0) - return (ret); - if ((ret = __db_add_recovery(dbenv, - __txn_ckp_print, DB_txn_ckp)) != 0) - return (ret); - if ((ret = __db_add_recovery(dbenv, - __txn_xa_regop_print, DB_txn_xa_regop)) != 0) - return (ret); - if ((ret = __db_add_recovery(dbenv, - __txn_child_print, DB_txn_child)) != 0) - return (ret); - return (0); -} - -/* - * PUBLIC: int __txn_init_recover __P((DB_ENV *)); - */ -int -__txn_init_recover(dbenv) - DB_ENV *dbenv; -{ - int ret; - - if ((ret = __db_add_recovery(dbenv, - __txn_regop_recover, DB_txn_regop)) != 0) - return (ret); - if ((ret = __db_add_recovery(dbenv, - __txn_ckp_recover, DB_txn_ckp)) != 0) - return (ret); - if ((ret = __db_add_recovery(dbenv, - __txn_xa_regop_recover, DB_txn_xa_regop)) != 0) - return (ret); - if ((ret = __db_add_recovery(dbenv, - __txn_child_recover, DB_txn_child)) != 0) - return (ret); - return (0); -} - diff --git a/db2/txn/txn_rec.c b/db2/txn/txn_rec.c deleted file mode 100644 index f21a0f92c8..0000000000 --- a/db2/txn/txn_rec.c +++ /dev/null @@ -1,296 +0,0 @@ -/*- - * See the file LICENSE for redistribution information. - * - * Copyright (c) 1996, 1997, 1998 - * Sleepycat Software. All rights reserved. - */ -/* - * Copyright (c) 1996 - * The President and Fellows of Harvard University. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "config.h" - -#ifndef lint -static const char sccsid[] = "@(#)txn_rec.c 10.15 (Sleepycat) 1/3/99"; -#endif /* not lint */ - -#ifndef NO_SYSTEM_INCLUDES -#include <sys/types.h> - -#include <errno.h> -#endif - -#include "db_int.h" -#include "db_page.h" -#include "shqueue.h" -#include "txn.h" -#include "db_am.h" -#include "log.h" -#include "common_ext.h" - -static int __txn_restore_txn __P((DB_ENV *, DB_LSN *, __txn_xa_regop_args *)); - -#define IS_XA_TXN(R) (R->xid.size != 0) - -/* - * PUBLIC: int __txn_regop_recover - * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); - * - * These records are only ever written for commits. - */ -int -__txn_regop_recover(logp, dbtp, lsnp, redo, info) - DB_LOG *logp; - DBT *dbtp; - DB_LSN *lsnp; - int redo; - void *info; -{ - __txn_regop_args *argp; - int ret; - -#ifdef DEBUG_RECOVER - (void)__txn_regop_print(logp, dbtp, lsnp, redo, info); -#endif - COMPQUIET(redo, 0); - COMPQUIET(logp, NULL); - - if ((ret = __txn_regop_read(dbtp->data, &argp)) != 0) - return (ret); - - if (argp->opcode != TXN_COMMIT) - ret = EINVAL; - else - if (__db_txnlist_find(info, argp->txnid->txnid) == DB_NOTFOUND) - ret = __db_txnlist_add(info, argp->txnid->txnid); - - if (ret == 0) - *lsnp = argp->prev_lsn; - __os_free(argp, 0); - - return (ret); -} - -/* - * PUBLIC: int __txn_xa_regop_recover - * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); - * - * These records are only ever written for prepares. - */ -int -__txn_xa_regop_recover(logp, dbtp, lsnp, redo, info) - DB_LOG *logp; - DBT *dbtp; - DB_LSN *lsnp; - int redo; - void *info; -{ - __txn_xa_regop_args *argp; - int ret; - -#ifdef DEBUG_RECOVER - (void)__txn_xa_regop_print(logp, dbtp, lsnp, redo, info); -#endif - COMPQUIET(redo, 0); - COMPQUIET(logp, NULL); - - if ((ret = __txn_xa_regop_read(dbtp->data, &argp)) != 0) - return (ret); - - if (argp->opcode != TXN_PREPARE) - ret = EINVAL; - else { - /* - * Whether we are in XA or not, we need to call - * __db_txnlist_find so that we update the maxid. - * If this is an XA transaction, then we treat - * prepares like commits so that we roll forward to - * a point where we can handle commit/abort calls - * from the TMS. If this isn't XA, then a prepare - * is treated like a No-op; we only care about the - * commit. - */ - ret = __db_txnlist_find(info, argp->txnid->txnid); - if (IS_XA_TXN(argp) && ret == DB_NOTFOUND) { - /* - * This is an XA prepared, but not yet committed - * transaction. We need to add it to the - * transaction list, so that it gets rolled - * forward. We also have to add it to the region's - * internal state so it can be properly aborted - * or recovered. - */ - ret = __db_txnlist_add(info, argp->txnid->txnid); - if (ret == 0) - ret = __txn_restore_txn(logp->dbenv, - lsnp, argp); - } - } - - if (ret == 0) - *lsnp = argp->prev_lsn; - __os_free(argp, 0); - - return (ret); -} - -/* - * PUBLIC: int __txn_ckp_recover __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); - */ -int -__txn_ckp_recover(logp, dbtp, lsnp, redo, info) - DB_LOG *logp; - DBT *dbtp; - DB_LSN *lsnp; - int redo; - void *info; -{ - __txn_ckp_args *argp; - int ret; - -#ifdef DEBUG_RECOVER - __txn_ckp_print(logp, dbtp, lsnp, redo, info); -#endif - COMPQUIET(logp, NULL); - - if ((ret = __txn_ckp_read(dbtp->data, &argp)) != 0) - return (ret); - - /* - * Check for 'restart' checkpoint record. This occurs when the - * checkpoint lsn is equal to the lsn of the checkpoint record - * and means that we could set the transaction ID back to 1, so - * that we don't exhaust the transaction ID name space. - */ - if (argp->ckp_lsn.file == lsnp->file && - argp->ckp_lsn.offset == lsnp->offset) - __db_txnlist_gen(info, redo ? -1 : 1); - - *lsnp = argp->last_ckp; - __os_free(argp, 0); - return (DB_TXN_CKP); -} - -/* - * __txn_child_recover - * Recover a commit record for a child transaction. - * - * PUBLIC: int __txn_child_recover - * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); - */ -int -__txn_child_recover(logp, dbtp, lsnp, redo, info) - DB_LOG *logp; - DBT *dbtp; - DB_LSN *lsnp; - int redo; - void *info; -{ - __txn_child_args *argp; - int ret; - -#ifdef DEBUG_RECOVER - (void)__txn_child_print(logp, dbtp, lsnp, redo, info); -#endif - COMPQUIET(redo, 0); - COMPQUIET(logp, NULL); - - if ((ret = __txn_child_read(dbtp->data, &argp)) != 0) - return (ret); - - /* - * We count the child as committed only if its parent committed. - * So, if we are not yet in the transaction list, but our parent - * is, then we should go ahead and commit. - */ - if (argp->opcode != TXN_COMMIT) - ret = EINVAL; - else - if (__db_txnlist_find(info, argp->parent) == 0 && - __db_txnlist_find(info, argp->txnid->txnid) == DB_NOTFOUND) - ret = __db_txnlist_add(info, argp->txnid->txnid); - - if (ret == 0) - *lsnp = argp->prev_lsn; - __os_free(argp, 0); - - return (ret); -} - -/* - * __txn_restore_txn -- - * Using only during XA recovery. If we find any transactions that are - * prepared, but not yet committed, then we need to restore the transaction's - * state into the shared region, because the TM is going to issue a txn_abort - * or txn_commit and we need to respond correctly. - * - * lsnp is the LSN of the returned LSN - * argp is the perpare record (in an appropriate structure) - */ -static int -__txn_restore_txn(dbenv, lsnp, argp) - DB_ENV *dbenv; - DB_LSN *lsnp; - __txn_xa_regop_args *argp; -{ - DB_TXNMGR *mgr; - TXN_DETAIL *td; - int ret; - - if (argp->xid.size == 0) - return(0); - - mgr = dbenv->tx_info; - LOCK_TXNREGION(mgr); - - /* Allocate a new transaction detail structure. */ - if ((ret = __db_shalloc(mgr->mem, sizeof(TXN_DETAIL), 0, &td)) != 0) - return (ret); - - /* Place transaction on active transaction list. */ - SH_TAILQ_INSERT_HEAD(&mgr->region->active_txn, td, links, __txn_detail); - - td->txnid = argp->txnid->txnid; - td->begin_lsn = argp->begin_lsn; - td->last_lsn = *lsnp; - td->last_lock = 0; - td->parent = 0; - td->status = TXN_PREPARED; - td->xa_status = TXN_XA_PREPARED; - memcpy(td->xid, argp->xid.data, argp->xid.size); - td->bqual = argp->bqual; - td->gtrid = argp->gtrid; - td->format = argp->formatID; - - UNLOCK_TXNREGION(mgr); - return (0); -} |