/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1998
* Sleepycat Software. All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* XXX Remove the global transaction and hang it off the environment. */
#include "config.h"
#ifndef lint
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#endif
#include "db_int.h"
#include "db_page.h"
#include "shqueue.h"
#include "log.h"
#include "txn.h"
#include "db_auto.h"
#include "db_ext.h"
#include "db_dispatch.h"
static int __db_xa_close __P((char *, int, long));
static int __db_xa_complete __P((int *, int *, int, long));
static int __db_xa_open __P((char *, int, long));
/*
* Possible flag values:
* Dynamic registration 0 => no dynamic registration
* TMREGISTER => dynamic registration
* Asynchronous operation 0 => no support for asynchrony
* TMUSEASYNC => async support
* Migration support 0 => migration of transactions across
* threads is possible
* TMNOMIGRATE => no migration across threads
*/
"Berkeley DB", /* name[RMNAMESZ] */
TMNOMIGRATE, /* flags */
0, /* version */
__db_xa_open, /* xa_open_entry */
__db_xa_close, /* xa_close_entry */
__db_xa_start, /* xa_start_entry */
__db_xa_end, /* xa_end_entry */
__db_xa_rollback, /* xa_rollback_entry */
__db_xa_prepare, /* xa_prepare_entry */
__db_xa_commit, /* xa_commit_entry */
__db_xa_recover, /* xa_recover_entry */
__db_xa_forget, /* xa_forget_entry */
__db_xa_complete /* xa_complete_entry */
};
/*
* __db_xa_open --
* The open call in the XA protocol. The rmid field is an id number
* that the TM assigned us and will pass us on every xa call. We need to
* map that rmid number into a dbenv structure that we create during
* initialization. Since this id number is thread specific, we do not
* need to store it in shared memory. The file xa_map.c implements all
* such xa->db mappings.
* The xa_info field is instance specific information. We require
* that the value of DB_HOME be passed in xa_info. Since xa_info is the
* only thing that we get to pass to db_appinit, any config information
* will have to be done via a config file instead of via the db_appinit
* call.
*/
static int
char *xa_info;
int rmid;
long flags;
{
return (XAER_ASYNC);
return (XAER_INVAL);
/* Verify if we already have this environment open. */
return (XA_OK);
/*
* Since we cannot tell whether the environment is OK or not,
* we can't actually do the db_appinit in xa_open. Instead,
* we save the mapping between the rmid and the xa_info. If
* we next get a call to __xa_recover, we do the db_appinit
* with DB_RECOVER set. If we get any other call, then we
* do the db_appinit.
*/
}
/*
* __db_xa_close --
* The close call of the XA protocol. The only trickiness here
* is that if there are any active transactions, we must fail. It is
* *not* an error to call close on an environment that has already been
* closed (I am interpreting that to mean it's OK to call close on an
* environment that has never been opened).
*/
static int
char *xa_info;
int rmid;
long flags;
{
return (XAER_ASYNC);
return (XAER_INVAL);
/* If the environment is closed, then we're done. */
return (XA_OK);
/* Check if there are any pending transactions. */
return (XAER_PROTO);
/* Now, destroy the mapping and close the environment. */
}
/*
* __db_xa_start --
* Begin a transaction for the current resource manager.
*/
static int
int rmid;
long flags;
{
int is_known;
return (XAER_INVAL);
return (XAER_INVAL);
return (XAER_ASYNC);
return (XAER_PROTO);
return (XAER_DUPID);
return (XAER_NOTA);
/*
* This can't block, so we can ignore TMNOWAIT.
*
* Other error conditions: RMERR, RMFAIL, OUTSIDE, PROTO, RB*
*/
if (is_known) {
return (XAER_PROTO);
return (XA_RBDEADLOCK);
return (XA_RBOTHER);
/* Now, fill in the global transaction structure. */
} else {
return (XAER_RMERR);
td = (TXN_DETAIL *)
}
return (XA_OK);
}
/*
* __db_xa_end --
* Disassociate the current transaction from the current process.
*/
static int
int rmid;
long flags;
{
return (XAER_INVAL);
return (XAER_PROTO);
return (XAER_NOTA);
return (XAER_PROTO);
return (XA_RBDEADLOCK);
return (XA_RBOTHER);
return (XAER_PROTO);
/* Update the shared memory last_lsn field */
/*
* status in the shared region; it would have to be process local.
*/
else
return (XA_OK);
}
/*
* __db_xa_prepare --
* Sync the log to disk so we can guarantee recoverability.
*/
static int
int rmid;
long flags;
{
return (XAER_ASYNC);
return (XAER_INVAL);
/*
* We need to know if we've ever called prepare on this.
* As part of the prepare, we set the xa_status field to
* reflect that fact that prepare has been called, and if
* it's ever called again, it's an error.
*/
return (XAER_PROTO);
return (XAER_NOTA);
return (XA_RBDEADLOCK);
return (XAER_PROTO);
/* Now, fill in the global transaction structure. */
return (XAER_RMERR);
/* No fatal value that would require an XAER_RMFAIL. */
return (XA_OK);
}
/*
* __db_xa_commit --
* Commit the transaction
*/
static int
int rmid;
long flags;
{
return (XAER_ASYNC);
return (XAER_INVAL);
/*
* We need to know if we've ever called prepare on this.
* We can verify this by examining the xa_status field.
*/
return (XAER_PROTO);
return (XAER_NOTA);
return (XA_RBDEADLOCK);
return (XA_RBOTHER);
if (LF_ISSET(TMONEPHASE) &&
return (XAER_PROTO);
return (XAER_PROTO);
/* Now, fill in the global transaction structure. */
return (XAER_RMERR);
/* No fatal value that would require an XAER_RMFAIL. */
return (XA_OK);
}
/*
* __db_xa_recover --
* Returns a list of prepared and heuristically completed transactions.
*
* The return value is the number of xids placed into the xid array (less
* than or equal to the count parameter). The flags are going to indicate
* whether we are starting a scan or continuing one.
*/
static int
int rmid;
{
char *dbhome;
ret = 0;
/*
* If we are starting a scan, then we need to open the environment
* and run recovery. This recovery puts us in a state where we can
* either commit or abort any transactions that were prepared but not
* yet committed. Once we've done that, we need to figure out where
* to begin checking for such transactions. If we are not starting
* a scan, then the environment had better have already been recovered
* and 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.
*/
if (LF_ISSET(TMSTARTRSCAN)) {
/* If the environment is open, we have a problem. */
return (XAER_PROTO);
return (XAER_RMERR);
goto err1;
goto err1;
goto err2;
/* Now figure out from where to begin scan. */
/*
* If there were no log files, then we have no
* transactions to return, so we simply return 0.
*/
return (0);
}
goto err3;
} else {
/* We had better already know about this rmid. */
return (XAER_PROTO);
/*
* If we are not starting a scan, the log cursor had
* better be set.
*/
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.
*/
/*
* 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.
*/
continue;
sizeof(txnid));
switch (rectype) {
case DB_txn_regop:
if (err == DB_NOTFOUND)
err = 0;
break;
case DB_txn_xa_regop:
/*
* This transaction is commited, so we needn't read
* the record and do anything.
*/
if (err == 0)
break;
if ((err =
ret = XAER_RMERR;
goto out;
}
ret++;
xidp++;
goto done;
break;
}
}
goto out;
}
return (ret);
return (XAER_RMERR);
}
/*
* __db_xa_rollback
* Abort an XA transaction.
*/
static int
int rmid;
long flags;
{
return (XAER_ASYNC);
return (XAER_INVAL);
return (XAER_PROTO);
return (XAER_NOTA);
return (XA_RBDEADLOCK);
return (XA_RBOTHER);
if (LF_ISSET(TMONEPHASE) &&
return (XAER_PROTO);
/* Now, fill in the global transaction structure. */
return (XAER_RMERR);
/* No fatal value that would require an XAER_RMFAIL. */
return (XA_OK);
}
/*
* __db_xa_forget --
* Forget about an XID for a transaction that was heuristically
* completed. Since we do not heuristically complete anything, I
* don't think we have to do anything here, but we should make sure
* that we reclaim the slots in the txnid table.
*/
static int
int rmid;
long flags;
{
return (XAER_ASYNC);
return (XAER_INVAL);
return (XAER_PROTO);
/*
* If mapping is gone, then we're done.
*/
return (XA_OK);
/* No fatal value that would require an XAER_RMFAIL. */
return (XA_OK);
}
/*
* __db_xa_complete --
* Used to wait for asynchronous operations to complete. Since we're
* not doing asynch, this is an invalid operation.
*/
static int
long flags;
{
return (XAER_INVAL);
}
/*
* __xa_txn_init --
* Fill in the fields of the local transaction structure given
* the detail transaction structure.
*/
static void
TXN_DETAIL *td;
{
}
/*
* __xa_txn_end --
* Invalidate a transaction structure that was generated by xa_txn_init.
*/
static void
{
}