Search in sources :

Example 6 with CommitMarkableResourceRecordRecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule in project narayana by jbosstm.

the class TestCommitMarkableResourceReturnUnknownOutcomeFrom1PCCommit method testRMFAILAfterNoCommit.

@Test
public void testRMFAILAfterNoCommit() throws Exception {
    jtaPropertyManager.getJTAEnvironmentBean().setNotifyCommitMarkableResourceRecoveryModuleOfCompleteBranches(false);
    final JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
    // Test code
    Utils.createTables(dataSource.getConnection());
    // We can't just instantiate one as we need to be using the
    // same one as
    // the transaction
    // manager would have used to mark the transaction for GC
    CommitMarkableResourceRecordRecoveryModule commitMarkableResourceRecoveryModule = null;
    Vector recoveryModules = manager.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
                commitMarkableResourceRecoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
            } else if (m instanceof XARecoveryModule) {
                XARecoveryModule xarm = (XARecoveryModule) m;
                xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

                    public boolean initialise(String p) throws Exception {
                        return true;
                    }

                    public XAResource[] getXAResources() throws Exception {
                        return new XAResource[] { xaResource };
                    }
                });
            }
        }
    }
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.begin();
    Uid get_uid = ((TransactionImple) tm.getTransaction()).get_uid();
    Connection localJDBCConnection = dataSource.getConnection();
    localJDBCConnection.setAutoCommit(false);
    nonXAResource = new JDBCConnectableResource(localJDBCConnection) {

        @Override
        public void commit(Xid arg0, boolean arg1) throws XAException {
            throw new XAException(XAException.XAER_RMFAIL);
        }
    };
    tm.getTransaction().enlistResource(nonXAResource);
    xaResource = new SimpleXAResource();
    tm.getTransaction().enlistResource(xaResource);
    localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
    tm.commit();
    assertTrue(xaResource.wasCommitted());
    Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
    assertNotNull(committed);
    InputObjectState uids = new InputObjectState();
    StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
    Uid uid = UidHelper.unpackFrom(uids);
    assertTrue(uid.equals(get_uid));
    // Belt and braces but we don't expect the CMR to be removed anyway as
    // the RM is "offline"
    manager.scan();
    manager.scan();
    // The recovery module has to perform lookups
    new InitialContext().rebind("commitmarkableresource", dataSource);
    assertFalse(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
    // This will make the AA a heuristic
    manager.scan();
    EditableAtomicAction editableAtomicAction = new EditableAtomicAction(get_uid);
    editableAtomicAction.deleteHeuristicParticipant(0);
    manager.scan();
    StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
    uid = UidHelper.unpackFrom(uids);
    assertTrue(uid.equals(Uid.nullUid()));
    // This is when the CMR deletes are done due to ordering
    manager.scan();
    // of the recovery modules
    assertFalse(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Enumeration(java.util.Enumeration) XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) InitialContext(javax.naming.InitialContext) Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) EditableAtomicAction(com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) EditableAtomicAction(com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) Vector(java.util.Vector) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 7 with CommitMarkableResourceRecordRecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule in project narayana by jbosstm.

the class CMRIntegrationTest method postRunCleanup.

public long postRunCleanup(DataSource dataSource) throws SQLException, ObjectStoreException {
    Connection connection = dataSource.getConnection();
    CommitMarkableResourceRecordRecoveryModule crrrm = getCRRRM();
    int expectedReapableConnectableResourceRecords = BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class).isPerformImmediateCleanupOfCommitMarkableResourceBranches() ? 0 : threadCount * iterationCount;
    try {
        Statement statement = connection.createStatement();
        checkSize("xids", statement, expectedReapableConnectableResourceRecords);
        if (expectedReapableConnectableResourceRecords > 0) {
            // The recovery module has to perform lookups
            // new InitialContext().rebind("connectableresource",
            // recoveryDataSource);
            long startTime = System.currentTimeMillis();
            crrrm.periodicWorkFirstPass();
            crrrm.periodicWorkSecondPass();
            long endTime = System.currentTimeMillis();
            checkSize("xids", statement, 0);
            statement.close();
            System.out.println("  Total cleanup time: " + (endTime - startTime) + " Average cleanup time: " + (endTime - startTime) / expectedReapableConnectableResourceRecords);
            return endTime - startTime;
        } else {
            statement.close();
        }
    } finally {
        connection.close();
    }
    return 0;
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)

Example 8 with CommitMarkableResourceRecordRecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule in project narayana by jbosstm.

the class CMRIntegrationTest method getCRRRM.

