Search in sources :

Example 11 with XARecoveryModule

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

the class RecoveryManagerService method removeXAResourceRecovery.

public void removeXAResourceRecovery(XAResourceRecovery xaResourceRecovery) {
    if (_recoveryManager == null) {
        throw new IllegalStateException(jbossatxLogger.i18NLogger.get_jta_RecoveryManagerService_norecoverysystem());
    }
    XARecoveryModule xaRecoveryModule = null;
    for (RecoveryModule recoveryModule : ((Vector<RecoveryModule>) _recoveryManager.getModules())) {
        if (recoveryModule instanceof XARecoveryModule) {
            xaRecoveryModule = (XARecoveryModule) recoveryModule;
            break;
        }
    }
    if (xaRecoveryModule == null) {
        throw new IllegalStateException(jbossatxLogger.i18NLogger.get_jta_RecoveryManagerService_norecoverymodule());
    }
    xaRecoveryModule.removeXAResourceRecoveryHelper(new XAResourceRecoveryHelperWrapper(xaResourceRecovery));
}
Also used : XAResourceRecoveryHelperWrapper(com.arjuna.ats.internal.jbossatx.jta.XAResourceRecoveryHelperWrapper) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 12 with XARecoveryModule

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

the class RecoveryTest method directRecoverableConnection.

@Test
@BMRule(name = "throw rmfail xaexception", targetClass = "org.h2.jdbcx.JdbcXAConnection", targetMethod = "commit", action = "throw new javax.transaction.xa.XAException(javax.transaction.xa.XAException.XAER_RMFAIL)", targetLocation = "AT ENTRY")
public void directRecoverableConnection() throws Exception {
    // jdbc:arjuna: <path to properties file>, path starting at System.getProperty("user.dir")
    String url = TransactionalDriver.arjunaDriver + "ds-direct.properties";
    Properties dbProperties = new Properties();
    dbProperties.put(TransactionalDriver.dynamicClass, PropertyFileDynamicClass.class.getName());
    dbProperties.put(TransactionalDriver.userName, "");
    dbProperties.put(TransactionalDriver.password, "");
    Properties p = System.getProperties();
    p.put("jdbc.drivers", Driver.class.getName());
    System.setProperties(p);
    transactionalDriver = new TransactionalDriver();
    DriverManager.registerDriver(transactionalDriver);
    step0_setupTables(url, dbProperties);
    // rmfail means the db connection was left to be recovered
    step1_leaveXidsInDbTable(url, dbProperties);
    step2_checkDbIsNotCommitted(url, dbProperties);
    // 3. Perform recovery - checking only top down XARecoveryModule functionality
    {
        XARecoveryModule xarm = new XARecoveryModule();
        RecoveryManager manager = RecoveryManager.manager();
        manager.removeAllModules(true);
        manager.addModule(xarm);
        AtomicActionRecoveryModule aarm = new AtomicActionRecoveryModule();
        aarm.periodicWorkFirstPass();
        Transformer.disableTriggers(true);
        aarm.periodicWorkSecondPass();
        Transformer.enableTriggers(true);
    }
    step4_finalDbCommitCheck(url, dbProperties);
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) TransactionalDriver(com.arjuna.ats.jdbc.TransactionalDriver) Driver(org.h2.Driver) PropertyFileDynamicClass(com.arjuna.ats.internal.jdbc.drivers.PropertyFileDynamicClass) Properties(java.util.Properties) TransactionalDriver(com.arjuna.ats.jdbc.TransactionalDriver) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test)

Example 13 with XARecoveryModule

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

the class XAResourceRecord method getNewXAResource.

/**
 * This routine finds the new XAResource for the transaction that used the
 * old resource we couldn't serialize. It does this by looking up the
 * XARecoveryModule in the recovery manager and asking it for the
 * XAResource. The recovery manager will then look through its list of
 * registered XARecoveryResource implementations for the appropriate
 * instance. If the XARecoveryModule hasn't been initialised yet then this
 * routine will fail, but on the next scan it should work.
 */
