Search in sources :

Example 1 with VisorTxTask

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

the class TransactionsMXBeanImpl method cancel.

/**
 * {@inheritDoc}
 */
@Override
public void cancel(String xid) {
    A.notNull(xid, "xid");
    IgniteCompute compute = ctx.cluster().get().compute();
    compute.execute(new VisorTxTask(), new VisorTaskArgument<>(ctx.localNodeId(), new VisorTxTaskArg(VisorTxOperation.KILL, 1, null, null, null, null, null, xid, null, null, null), false));
}
Also used : VisorTxTaskArg(org.apache.ignite.internal.visor.tx.VisorTxTaskArg) IgniteCompute(org.apache.ignite.IgniteCompute) VisorTxTask(org.apache.ignite.internal.visor.tx.VisorTxTask)

Example 2 with VisorTxTask

use of org.apache.ignite.internal.visor.tx.VisorTxTask 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 VisorTxTask

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

the class TransactionsMXBeanImpl method getActiveTransactions.

/**
 * {@inheritDoc}
 */
@Override
public String getActiveTransactions(Long minDuration, Integer minSize, String prj, String consistentIds, String xid, String lbRegex, Integer limit, String order, boolean detailed, boolean kill) {
    try {
        IgniteCompute compute = ctx.cluster().get().compute();
        VisorTxProjection proj = null;
        if (prj != null) {
            if ("clients".equals(prj))
                proj = VisorTxProjection.CLIENT;
            else if ("servers".equals(prj))
                proj = VisorTxProjection.SERVER;
        }
        List<String> consIds = null;
        if (consistentIds != null)
            consIds = Arrays.stream(consistentIds.split(",")).collect(Collectors.toList());
        VisorTxSortOrder sortOrder = null;
        if (order != null)
            sortOrder = VisorTxSortOrder.valueOf(order.toUpperCase());
        VisorTxTaskArg arg = new VisorTxTaskArg(kill ? VisorTxOperation.KILL : VisorTxOperation.LIST, limit, minDuration == null ? null : minDuration * 1000, minSize, null, proj, consIds, xid, lbRegex, sortOrder, null);
        Map<ClusterNode, VisorTxTaskResult> res = compute.execute(new VisorTxTask(), new VisorTaskArgument<>(ctx.cluster().get().localNode().id(), arg, false));
        if (detailed) {
            StringWriter sw = new StringWriter();
            PrintWriter w = new PrintWriter(sw);
            for (Map.Entry<ClusterNode, VisorTxTaskResult> entry : res.entrySet()) {
                if (entry.getValue().getInfos().isEmpty())
                    continue;
                ClusterNode key = entry.getKey();
                w.println(key.toString());
                for (VisorTxInfo info : entry.getValue().getInfos()) w.println(info.toUserString());
            }
            w.flush();
            return sw.toString();
        } else {
            int cnt = 0;
            for (VisorTxTaskResult result : res.values()) cnt += result.getInfos().size();
            return Integer.toString(cnt);
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) VisorTxTaskArg(org.apache.ignite.internal.visor.tx.VisorTxTaskArg) VisorTxProjection(org.apache.ignite.internal.visor.tx.VisorTxProjection) VisorTxSortOrder(org.apache.ignite.internal.visor.tx.VisorTxSortOrder) StringWriter(java.io.StringWriter) VisorTxInfo(org.apache.ignite.internal.visor.tx.VisorTxInfo) VisorTxTaskResult(org.apache.ignite.internal.visor.tx.VisorTxTaskResult) Map(java.util.Map) IgniteCompute(org.apache.ignite.IgniteCompute) VisorTxTask(org.apache.ignite.internal.visor.tx.VisorTxTask) PrintWriter(java.io.PrintWriter)

Aggregations

VisorTxTask (org.apache.ignite.internal.visor.tx.VisorTxTask)3 VisorTxTaskArg (org.apache.ignite.internal.visor.tx.VisorTxTaskArg)3 Map (java.util.Map)2 IgniteCompute (org.apache.ignite.IgniteCompute)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 VisorTxInfo (org.apache.ignite.internal.visor.tx.VisorTxInfo)2 VisorTxTaskResult (org.apache.ignite.internal.visor.tx.VisorTxTaskResult)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CacheException (javax.cache.CacheException)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 Event (org.apache.ignite.events.Event)1 IgniteFutureCancelledCheckedException (org.apache.ignite.internal.IgniteFutureCancelledCheckedException)1