Search in sources :

Example 1 with VisorTxInfo

use of org.apache.ignite.internal.visor.tx.VisorTxInfo in project ignite by apache.

the class GridCommandHandlerTest method testKillHangingLocalTransactions.

/**
 */
@Test
public void testKillHangingLocalTransactions() throws Exception {
    Ignite ignite = startGridsMultiThreaded(2);
    ignite.cluster().active(true);
    Ignite client = startGrid("client");
    client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setAtomicityMode(TRANSACTIONAL).setWriteSynchronizationMode(FULL_SYNC).setAffinity(new RendezvousAffinityFunction(false, 64)));
    Ignite prim = primaryNode(0L, DEFAULT_CACHE_NAME);
    // Blocks lock response to near node.
    TestRecordingCommunicationSpi.spi(prim).blockMessages(GridNearLockResponse.class, client.name());
    TestRecordingCommunicationSpi.spi(client).blockMessages(GridNearTxFinishRequest.class, prim.name());
    GridNearTxLocal clientTx = null;
    try (Transaction tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED, 2000, 1)) {
        clientTx = ((TransactionProxyImpl) tx).tx();
        client.cache(DEFAULT_CACHE_NAME).put(0L, 0L);
        fail();
    } catch (Exception e) {
        assertTrue(X.hasCause(e, TransactionTimeoutException.class));
    }
    assertNotNull(clientTx);
    IgniteEx primEx = (IgniteEx) prim;
    IgniteInternalTx tx0 = primEx.context().cache().context().tm().activeTransactions().iterator().next();
    assertNotNull(tx0);
    CommandHandler h = new CommandHandler();
    validate(h, map -> {
        ClusterNode node = grid(0).cluster().localNode();
        VisorTxTaskResult res = map.get(node);
        for (VisorTxInfo info : res.getInfos()) assertEquals(tx0.xid(), info.getXid());
        assertEquals(1, map.size());
    }, "--tx", "--xid", tx0.xid().toString(), "--kill");
    tx0.finishFuture().get();
    TestRecordingCommunicationSpi.spi(prim).stopBlock();
    TestRecordingCommunicationSpi.spi(client).stopBlock();
    IgniteInternalFuture<?> nearFinFut = U.field(clientTx, "finishFut");
    nearFinFut.get();
    checkUserFutures();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EntryProcessorException(javax.cache.processor.EntryProcessorException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) IgniteException(org.apache.ignite.IgniteException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) Transaction(org.apache.ignite.transactions.Transaction) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteCacheGroupsWithRestartsTest(org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest) Test(org.junit.Test)

Example 2 with VisorTxInfo

use of org.apache.ignite.internal.visor.tx.VisorTxInfo in project ignite by apache.

the class TxRollbackAsyncTest method testRollbackOnTopologyLockPessimistic.

/**
 */