private CommitMarkableResourceRecordRecoveryModule getCRRRM() {
    CommitMarkableResourceRecordRecoveryModule crrrm = null;
    RecoveryManager recMan = RecoveryManager.manager();
    Vector recoveryModules = recMan.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
                return (CommitMarkableResourceRecordRecoveryModule) m;
            }
        }
    }
    return null;
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) Enumeration(java.util.Enumeration) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) Vector(java.util.Vector)

Example 9 with CommitMarkableResourceRecordRecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule in project narayana by jbosstm.

the class FailAfterPrepareBase method generateCMRRecord.

protected Uid generateCMRRecord(final DataSource dataSource) throws Exception {
    ((JdbcDataSource) dataSource).setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
    // Test code
    Utils.createTables(dataSource.getConnection());
    // We can't just instantiate one as we need to be using the
    // same one as
    // the transaction
    // manager would have used to mark the transaction for GC
    Vector recoveryModules = manager.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
                recoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
            } else if (m instanceof XARecoveryModule) {
                XARecoveryModule xarm = (XARecoveryModule) m;
                xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

                    public boolean initialise(String p) throws Exception {
                        return true;
                    }

                    public XAResource[] getXAResources() throws Exception {
                        return new XAResource[] { xaResource };
                    }
                });
            }
        }
    }
    // final Object o = new Object();
    // synchronized (o) {
    final Uid[] uids = new Uid[1];
    Thread foo = new Thread(new Runnable() {

        public void run() {
            try {
                javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
                tm.begin();
                Connection localJDBCConnection = dataSource.getConnection();
                localJDBCConnection.setAutoCommit(false);
                nonXAResource = new JDBCConnectableResource(localJDBCConnection);
                tm.getTransaction().enlistResource(nonXAResource);
                xaResource = new SimpleXAResource();
                tm.getTransaction().enlistResource(xaResource);
                localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
                uids[0] = ((TransactionImple) tm.getTransaction()).get_uid();
                tm.commit();
            } catch (ExecuteException t) {
            } catch (Exception t) {
                t.printStackTrace();
                failed = true;
            } catch (Error t) {
            }
        }
    });
    foo.start();
    foo.join();
    assertFalse(failed);
    return uids[0];
}
Also used : Enumeration(java.util.Enumeration) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) NamingException(javax.naming.NamingException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) Uid(com.arjuna.ats.arjuna.common.Uid) XAResource(javax.transaction.xa.XAResource) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Vector(java.util.Vector) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 10 with CommitMarkableResourceRecordRecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule in project narayana by jbosstm.

the class TestCommitMarkableResource method doTest.

private void doTest(DataSource dataSource) throws Exception {
    // Test code
    Utils.createTables(dataSource.getConnection());
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.begin();
    Connection localJDBCConnection = dataSource.getConnection();
    localJDBCConnection.setAutoCommit(false);
    XAResource nonXAResource = new JDBCConnectableResource(localJDBCConnection);
    tm.getTransaction().enlistResource(nonXAResource);
    tm.getTransaction().enlistResource(new DummyXAResource());
    localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
    tm.commit();
    // This is test code, it allows us to verify that the correct XID was
    // removed
    Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
    assertNotNull(committed);
    // We can't just instantiate one as we need to be using the same one as
    // the transaction
    // manager would have used to mark the transaction for GC
    CommitMarkableResourceRecordRecoveryModule recoveryModule = null;
    Vector recoveryModules = manager.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
                recoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
            }
        }
    }
    recoveryModule = new CommitMarkableResourceRecordRecoveryModule();
    // The recovery module has to perform lookups
    new InitialContext().rebind("commitmarkableresource", dataSource);
    // Run the first pass it will load the committed Xids into memory
    recoveryModule.periodicWorkFirstPass();
    assertTrue(recoveryModule.wasCommitted("commitmarkableresource", committed));
    recoveryModule.periodicWorkSecondPass();
    // Make sure that the resource was GC'd by the CRRRM
    assertFalse(recoveryModule.wasCommitted("commitmarkableresource", committed));
}
Also used : XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) Enumeration(java.util.Enumeration) Connection(java.sql.Connection) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) Vector(java.util.Vector) InitialContext(javax.naming.InitialContext)

Aggregations

CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)12 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)11 Connection (java.sql.Connection)11 Enumeration (java.util.Enumeration)11 Vector (java.util.Vector)11 XAResource (javax.transaction.xa.XAResource)10 InitialContext (javax.naming.InitialContext)9 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)8 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)8 Xid (javax.transaction.xa.Xid)8 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)7 ExecuteException (org.jboss.byteman.rule.exception.ExecuteException)6 Test (org.junit.Test)6 Uid (com.arjuna.ats.arjuna.common.Uid)3 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)3 DataSource (javax.sql.DataSource)3 XAException (javax.transaction.xa.XAException)3 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)3 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)2 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)2