2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2005-2009 Oracle. All rights reserved.
12 #include "dbinc/txn.h"
16 * Check for transactions started by dead threads of control.
18 * PUBLIC: int __txn_failchk __P((ENV *));
31 char buf[DB_THREADID_STRLEN];
36 region = mgr->reginfo.primary;
38 retry: TXN_SYSTEM_LOCK(env);
40 SH_TAILQ_FOREACH(td, ®ion->active_txn, links, __txn_detail) {
42 * If this is a child transaction, skip it.
43 * The parent will take care of it.
45 if (td->parent != INVALID_ROFF)
48 * If the txn is prepared, then it does not matter
49 * what the state of the thread is.
51 if (td->status == TXN_PREPARED)
54 /* If the thread is still alive, it's not a problem. */
55 if (dbenv->is_alive(dbenv, td->pid, td->tid, 0))
58 if (F_ISSET(td, TXN_DTL_INMEMORY)) {
59 TXN_SYSTEM_UNLOCK(env);
60 return (__db_failed(env,
61 "Transaction has in memory logs",
65 /* Abort the transaction. */
66 TXN_SYSTEM_UNLOCK(env);
67 if ((ret = __os_calloc(env, 1, sizeof(DB_TXN), &txn)) != 0)
69 if ((ret = __txn_continue(env, txn, td)) != 0)
71 F_SET(txn, TXN_MALLOC);
72 SH_TAILQ_FOREACH(ktd, &td->kids, klinks, __txn_detail) {
73 if (F_ISSET(ktd, TXN_DTL_INMEMORY))
74 return (__db_failed(env,
75 "Transaction has in memory logs",
78 __os_calloc(env, 1, sizeof(DB_TXN), &ktxn)) != 0)
80 if ((ret = __txn_continue(env, ktxn, ktd)) != 0)
82 F_SET(ktxn, TXN_MALLOC);
84 TAILQ_INSERT_HEAD(&txn->kids, txn, klinks);
86 TAILQ_INSERT_TAIL(&mgr->txn_chain, txn, links);
89 (void)dbenv->thread_id_string(dbenv, pid, tid, buf);
91 "Aborting txn %#lx: %s", (u_long)txn->txnid, buf);
92 if ((ret = __txn_abort(txn)) != 0)
93 return (__db_failed(env,
94 "Transaction abort failed", pid, tid));
98 TXN_SYSTEM_UNLOCK(env);