@Test
public void testRollbackOnTopologyLockPessimistic() throws Exception {
    final Ignite client = startClient();
    Ignite crd = grid(0);
    List<Integer> keys = primaryKeys(grid(1).cache(CACHE_NAME), 1);
    assertTrue(crd.cluster().localNode().order() == 1);
    CountDownLatch txLatch = new CountDownLatch(1);
    CountDownLatch tx2Latch = new CountDownLatch(1);
    CountDownLatch commitLatch = new CountDownLatch(1);
    final long commitLatchTimeoutSeconds = 60;
    // Start tx holding topology.
    IgniteInternalFuture txFut = runAsync(new Runnable() {

        @Override
        public void run() {
            List<Integer> keys = primaryKeys(grid(0).cache(CACHE_NAME), 1);
            try (Transaction tx = client.transactions().txStart()) {
                client.cache(CACHE_NAME).put(keys.get(0), 0);
                txLatch.countDown();
                assertTrue(U.await(commitLatch, commitLatchTimeoutSeconds, TimeUnit.SECONDS));
                tx.commit();
                fail();
            } catch (Exception e) {
            // Expected.
            }
        }
    });
    U.awaitQuiet(txLatch);
    crd.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            runAsync(new Runnable() {

                @Override
                public void run() {
                    try (Transaction tx = crd.transactions().withLabel("testLbl").txStart()) {
                        // Wait for node start.
                        waitForCondition(new GridAbsPredicate() {

                            @Override
                            public boolean apply() {
                                return crd.cluster().topologyVersion() != GRID_CNT + /**
                                 * client node
                                 */
                                1 + /**
                                 * stop server node
                                 */
                                1 + /**
                                 * start server node
                                 */
                                1;
                            }
                        }, 10_000);
                        tx2Latch.countDown();
                        crd.cache(CACHE_NAME).put(keys.get(0), 0);
                        assertTrue(U.await(commitLatch, commitLatchTimeoutSeconds, TimeUnit.SECONDS));
                        tx.commit();
                        fail();
                    } catch (Exception e) {
                    // Expected.
                    }
                }
            });
            return false;
        }
    }, EventType.EVT_NODE_FAILED, EventType.EVT_NODE_LEFT);
    IgniteInternalFuture restartFut = runAsync(new Runnable() {

        @Override
        public void run() {
            stopGrid(2);
            try {
                startGrid(2);
            } catch (Exception e) {
                fail();
            }
        }
    });
    U.awaitQuiet(tx2Latch);
    // Rollback tx using kill task.
    VisorTxTaskArg arg = new VisorTxTaskArg(VisorTxOperation.KILL, null, null, null, null, null, null, null, null, null, null);
    Map<ClusterNode, VisorTxTaskResult> res = client.compute(client.cluster().forPredicate(F.alwaysTrue())).execute(new VisorTxTask(), new VisorTaskArgument<>(client.cluster().localNode().id(), arg, false));
    int expCnt = 0;
    for (Map.Entry<ClusterNode, VisorTxTaskResult> entry : res.entrySet()) {
        if (entry.getValue().getInfos().isEmpty())
            continue;
        for (VisorTxInfo info : entry.getValue().getInfos()) {
            log.info(info.toUserString());
            expCnt++;
        }
    }
    assertEquals("Expecting 2 transactions", 2, expCnt);
    commitLatch.countDown();
    txFut.get();
    restartFut.get();
    checkFutures();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) VisorTxTaskArg(org.apache.ignite.internal.visor.tx.VisorTxTaskArg) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) Transaction(org.apache.ignite.transactions.Transaction) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) List(java.util.List) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) TreeMap(java.util.TreeMap) VisorTxTask(org.apache.ignite.internal.visor.tx.VisorTxTask) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with VisorTxInfo

use of org.apache.ignite.internal.visor.tx.VisorTxInfo in project ignite by apache.

the class TxCommands method transactions.

/**
 * Dump transactions information.
 *
 * @param client Client.
 */