private final XAResource getNewXAResource() {
    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 XARecoveryModule) {
                return ((XARecoveryModule) m).getNewXAResource(this);
            }
        }
    }
    return null;
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) Enumeration(java.util.Enumeration) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) Vector(java.util.Vector) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 14 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project wildfly by wildfly.

the class InboundBridgeService method addDeserializerAndOrphanFilter.

private void addDeserializerAndOrphanFilter() {
    final RecoveryManager recoveryManager = RecoveryManager.manager();
    for (RecoveryModule recoveryModule : recoveryManager.getModules()) {
        if (recoveryModule instanceof XARecoveryModule) {
            orphanFilter = new InboundBridgeOrphanFilter();
            ((XARecoveryModule) recoveryModule).addXAResourceOrphanFilter(orphanFilter);
            ((XARecoveryModule) recoveryModule).addSerializableXAResourceDeserializer(new InboundBridge());
        }
    }
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) InboundBridge(org.jboss.narayana.rest.bridge.inbound.InboundBridge) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) InboundBridgeRecoveryModule(org.jboss.narayana.rest.bridge.inbound.InboundBridgeRecoveryModule) InboundBridgeOrphanFilter(org.jboss.narayana.rest.bridge.inbound.InboundBridgeOrphanFilter) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 15 with XARecoveryModule

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

the class RecoveryTest method test.

@Test
@BMRule(name = "throw lang error exception", targetClass = "org.h2.jdbcx.JdbcXAConnection", targetMethod = "commit", action = "throw new java.lang.Error()", targetLocation = "AT ENTRY")
public void test() throws Exception {
    String url = "jdbc:arjuna:";
    Properties p = System.getProperties();
    p.put("jdbc.drivers", Driver.class.getName());
    System.setProperties(p);
    transactionalDriver = new TransactionalDriver();
    DriverManager.registerDriver(transactionalDriver);
    Properties dbProperties = new Properties();
    final JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    dbProperties.put(TransactionalDriver.XADataSource, ds);
    step0_setupTables(url, dbProperties);
    // We need to do this in a different thread as otherwise the transaction would still be associated with the connection due to the java.lang.Error
    // RMFAIL on it's own will cause H2 to close connection and that seems to discard the indoubt transactions
    step1_leaveXidsInDbTable(url, dbProperties);
    step2_checkDbIsNotCommitted(url, dbProperties);
    // 3. Perform recovery
    {
        XARecoveryModule xarm = new XARecoveryModule();
        xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

            @Override
            public boolean initialise(String p) throws Exception {
                return false;
            }

            @Override
            public XAResource[] getXAResources() throws Exception {
                return new XAResource[] { ds.getXAConnection().getXAResource() };
            }
        });
        RecoveryManager manager = RecoveryManager.manager();
        manager.removeAllModules(true);
        manager.addModule(xarm);
        AtomicActionRecoveryModule aarm = new AtomicActionRecoveryModule();
        aarm.periodicWorkFirstPass();
        Transformer.disableTriggers(true);
        aarm.periodicWorkSecondPass();
        Transformer.enableTriggers(true);
    }
    step4_finalDbCommitCheck(url, dbProperties);
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) XAResource(javax.transaction.xa.XAResource) AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) TransactionalDriver(com.arjuna.ats.jdbc.TransactionalDriver) Driver(org.h2.Driver) Properties(java.util.Properties) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) TransactionalDriver(com.arjuna.ats.jdbc.TransactionalDriver) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test)

Aggregations

XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)37 Test (org.junit.Test)25 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)19 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)18 XAResource (javax.transaction.xa.XAResource)17 Xid (javax.transaction.xa.Xid)14 Uid (com.arjuna.ats.arjuna.common.Uid)10 XidImple (com.arjuna.ats.jta.xa.XidImple)9 Enumeration (java.util.Enumeration)9 Vector (java.util.Vector)9 XAException (javax.transaction.xa.XAException)9 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)8 Connection (java.sql.Connection)8 InitialContext (javax.naming.InitialContext)7 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)7 RecoveryManager (com.arjuna.ats.arjuna.recovery.RecoveryManager)6 ExecuteException (org.jboss.byteman.rule.exception.ExecuteException)6 JTANodeNameXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter)5 ArrayList (java.util.ArrayList)5 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)4