Search in sources :

Example 1 with RecoveryEnvironmentBean

use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project narayana by jbosstm.

the class CrashRecovery2 method setUp.

@Before
public void setUp() {
    RecoveryEnvironmentBean recoveryEnvironmentBean = recoveryPropertyManager.getRecoveryEnvironmentBean();
    recoveryEnvironmentBean.setRecoveryModuleClassNames(Arrays.asList(new String[] { "com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule", "com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule" }));
    JTAEnvironmentBean jtaEnvironmentBean = jtaPropertyManager.getJTAEnvironmentBean();
    jtaEnvironmentBean.setXaResourceRecoveryClassNames(Arrays.asList(new String[] { "com.hp.mwtests.ts.jta.recovery.TestXAResourceRecovery" }));
    jtaEnvironmentBean.setXaResourceOrphanFilterClassNames(Arrays.asList(new String[] { "com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter", "com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter" }));
    jtaEnvironmentBean.setXaRecoveryNodes(Arrays.asList(new String[] { "1" }));
}
Also used : RecoveryEnvironmentBean(com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean) JTAEnvironmentBean(com.arjuna.ats.jta.common.JTAEnvironmentBean) Before(org.junit.Before)

Example 2 with RecoveryEnvironmentBean

use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project narayana by jbosstm.

the class CrashRecoveryCommitReturnsXA_RETRY method test.

@Test
public void test() throws Exception {
    // this test is supposed to leave a record around in the log store
    // during a commit long enough
    // that the periodic recovery thread runs and detects it. rather than
    // rely on delays to make
    // this happen (placing us at the mercy of the scheduler) we use a
    // byteman script to enforce
    // the thread sequence we need
    RecoveryEnvironmentBean recoveryEnvironmentBean = BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class);
    recoveryEnvironmentBean.setRecoveryBackoffPeriod(1);
    recoveryEnvironmentBean.setPeriodicRecoveryPeriod(1);
    List<String> recoveryModuleClassNames = new ArrayList<String>();
    recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
    recoveryModuleClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
    recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryModuleClassNames);
    List<String> expiryScannerClassNames = new ArrayList<String>();
    expiryScannerClassNames.add("com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
    recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScannerClassNames);
    recoveryEnvironmentBean.setRecoveryActivators(null);
    // start the recovery manager
    RecoveryManager.manager().initialize();
    XARecoveryModule xaRecoveryModule = null;
    for (RecoveryModule recoveryModule : ((Vector<RecoveryModule>) RecoveryManager.manager().getModules())) {
        if (recoveryModule instanceof XARecoveryModule) {
            xaRecoveryModule = (XARecoveryModule) recoveryModule;
            break;
        }
    }
    if (xaRecoveryModule == null) {
        throw new Exception("No XARM");
    }
    XAResource firstResource = new SimpleResource();
    final SimpleResourceXA_RETRY secondResource = new SimpleResourceXA_RETRY(this);
    xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

        @Override
        public boolean initialise(String p) throws Exception {
            // TODO Auto-generated method stub
            return true;
        }

        @Override
        public XAResource[] getXAResources() throws Exception {
            // TODO Auto-generated method stub
            return new XAResource[] { secondResource };
        }
    });
    // ok, now drive a TX to completion. the script should ensure that the
    // recovery
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.begin();
    javax.transaction.Transaction theTransaction = tm.getTransaction();
    theTransaction.enlistResource(firstResource);
    theTransaction.enlistResource(secondResource);
    assertFalse(secondResource.wasCommitted());
    tm.commit();
    synchronized (this) {
        while (!committed) {
            wait();
        }
    }
    assertTrue(secondResource.wasCommitted());
}
Also used : ArrayList(java.util.ArrayList) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) RecoveryEnvironmentBean(com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean) XAResource(javax.transaction.xa.XAResource) 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) Test(org.junit.Test)

Example 3 with RecoveryEnvironmentBean

use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project wildfly by wildfly.

the class ArjunaRecoveryManagerService method start.