private void transactions(GridClient client, GridClientConfiguration conf) throws GridClientException {
    try {
        if (args.getOperation() == VisorTxOperation.INFO) {
            transactionInfo(client, conf);
            return;
        }
        Map<ClusterNode, VisorTxTaskResult> res = executeTask(client, VisorTxTask.class, args, conf);
        for (Map.Entry<ClusterNode, VisorTxTaskResult> entry : res.entrySet()) {
            if (entry.getValue().getInfos().isEmpty())
                continue;
            ClusterNode key = entry.getKey();
            logger.info(nodeDescription(key));
            for (VisorTxInfo info : entry.getValue().getInfos()) logger.info(info.toUserString());
        }
    } catch (Throwable e) {
        logger.severe("Failed to perform operation.");
        throw e;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with VisorTxInfo

use of org.apache.ignite.internal.visor.tx.VisorTxInfo in project ignite by apache.

the class TxCommands method printTxInfoResult.

/**
 * Prints result of --tx --info command to output.
 *
 * @param res Response.
 */
private void printTxInfoResult(Map<ClusterNode, VisorTxTaskResult> res) {
    String lb = null;
    Map<Integer, String> usedCaches = new HashMap<>();
    Map<Integer, String> usedCacheGroups = new HashMap<>();
    VisorTxInfo firstInfo = null;
    TxVerboseInfo firstVerboseInfo = null;
    Set<TransactionState> states = new HashSet<>();
    for (Map.Entry<ClusterNode, VisorTxTaskResult> entry : res.entrySet()) {
        for (VisorTxInfo info : entry.getValue().getInfos()) {
            assert info.getTxVerboseInfo() != null;
            if (lb == null)
                lb = info.getLabel();
            if (firstInfo == null) {
                firstInfo = info;
                firstVerboseInfo = info.getTxVerboseInfo();
            }
            usedCaches.putAll(info.getTxVerboseInfo().usedCaches());
            usedCacheGroups.putAll(info.getTxVerboseInfo().usedCacheGroups());
            states.add(info.getState());
        }
    }
    String indent = "";
    logger.info("");
    logger.info(indent + "Transaction detailed info:");
    printTransactionDetailedInfo(res, usedCaches, usedCacheGroups, firstInfo, firstVerboseInfo, states, indent + DOUBLE_INDENT);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) TransactionState(org.apache.ignite.transactions.TransactionState) HashMap(java.util.HashMap) TxVerboseInfo(org.apache.ignite.internal.visor.tx.TxVerboseInfo) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 5 with VisorTxInfo

use of org.apache.ignite.internal.visor.tx.VisorTxInfo in project ignite by apache.

the class TxCommands method execute.

/**
 * Dump transactions information.
 *
 * @param clientCfg Client configuration.
 */
@Override
public Object execute(GridClientConfiguration clientCfg, Logger logger) throws Exception {
    this.logger = logger;
    try (GridClient client = Command.startClient(clientCfg)) {
        if (args.getOperation() == VisorTxOperation.INFO)
            return transactionInfo(client, clientCfg);
        Map<ClusterNode, VisorTxTaskResult> res = executeTask(client, VisorTxTask.class, args, clientCfg);
        if (res.isEmpty())
            logger.info("Nothing found.");
        else if (args.getOperation() == VisorTxOperation.KILL)
            logger.info("Killed transactions:");
        else
            logger.info("Matching transactions:");
        for (Map.Entry<ClusterNode, VisorTxTaskResult> entry : res.entrySet()) {
            if (entry.getValue().getInfos().isEmpty())
                continue;
            ClusterNode key = entry.getKey();
            logger.info(key.getClass().getSimpleName() + " [id=" + key.id() + ", addrs=" + key.addresses() + ", order=" + key.order() + ", ver=" + key.version() + ", isClient=" + key.isClient() + ", consistentId=" + key.consistentId() + "]");
            for (VisorTxInfo info : entry.getValue().getInfos()) logger.info(info.toUserString());
        }
        return res;
    } catch (Throwable e) {
        logger.severe("Failed to perform operation.");
        logger.severe(CommandLogger.errorMessage(e));
        throw e;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) GridClient(org.apache.ignite.internal.client.GridClient) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VisorTxInfo (org.apache.ignite.internal.visor.tx.VisorTxInfo)9 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 VisorTxTaskResult (org.apache.ignite.internal.visor.tx.VisorTxTaskResult)8 Map (java.util.Map)7 HashMap (java.util.HashMap)5 Ignite (org.apache.ignite.Ignite)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteException (org.apache.ignite.IgniteException)4 TransactionRollbackException (org.apache.ignite.transactions.TransactionRollbackException)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 TreeMap (java.util.TreeMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 EntryProcessorException (javax.cache.processor.EntryProcessorException)3 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)3 CommandHandler (org.apache.ignite.internal.commandline.CommandHandler)3 IgniteCacheGroupsWithRestartsTest (org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest)3 AbstractSnapshotSelfTest.doSnapshotCancellationTest (org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest)3 TransactionTimeoutException (org.apache.ignite.transactions.TransactionTimeoutException)3 List (java.util.List)2