Search in sources :

Example 6 with TransactionsMXBean

use of org.apache.ignite.mxbean.TransactionsMXBean in project ignite by apache.

the class TransactionsMXBeanImplTest method checkLongOperationsDumpTimeoutViaTxMxBean.

/**
 * Checking changes and receiving lrt through MXBean.
 *
 * @param defTimeout Default lrt timeout.
 * @param newTimeout New lrt timeout.
 * @param waitTimeTx Waiting time for a lrt.
 * @param expectTx Expect or not a lrt to log.
 * @throws Exception If failed.
 */
private void checkLongOperationsDumpTimeoutViaTxMxBean(long defTimeout, long newTimeout, long waitTimeTx, boolean expectTx) throws Exception {
    IgniteEx ignite = startGrid(0);
    IgniteEx ignite1 = startGrid(1);
    ignite.cluster().state(ACTIVE);
    TransactionsMXBean txMXBean = txMXBean(0);
    TransactionsMXBean txMXBean1 = txMXBean(1);
    assertEquals(defTimeout, txMXBean.getLongOperationsDumpTimeout());
    assertEquals(defTimeout, txMXBean1.getLongOperationsDumpTimeout());
    Transaction tx = ignite.transactions().txStart();
    LogListener lrtLogLsnr = matches("First 10 long running transactions [total=1]").build();
    LogListener txLogLsnr = matches(((TransactionProxyImpl) tx).tx().xidVersion().toString()).build();
    testLog.registerListener(lrtLogLsnr);
    testLog.registerListener(txLogLsnr);
    txMXBean.setLongOperationsDumpTimeout(newTimeout);
    assertEquals(newTimeout, ignite.context().cache().context().tm().longOperationsDumpTimeout());
    assertEquals(newTimeout, ignite1.context().cache().context().tm().longOperationsDumpTimeout());
    if (expectTx)
        assertTrue(waitForCondition(() -> lrtLogLsnr.check() && txLogLsnr.check(), waitTimeTx));
    else
        assertFalse(waitForCondition(() -> lrtLogLsnr.check() && txLogLsnr.check(), waitTimeTx));
}
Also used : TransactionsMXBean(org.apache.ignite.mxbean.TransactionsMXBean) Transaction(org.apache.ignite.transactions.Transaction) LogListener(org.apache.ignite.testframework.LogListener) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)

Example 7 with TransactionsMXBean

use of org.apache.ignite.mxbean.TransactionsMXBean in project ignite by apache.

the class GridCacheLongRunningTransactionDiagnosticsTest method testLrtChangeSetting.

/**
 * Tests transaction mx bean and its ability to turn on and off thread dump requests
 * from local node to near node.
 *
 * @throws Exception if grids start failed.
 */
@Test
public void testLrtChangeSetting() throws Exception {
    startGridsMultiThreaded(2);
    TransactionsMXBean tMXBean0 = txMXBean(0);
    TransactionsMXBean tMXBean1 = txMXBean(1);
    assertTrue(tMXBean0.getTxOwnerDumpRequestsAllowed());
    assertTrue(tMXBean1.getTxOwnerDumpRequestsAllowed());
    tMXBean0.setTxOwnerDumpRequestsAllowed(false);
    assertFalse(tMXBean0.getTxOwnerDumpRequestsAllowed());
    assertFalse(tMXBean1.getTxOwnerDumpRequestsAllowed());
    imitateLongTransaction(false);
}
Also used : TransactionsMXBean(org.apache.ignite.mxbean.TransactionsMXBean) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 8 with TransactionsMXBean

use of org.apache.ignite.mxbean.TransactionsMXBean in project ignite by apache.

the class SetTxTimeoutOnPartitionMapExchangeTest method testJmxSetTxTimeoutOnPartitionMapExchange.

/**
 */
@Test
public void testJmxSetTxTimeoutOnPartitionMapExchange() throws Exception {
    startGrid(1);
    startGrid(2);
    TransactionsMXBean mxBean1 = txMXBean(1);
    TransactionsMXBean mxBean2 = txMXBean(2);
    final long expTimeout1 = 20_000L;
    final long expTimeout2 = 30_000L;
    mxBean1.setTxTimeoutOnPartitionMapExchange(expTimeout1);
    assertTxTimeoutOnPartitionMapExchange(expTimeout1);
    assertEquals(expTimeout1, mxBean1.getTxTimeoutOnPartitionMapExchange());
    mxBean2.setTxTimeoutOnPartitionMapExchange(expTimeout2);
    assertTxTimeoutOnPartitionMapExchange(expTimeout2);
    assertEquals(expTimeout2, mxBean2.getTxTimeoutOnPartitionMapExchange());
}
Also used : TransactionsMXBean(org.apache.ignite.mxbean.TransactionsMXBean) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with TransactionsMXBean

use of org.apache.ignite.mxbean.TransactionsMXBean in project ignite by apache.

the class SetTxTimeoutOnPartitionMapExchangeTest method checkSetTxTimeoutDuringPartitionMapExchange.

/**
 * @param ig Ignite instance where deadlock tx will start.
 * @throws Exception If fails.
 */
private void checkSetTxTimeoutDuringPartitionMapExchange(IgniteEx ig) throws Exception {
    final long longTimeout = 600_000L;
    final long shortTimeout = 5_000L;
    TransactionsMXBean mxBean = txMXBean(0);
    // Case 1: set very long txTimeoutOnPME, transaction should be rolled back.
    mxBean.setTxTimeoutOnPartitionMapExchange(longTimeout);
    assertTxTimeoutOnPartitionMapExchange(longTimeout);
    AtomicReference<Exception> txEx = new AtomicReference<>();
    IgniteInternalFuture<Long> fut = startDeadlock(ig, txEx, 0);
    startGridAsync(2);
    waitForExchangeStarted(ig);
    mxBean.setTxTimeoutOnPartitionMapExchange(shortTimeout);
    awaitPartitionMapExchange();
    fut.get();
    assertTrue("Transaction should be rolled back", hasCause(txEx.get(), TransactionRollbackException.class));
    // Case 2: txTimeoutOnPME will be set to 0 after starting of PME, transaction should be cancelled on timeout.
    mxBean.setTxTimeoutOnPartitionMapExchange(longTimeout);
    assertTxTimeoutOnPartitionMapExchange(longTimeout);
    fut = startDeadlock(ig, txEx, 10000L);
    startGridAsync(3);
    waitForExchangeStarted(ig);
    mxBean.setTxTimeoutOnPartitionMapExchange(0);
    fut.get();
    assertTrue("Transaction should be canceled on timeout", hasCause(txEx.get(), TransactionTimeoutException.class));
}
Also used : TransactionsMXBean(org.apache.ignite.mxbean.TransactionsMXBean) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException)

Aggregations

TransactionsMXBean (org.apache.ignite.mxbean.TransactionsMXBean)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 Transaction (org.apache.ignite.transactions.Transaction)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 TransactionProxyImpl (org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)2 LogListener (org.apache.ignite.testframework.LogListener)2 Serializable (java.io.Serializable)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BiConsumer (java.util.function.BiConsumer)1 Function (java.util.function.Function)1 Ignite (org.apache.ignite.Ignite)1 IGNITE_DUMP_TX_COLLISIONS_INTERVAL (org.apache.ignite.IgniteSystemProperties.IGNITE_DUMP_TX_COLLISIONS_INTERVAL)1