summaryrefslogtreecommitdiff
path: root/bdb/xa
diff options
context:
space:
mode:
Diffstat (limited to 'bdb/xa')
-rw-r--r--bdb/xa/xa.c184
-rw-r--r--bdb/xa/xa_db.c28
-rw-r--r--bdb/xa/xa_map.c30
3 files changed, 49 insertions, 193 deletions
diff --git a/bdb/xa/xa.c b/bdb/xa/xa.c
index b13a6d503b3..6667d14c2bf 100644
--- a/bdb/xa/xa.c
+++ b/bdb/xa/xa.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1998, 1999, 2000
+ * Copyright (c) 1998-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: xa.c,v 11.10 2000/12/14 07:39:14 ubell Exp $";
+static const char revid[] = "$Id: xa.c,v 11.23 2002/08/29 14:22:25 margo Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -19,11 +19,7 @@ static const char revid[] = "$Id: xa.c,v 11.10 2000/12/14 07:39:14 ubell Exp $";
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "log.h"
-#include "txn.h"
-#include "db_am.h"
-#include "db_dispatch.h"
+#include "dbinc/txn.h"
static int __db_xa_close __P((char *, int, long));
static int __db_xa_commit __P((XID *, int, long));
@@ -35,8 +31,7 @@ static int __db_xa_prepare __P((XID *, int, long));
static int __db_xa_recover __P((XID *, long, int, long));
static int __db_xa_rollback __P((XID *, int, long));
static int __db_xa_start __P((XID *, int, long));
-static void __xa_txn_end __P((DB_ENV *));
-static void __xa_txn_init __P((DB_ENV *, TXN_DETAIL *, size_t));
+static void __xa_txn_end __P((DB_TXN *));
/*
* Possible flag values:
@@ -158,7 +153,7 @@ __db_xa_close(xa_info, rmid, flags)
/* Discard space held for the current transaction. */
if (env->xa_txn != NULL)
- __os_free(env->xa_txn, sizeof(DB_TXN));
+ __os_free(env, env->xa_txn);
/* Close the environment. */
if ((t_ret = env->close(env, 0)) != 0 && ret == 0)
@@ -220,7 +215,7 @@ __db_xa_start(xid, rmid, flags)
return (XA_RBOTHER);
/* Now, fill in the global transaction structure. */
- __xa_txn_init(env, td, off);
+ __txn_continue(env, env->xa_txn, td, off);
td->xa_status = TXN_XA_STARTED;
} else {
if (__txn_xa_begin(env, env->xa_txn) != 0)
@@ -327,15 +322,15 @@ __db_xa_prepare(xid, rmid, flags)
return (XAER_PROTO);
/* Now, fill in the global transaction structure. */
- __xa_txn_init(env, td, off);
+ __txn_continue(env, env->xa_txn, td, off);
- if (txn_prepare(env->xa_txn) != 0)
+ if (env->xa_txn->prepare(env->xa_txn, (u_int8_t *)xid->data) != 0)
return (XAER_RMERR);
td->xa_status = TXN_XA_PREPARED;
/* No fatal value that would require an XAER_RMFAIL. */
- __xa_txn_end(env);
+ __xa_txn_end(env->xa_txn);
return (XA_OK);
}
@@ -385,13 +380,13 @@ __db_xa_commit(xid, rmid, flags)
return (XAER_PROTO);
/* Now, fill in the global transaction structure. */
- __xa_txn_init(env, td, off);
+ __txn_continue(env, env->xa_txn, td, off);
- if (txn_commit(env->xa_txn, 0) != 0)
+ if (env->xa_txn->commit(env->xa_txn, 0) != 0)
return (XAER_RMERR);
/* No fatal value that would require an XAER_RMFAIL. */
- __xa_txn_end(env);
+ __xa_txn_end(env->xa_txn);
return (XA_OK);
}
@@ -409,118 +404,26 @@ __db_xa_recover(xids, count, rmid, flags)
long count, flags;
int rmid;
{
- __txn_xa_regop_args *argp;
- DBT data;
DB_ENV *env;
- DB_LOG *log;
- XID *xidp;
- int err, ret;
- u_int32_t rectype, txnid;
-
- ret = 0;
- xidp = xids;
+ u_int32_t newflags;
+ long rval;
/* If the environment is closed, then we're done. */
if (__db_rmid_to_env(rmid, &env) != 0)
return (XAER_PROTO);
- /*
- * If we are starting a scan, then we need to figure out where
- * to begin. If we are not starting a scan, we'll start from
- * wherever the log cursor is. Since XA apps cannot be threaded,
- * we don't have to worry about someone else having moved it.
- */
- log = env->lg_handle;
- if (LF_ISSET(TMSTARTRSCAN)) {
- if ((err = __log_findckp(env, &log->xa_first)) == DB_NOTFOUND) {
- /*
- * If there were no log files, then we have no
- * transactions to return, so we simply return 0.
- */
- return (0);
- }
- if ((err = __db_txnlist_init(env, &log->xa_info)) != 0)
- return (XAER_RMERR);
- } else {
- /*
- * If we are not starting a scan, the log cursor had
- * better be set.
- */
- if (IS_ZERO_LSN(log->xa_lsn))
- return (XAER_PROTO);
- }
-
- /*
- * At this point log->xa_first contains the point in the log
- * to which we need to roll back. If we are starting a scan,
- * we'll start at the last record; if we're continuing a scan,
- * we'll have to start at log->xa_lsn.
- */
-
- memset(&data, 0, sizeof(data));
- for (err = log_get(env, &log->xa_lsn, &data,
- LF_ISSET(TMSTARTRSCAN) ? DB_LAST : DB_SET);
- err == 0 && log_compare(&log->xa_lsn, &log->xa_first) > 0;
- err = log_get(env, &log->xa_lsn, &data, DB_PREV)) {
- memcpy(&rectype, data.data, sizeof(rectype));
-
- /*
- * The only record type we care about is an DB_txn_xa_regop.
- * If it's a commit, we have to add it to a txnlist. If it's
- * a prepare, and we don't have a commit, then we return it.
- * We are redoing some of what's in the xa_regop_recovery
- * code, but we have to do it here so we can get at the xid
- * in the record.
- */
- if (rectype != DB_txn_xa_regop && rectype != DB_txn_regop)
- continue;
-
- memcpy(&txnid, (u_int8_t *)data.data + sizeof(rectype),
- sizeof(txnid));
- err = __db_txnlist_find(log->xa_info, txnid);
- switch (rectype) {
- case DB_txn_regop:
- if (err == DB_NOTFOUND)
- __db_txnlist_add(env, log->xa_info, txnid, 0);
- err = 0;
- break;
- case DB_txn_xa_regop:
- /*
- * This transaction is committed, so we needn't read
- * the record and do anything.
- */
- if (err == 0)
- break;
- if ((err =
- __txn_xa_regop_read(env, data.data, &argp)) != 0) {
- ret = XAER_RMERR;
- goto out;
- }
-
- xidp->formatID = argp->formatID;
- xidp->gtrid_length = argp->gtrid;
- xidp->bqual_length = argp->bqual;
- memcpy(xidp->data, argp->xid.data, argp->xid.size);
- ret++;
- xidp++;
- __os_free(argp, sizeof(*argp));
- if (ret == count)
- goto done;
- break;
- }
- }
-
- if (err != 0 && err != DB_NOTFOUND)
- goto out;
-
-done: if (LF_ISSET(TMENDRSCAN)) {
- ZERO_LSN(log->xa_lsn);
- ZERO_LSN(log->xa_first);
+ if (LF_ISSET(TMSTARTRSCAN))
+ newflags = DB_FIRST;
+ else if (LF_ISSET(TMENDRSCAN))
+ newflags = DB_LAST;
+ else
+ newflags = DB_NEXT;
-out: __db_txnlist_end(env, log->xa_info);
- log->xa_info = NULL;
- }
- return (ret);
+ rval = 0;
+ if (__txn_get_prepared(env, xids, NULL, count, &rval, newflags) != 0)
+ return (XAER_RMERR);
+ else
+ return (rval);
}
/*
@@ -560,12 +463,12 @@ __db_xa_rollback(xid, rmid, flags)
return (XAER_PROTO);
/* Now, fill in the global transaction structure. */
- __xa_txn_init(env, td, off);
- if (txn_abort(env->xa_txn) != 0)
+ __txn_continue(env, env->xa_txn, td, off);
+ if (env->xa_txn->abort(env->xa_txn) != 0)
return (XAER_RMERR);
/* No fatal value that would require an XAER_RMFAIL. */
- __xa_txn_end(env);
+ __xa_txn_end(env->xa_txn);
return (XA_OK);
}
@@ -624,38 +527,13 @@ __db_xa_complete(handle, retval, rmid, flags)
}
/*
- * __xa_txn_init --
- * Fill in the fields of the local transaction structure given
- * the detail transaction structure.
- */
-static void
-__xa_txn_init(env, td, off)
- DB_ENV *env;
- TXN_DETAIL *td;
- size_t off;
-{
- DB_TXN *txn;
-
- txn = env->xa_txn;
- txn->mgrp = env->tx_handle;
- txn->parent = NULL;
- txn->last_lsn = td->last_lsn;
- txn->txnid = td->txnid;
- txn->off = off;
- txn->flags = 0;
-}
-
-/*
* __xa_txn_end --
- * Invalidate a transaction structure that was generated by xa_txn_init.
+ * Invalidate a transaction structure that was generated by __txn_continue.
*/
static void
-__xa_txn_end(env)
- DB_ENV *env;
-{
+__xa_txn_end(txn)
DB_TXN *txn;
-
- txn = env->xa_txn;
+{
if (txn != NULL)
txn->txnid = TXN_INVALID;
}
diff --git a/bdb/xa/xa_db.c b/bdb/xa/xa_db.c
index ba3dbfeddbb..b84bb1c9fa9 100644
--- a/bdb/xa/xa_db.c
+++ b/bdb/xa/xa_db.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1998, 1999, 2000
+ * Copyright (c) 1998-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: xa_db.c,v 11.9 2000/09/06 18:57:59 ubell Exp $";
+static const char revid[] = "$Id: xa_db.c,v 11.21 2002/08/29 14:22:25 margo Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -16,15 +16,14 @@ static const char revid[] = "$Id: xa_db.c,v 11.9 2000/09/06 18:57:59 ubell Exp $
#endif
#include "db_int.h"
-#include "xa.h"
-#include "xa_ext.h"
-#include "txn.h"
+#include "dbinc/xa.h"
+#include "dbinc/txn.h"
static int __xa_close __P((DB *, u_int32_t));
static int __xa_cursor __P((DB *, DB_TXN *, DBC **, u_int32_t));
static int __xa_del __P((DB *, DB_TXN *, DBT *, u_int32_t));
static int __xa_get __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
-static int __xa_open __P((DB *,
+static int __xa_open __P((DB *, DB_TXN *,
const char *, const char *, DBTYPE, u_int32_t, int));
static int __xa_put __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
@@ -33,7 +32,7 @@ typedef struct __xa_methods {
int (*cursor) __P((DB *, DB_TXN *, DBC **, u_int32_t));
int (*del) __P((DB *, DB_TXN *, DBT *, u_int32_t));
int (*get) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
- int (*open) __P((DB *,
+ int (*open) __P((DB *, DB_TXN *,
const char *, const char *, DBTYPE, u_int32_t, int));
int (*put) __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
} XA_METHODS;
@@ -73,8 +72,9 @@ __db_xa_create(dbp)
*/
static int
-__xa_open(dbp, name, subdb, type, flags, mode)
+__xa_open(dbp, txn, name, subdb, type, flags, mode)
DB *dbp;
+ DB_TXN *txn;
const char *name, *subdb;
DBTYPE type;
u_int32_t flags;
@@ -85,7 +85,7 @@ __xa_open(dbp, name, subdb, type, flags, mode)
xam = (XA_METHODS *)dbp->xa_internal;
- if ((ret = xam->open(dbp, name, subdb, type, flags, mode)) != 0)
+ if ((ret = xam->open(dbp, txn, name, subdb, type, flags, mode)) != 0)
return (ret);
xam->cursor = dbp->cursor;
@@ -109,7 +109,7 @@ __xa_cursor(dbp, txn, dbcp, flags)
{
DB_TXN *t;
- t = txn != NULL && txn == dbp->open_txn ? txn : dbp->dbenv->xa_txn;
+ t = txn != NULL ? txn : dbp->dbenv->xa_txn;
if (t->txnid == TXN_INVALID)
t = NULL;
@@ -125,7 +125,7 @@ __xa_del(dbp, txn, key, flags)
{
DB_TXN *t;
- t = txn != NULL && txn == dbp->open_txn ? txn : dbp->dbenv->xa_txn;
+ t = txn != NULL ? txn : dbp->dbenv->xa_txn;
if (t->txnid == TXN_INVALID)
t = NULL;
@@ -141,7 +141,7 @@ __xa_close(dbp, flags)
real_close = ((XA_METHODS *)dbp->xa_internal)->close;
- __os_free(dbp->xa_internal, sizeof(XA_METHODS));
+ __os_free(dbp->dbenv, dbp->xa_internal);
dbp->xa_internal = NULL;
return (real_close(dbp, flags));
@@ -156,7 +156,7 @@ __xa_get(dbp, txn, key, data, flags)
{
DB_TXN *t;
- t = txn != NULL && txn == dbp->open_txn ? txn : dbp->dbenv->xa_txn;
+ t = txn != NULL ? txn : dbp->dbenv->xa_txn;
if (t->txnid == TXN_INVALID)
t = NULL;
@@ -173,7 +173,7 @@ __xa_put(dbp, txn, key, data, flags)
{
DB_TXN *t;
- t = txn != NULL && txn == dbp->open_txn ? txn : dbp->dbenv->xa_txn;
+ t = txn != NULL ? txn : dbp->dbenv->xa_txn;
if (t->txnid == TXN_INVALID)
t = NULL;
diff --git a/bdb/xa/xa_map.c b/bdb/xa/xa_map.c
index 1af268477db..42fa4b20ed2 100644
--- a/bdb/xa/xa_map.c
+++ b/bdb/xa/xa_map.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 1997, 1998, 1999, 2000
+ * Copyright (c) 1996-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: xa_map.c,v 11.5 2000/11/30 00:58:46 ubell Exp $";
+static const char revid[] = "$Id: xa_map.c,v 11.19 2002/09/03 14:58:27 sue Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -18,7 +18,7 @@ static const char revid[] = "$Id: xa_map.c,v 11.5 2000/11/30 00:58:46 ubell Exp
#endif
#include "db_int.h"
-#include "txn.h"
+#include "dbinc/txn.h"
/*
* This file contains all the mapping information that we need to support
@@ -72,31 +72,9 @@ __db_xid_to_txn(dbenv, xid, offp)
XID *xid;
size_t *offp;
{
- DB_TXNMGR *mgr;
- DB_TXNREGION *tmr;
struct __txn_detail *td;
- mgr = dbenv->tx_handle;
- tmr = mgr->reginfo.primary;
-
- /*
- * Search the internal active transaction table to find the
- * matching xid. If this is a performance hit, then we
- * can create a hash table, but I doubt it's worth it.
- */
- R_LOCK(dbenv, &mgr->reginfo);
- for (td = SH_TAILQ_FIRST(&tmr->active_txn, __txn_detail);
- td != NULL;
- td = SH_TAILQ_NEXT(td, links, __txn_detail))
- if (memcmp(xid->data, td->xid, XIDDATASIZE) == 0)
- break;
- R_UNLOCK(dbenv, &mgr->reginfo);
-
- if (td == NULL)
- return (EINVAL);
-
- *offp = R_OFFSET(&mgr->reginfo, td);
- return (0);
+ return (__txn_map_gid(dbenv, (u_int8_t *)xid->data, &td, offp));
}
/*