public synchronized void start(StartContext context) throws StartException {
    // Recovery env bean
    final RecoveryEnvironmentBean recoveryEnvironmentBean = recoveryPropertyManager.getRecoveryEnvironmentBean();
    final SocketBinding recoveryBinding = recoveryBindingInjector.getValue();
    recoveryEnvironmentBean.setRecoveryInetAddress(recoveryBinding.getSocketAddress().getAddress());
    recoveryEnvironmentBean.setRecoveryPort(recoveryBinding.getSocketAddress().getPort());
    final SocketBinding statusBinding = statusBindingInjector.getValue();
    recoveryEnvironmentBean.setTransactionStatusManagerInetAddress(statusBinding.getSocketAddress().getAddress());
    recoveryEnvironmentBean.setTransactionStatusManagerPort(statusBinding.getSocketAddress().getPort());
    recoveryEnvironmentBean.setRecoveryListener(recoveryListener);
    if (recoveryListener) {
        ManagedBinding binding = ManagedBinding.Factory.createSimpleManagedBinding(recoveryBinding);
        bindingManager.getValue().getNamedRegistry().registerBinding(binding);
    }
    final List<String> recoveryExtensions = new ArrayList<String>();
    // must be first
    recoveryExtensions.add(CommitMarkableResourceRecordRecoveryModule.class.getName());
    recoveryExtensions.add(AtomicActionRecoveryModule.class.getName());
    recoveryExtensions.add(TORecoveryModule.class.getName());
    recoveryExtensions.add(SubordinateAtomicActionRecoveryModule.class.getName());
    final List<String> expiryScanners;
    if (System.getProperty("RecoveryEnvironmentBean.expiryScannerClassNames") != null || System.getProperty("com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean.expiryScannerClassNames") != null) {
        expiryScanners = recoveryEnvironmentBean.getExpiryScannerClassNames();
    } else {
        expiryScanners = new ArrayList<String>();
        expiryScanners.add(ExpiredTransactionStatusManagerScanner.class.getName());
    }
    if (!jts) {
        recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.class.getName());
        recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryExtensions);
        recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScanners);
        recoveryEnvironmentBean.setRecoveryActivators(null);
        final RecoveryManagerService recoveryManagerService = new RecoveryManagerService();
        try {
            recoveryManagerService.create();
        } catch (Exception e) {
            throw TransactionLogger.ROOT_LOGGER.managerStartFailure(e, "Recovery");
        }
        recoveryManagerService.start();
        this.recoveryManagerService = recoveryManagerService;
    } else {
        final ORB orb = orbInjector.getValue();
        new PostInitLoader(PostInitLoader.generateORBPropertyName("com.arjuna.orbportability.orb"), orb);
        recoveryExtensions.add(TopLevelTransactionRecoveryModule.class.getName());
        recoveryExtensions.add(ServerTransactionRecoveryModule.class.getName());
        recoveryExtensions.add(JCAServerTransactionRecoveryModule.class.getName());
        recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule.class.getName());
        expiryScanners.add(ExpiredContactScanner.class.getName());
        expiryScanners.add(ExpiredToplevelScanner.class.getName());
        expiryScanners.add(ExpiredServerScanner.class.getName());
        recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryExtensions);
        recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScanners);
        recoveryEnvironmentBean.setRecoveryActivatorClassNames(Collections.singletonList(com.arjuna.ats.internal.jts.orbspecific.recovery.RecoveryEnablement.class.getName()));
        try {
            final RecoveryManagerService recoveryManagerService = new com.arjuna.ats.jbossatx.jts.RecoveryManagerService(orb);
            recoveryManagerService.create();
            recoveryManagerService.start();
            this.recoveryManagerService = recoveryManagerService;
        } catch (Exception e) {
            throw TransactionLogger.ROOT_LOGGER.managerStartFailure(e, "Recovery");
        }
    }
    recoverySuspendController = new RecoverySuspendController(recoveryManagerService);
    processStateInjector.getValue().addPropertyChangeListener(recoverySuspendController);
    suspendControllerInjector.getValue().registerActivity(recoverySuspendController);
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) ExpiredContactScanner(com.arjuna.ats.internal.jts.recovery.contact.ExpiredContactScanner) SubordinateAtomicActionRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinateAtomicActionRecoveryModule) AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) ExpiredTransactionStatusManagerScanner(com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner) ArrayList(java.util.ArrayList) TopLevelTransactionRecoveryModule(com.arjuna.ats.internal.jts.recovery.transactions.TopLevelTransactionRecoveryModule) ManagedBinding(org.jboss.as.network.ManagedBinding) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryManagerService(com.arjuna.ats.jbossatx.jta.RecoveryManagerService) PostInitLoader(com.arjuna.orbportability.internal.utils.PostInitLoader) StartException(org.jboss.msc.service.StartException) ExpiredToplevelScanner(com.arjuna.ats.internal.jts.recovery.transactions.ExpiredToplevelScanner) TORecoveryModule(com.arjuna.ats.internal.txoj.recovery.TORecoveryModule) RecoveryEnvironmentBean(com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean) RecoverySuspendController(org.jboss.as.txn.suspend.RecoverySuspendController) SubordinateAtomicActionRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinateAtomicActionRecoveryModule) JCAServerTransactionRecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.JCAServerTransactionRecoveryModule) ServerTransactionRecoveryModule(com.arjuna.ats.internal.jts.recovery.transactions.ServerTransactionRecoveryModule) JCAServerTransactionRecoveryModule(com.arjuna.ats.internal.jta.recovery.jts.JCAServerTransactionRecoveryModule) ExpiredServerScanner(com.arjuna.ats.internal.jts.recovery.transactions.ExpiredServerScanner) ORB(org.omg.CORBA.ORB)

