Search in sources :

Example 1 with GlobalTransactionId

use of org.apache.derby.iapi.store.raw.GlobalTransactionId in project derby by apache.

the class TransactionTable method getMostRecentPreparedRecoveredXact.

/**
 *		Get the most recently added transaction that says it is prepared during
 *        recovery the transaction table and make the passed in transaction
 *        assume its identity. This routine turns off the isRecovery() state
 *		<B> Should only be used in recovery handle prepare after undo !! </B>
 *
 *		<P>MT - unsafe, caller is recovery, which is single threaded.
 */
/**
 * Get the most recent recovered prepared transaction.
 * <p>
 * Get the most recently added transaction that says it is prepared during
 * recovery the transaction table and make the passed in transaction
 * assume its identity.
 * <p>
 * This routine, unlike the redo and rollback getMostRecent*() routines
 * expects a brand new transaction to be passed in.  If a candidate
 * transaction is found, then upon return the transaction table will
 * be altered such that the old entry no longer exists, and a new entry
 * will exist pointing to the transaction passed in.  The new entry will
 * look the same as if the prepared transaction had been created during
 * runtime rather than recovery.
 *
 * <B> Should only be used in recovery handle prepare after undo !! </B>
 *
 * <P>MT - unsafe, caller is recovery, which is single threaded.
 *
 * @return true if a candidate transaction has been found.  false if no
 *         prepared/recovery transactions found in the table.
 *
 * @param tran   Newly allocated transaction to add to link to a entry.
 */
public boolean getMostRecentPreparedRecoveredXact(RawTransaction tran) {
    TransactionTableEntry found_ent = null;
    if (!trans.isEmpty()) {
        TransactionId id = null;
        GlobalTransactionId gid = null;
        for (TransactionTableEntry ent : trans.values()) {
            if (ent != null && ent.isRecovery() && ent.isPrepared()) {
                // try to locate the most recent one
                if (id == null || XactId.compare(id, ent.getXid()) < 0) {
                    found_ent = ent;
                    id = ent.getXid();
                    gid = ent.getGid();
                }
            }
        }
        if (SanityManager.DEBUG) {
            if (found_ent == null) {
                // be non-recover, prepared global transactions.
                for (TransactionTableEntry ent : trans.values()) {
                    if (XactId.compare(ent.getXid(), tran.getId()) != 0) {
                        SanityManager.ASSERT(!ent.isRecovery() && ent.isPrepared());
                        SanityManager.ASSERT(ent.getGid() != null);
                    }
                }
            }
        }
        if (found_ent != null) {
            // At this point there are 2 tt entries of interest:
            // new_ent - the read only transaction entry that was
            // created when we allocated a new transaction.
            // We will just throw this one away after
            // assuming the identity of the global xact.
            // found_ent
            // - the entry of the transaction that we are going
            // to take over.
            TransactionTableEntry new_ent = trans.remove(tran.getId());
            // At this point only the found_ent should be in the table.
            if (SanityManager.DEBUG) {
                SanityManager.ASSERT(findTransactionEntry(id) == found_ent);
            }
            ((Xact) tran).assumeGlobalXactIdentity(found_ent);
            // transform this recovery entry, into a runtime entry.
            found_ent.unsetRecoveryStatus();
        }
    }
    return (found_ent != null);
}
Also used : GlobalTransactionId(org.apache.derby.iapi.store.raw.GlobalTransactionId) GlobalTransactionId(org.apache.derby.iapi.store.raw.GlobalTransactionId) TransactionId(org.apache.derby.iapi.store.raw.xact.TransactionId)

Example 2 with GlobalTransactionId

use of org.apache.derby.iapi.store.raw.GlobalTransactionId in project derby by apache.

the class TransactionTableEntry method getGlobalTransactionIdString.

public String getGlobalTransactionIdString() {
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(!recovery, "trying to display recovery transaction");
        SanityManager.ASSERT(myxact != null, "my xact is null");
        SanityManager.ASSERT(isClone, "Should only call method on a clone");
    }
    GlobalTransactionId gid = myxact.getGlobalId();
    return (gid == null) ? null : gid.toString();
}
Also used : GlobalTransactionId(org.apache.derby.iapi.store.raw.GlobalTransactionId)

Aggregations

GlobalTransactionId (org.apache.derby.iapi.store.raw.GlobalTransactionId)2 TransactionId (org.apache.derby.iapi.store.raw.xact.TransactionId)1