Example 4 with RecoveryEnvironmentBean

use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project narayana by jbosstm.

the class PeriodicRecoveryTest method testInitialDelay.

@Test
public void testInitialDelay() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    RecoveryEnvironmentBean bean = recoveryPropertyManager.getRecoveryEnvironmentBean().setPeriodicRecoveryInitilizationOffset(1);
    PeriodicRecovery periodicRecovery = new PeriodicRecovery(false, false);
    Method doInitialWait = periodicRecovery.getClass().getDeclaredMethod("doInitialWait");
    doInitialWait.setAccessible(true);
    long l = System.currentTimeMillis();
    try {
        doInitialWait.invoke(periodicRecovery, null);
    } finally {
        doInitialWait.setAccessible(false);
    }
    assertTrue(System.currentTimeMillis() - l > 500);
}
Also used : RecoveryEnvironmentBean(com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean) PeriodicRecovery(com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 5 with RecoveryEnvironmentBean

use of com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean in project narayana by jbosstm.

the class CrashRecoveryCommitReturnsXA_RETRYHeuristicRollback method testHeuristicRollback.

@Test
public void testHeuristicRollback() throws Exception {
    // this test is supposed to leave a record around in the log store
    // during a commit long enough
    // that the periodic recovery thread runs and detects it. rather than
    // rely on delays to make
    // this happen (placing us at the mercy of the scheduler) we use a
    // byteman script to enforce
    // the thread sequence we need
    RecoveryEnvironmentBean recoveryEnvironmentBean = BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class);
    // JBTM-1354 we need to make sure that a full scan has gone off
    recoveryEnvironmentBean.setRecoveryBackoffPeriod(1);
    recoveryEnvironmentBean.setPeriodicRecoveryPeriod(Integer.MAX_VALUE);
    List<String> recoveryModuleClassNames = new ArrayList<String>();
    recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
    recoveryModuleClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
    recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryModuleClassNames);
    List<String> expiryScannerClassNames = new ArrayList<String>();
    expiryScannerClassNames.add("com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
    recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScannerClassNames);
    recoveryEnvironmentBean.setRecoveryActivators(null);
    // start the recovery manager
    RecoveryManager.manager().initialize();
    XARecoveryModule xaRecoveryModule = null;
    for (RecoveryModule recoveryModule : ((Vector<RecoveryModule>) RecoveryManager.manager().getModules())) {
        if (recoveryModule instanceof XARecoveryModule) {
            xaRecoveryModule = (XARecoveryModule) recoveryModule;
            break;
        }
    }
    if (xaRecoveryModule == null) {
        throw new Exception("No XARM");
    }
    // JBTM-1354 Run a scan to make sure that the recovery thread has completed a full run before starting the test
    // The important thing is that replayCompletion is allowed to do a scan of the transactions
    RecoveryManager.manager().scan();
    XAResource firstResource = new SimpleResource();
    Object toWakeUp = new Object();
    final SimpleResourceXA_RETRYHeuristicRollback secondResource = new SimpleResourceXA_RETRYHeuristicRollback();
    xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

        @Override
        public boolean initialise(String p) throws Exception {
            // TODO Auto-generated method stub
            return true;
        }

        @Override
        public XAResource[] getXAResources() throws Exception {
            // TODO Auto-generated method stub
            return new XAResource[] { secondResource };
        }
    });
    // ok, now drive a TX to completion. the script should ensure that the
    // recovery
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.begin();
    javax.transaction.Transaction theTransaction = tm.getTransaction();
    Uid txUid = ((TransactionImple) theTransaction).get_uid();
    theTransaction.enlistResource(firstResource);
    theTransaction.enlistResource(secondResource);
    assertFalse(secondResource.wasCommitted());
    tm.commit();
    InputObjectState uids = new InputObjectState();
    String type = new AtomicAction().type();
    StoreManager.getRecoveryStore().allObjUids(type, uids);
    boolean moreUids = true;
    boolean found = false;
    while (moreUids) {
        Uid theUid = UidHelper.unpackFrom(uids);
        if (theUid.equals(txUid)) {
            found = true;
            Field heuristicListField = BasicAction.class.getDeclaredField("heuristicList");
            heuristicListField.setAccessible(true);
            ActionStatusService ass = new ActionStatusService();
            {
                int theStatus = ass.getTransactionStatus(type, theUid.stringForm());
                assertTrue(theStatus == ActionStatus.COMMITTED);
                RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(theUid, theStatus);
                theStatus = rcvAtomicAction.status();
                rcvAtomicAction.replayPhase2();
                assertTrue(theStatus == ActionStatus.COMMITTED);
                assertTrue(secondResource.wasCommitted());
                RecordList heuristicList = (RecordList) heuristicListField.get(rcvAtomicAction);
                assertTrue("Expected 1 heuristics: " + heuristicList.size(), heuristicList.size() == 1);
            }
            {
                int theStatus = ass.getTransactionStatus(type, theUid.stringForm());
                assertTrue(theStatus == ActionStatus.COMMITTED);
                RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(theUid, theStatus);
                theStatus = rcvAtomicAction.status();
                assertTrue(theStatus == ActionStatus.COMMITTED);
                RecordList heuristicList = (RecordList) heuristicListField.get(rcvAtomicAction);
                assertTrue("Expected 1 heuristics: " + heuristicList.size(), heuristicList.size() == 1);
                assertTrue(secondResource.wasCommitted());
            }
        } else if (theUid.equals(Uid.nullUid())) {
            moreUids = false;
        }
    }
    if (!found) {
        throw new Exception("Could not locate the Uid");
    }
}
Also used : TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) ArrayList(java.util.ArrayList) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) Field(java.lang.reflect.Field) ActionStatusService(com.arjuna.ats.arjuna.recovery.ActionStatusService) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) RecoveryEnvironmentBean(com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean) XAResource(javax.transaction.xa.XAResource) RecordList(com.arjuna.ats.arjuna.coordinator.RecordList) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Aggregations

RecoveryEnvironmentBean (com.arjuna.ats.arjuna.common.RecoveryEnvironmentBean)7 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)2 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)2 RecoveryManagerService (com.arjuna.ats.jbossatx.jta.RecoveryManagerService)2 JTAEnvironmentBean (com.arjuna.ats.jta.common.JTAEnvironmentBean)2 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)2 XAResource (javax.transaction.xa.XAResource)2 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)1 CoordinatorEnvironmentBean (com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean)1 CoreEnvironmentBean (com.arjuna.ats.arjuna.common.CoreEnvironmentBean)1 ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)1 Uid (com.arjuna.ats.arjuna.common.Uid)1 RecordList (com.arjuna.ats.arjuna.coordinator.RecordList)1 TxControl (com.arjuna.ats.arjuna.coordinator.TxControl)1 ActionStatusService (com.arjuna.ats.arjuna.recovery.ActionStatusService)1 RecoverAtomicAction (com.arjuna.ats.arjuna.recovery.RecoverAtomicAction)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 AtomicActionRecoveryModule (com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule)1