Search in sources :

Example 1 with VisorTxTaskArg

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

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

the class KillCommand method parseArguments.

/**
 * {@inheritDoc}
 */
@Override
public void parseArguments(CommandArgIterator argIter) {
    KillSubcommand cmd;
    try {
        cmd = KillSubcommand.valueOf(argIter.nextArg("Expected type of resource to kill.").toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Expected type of resource to kill.");
    }
    switch(cmd) {
        case COMPUTE:
            taskArgs = new VisorComputeCancelSessionTaskArg(IgniteUuid.fromString(argIter.nextArg("Expected compute task id.")));
            taskName = VisorComputeCancelSessionTask.class.getName();
            nodeId = null;
            break;
        case SERVICE:
            taskArgs = new VisorCancelServiceTaskArg(argIter.nextArg("Expected service name."));
            taskName = VisorCancelServiceTask.class.getName();
            nodeId = null;
            break;
        case TRANSACTION:
            String xid = argIter.nextArg("Expected transaction id.");
            taskArgs = new VisorTxTaskArg(VisorTxOperation.KILL, null, null, null, null, null, null, xid, null, null, null);
            taskName = VisorTxTask.class.getName();
            nodeId = null;
            break;
        case SQL:
            T2<UUID, Long> ids = parseGlobalQueryId(argIter.nextArg("Expected SQL query id."));
            if (ids == null)
                throw new IllegalArgumentException("Expected global query id. " + EXPECTED_GLOBAL_QRY_ID_FORMAT);
            taskArgs = new VisorQueryCancelOnInitiatorTaskArg(ids.get1(), ids.get2());
            taskName = VisorQueryCancelOnInitiatorTask.class.getName();
            nodeId = null;
            break;
        case SCAN:
            String originNodeIsStr = argIter.nextArg("Expected query originating node id.");
            UUID originNodeId = UUID.fromString(originNodeIsStr);
            String cacheName = argIter.nextArg("Expected cache name.");
            long qryId = Long.parseLong(argIter.nextArg("Expected query identifier."));
            taskArgs = new VisorScanQueryCancelTaskArg(originNodeId, cacheName, qryId);
            taskName = VisorScanQueryCancelTask.class.getName();
            nodeId = null;
            break;
        case CONTINUOUS:
            taskArgs = new VisorContinuousQueryCancelTaskArg(UUID.fromString(argIter.nextArg("Expected query originating node id.")), UUID.fromString(argIter.nextArg("Expected continuous query id.")));
            taskName = VisorContinuousQueryCancelTask.class.getName();
            nodeId = null;
            break;
        case SNAPSHOT:
            taskArgs = argIter.nextArg("Expected snapshot name.");
            taskName = VisorSnapshotCancelTask.class.getName();
            nodeId = null;
            break;
        case CONSISTENCY:
            taskName = VisorConsistencyCancelTask.class.getName();
            taskArgs = null;
            nodeId = BROADCAST_UUID;
            break;
        default:
            throw new IllegalArgumentException("Unknown kill subcommand: " + cmd);
    }
}
Also used : VisorContinuousQueryCancelTask(org.apache.ignite.internal.visor.query.VisorContinuousQueryCancelTask) VisorQueryCancelOnInitiatorTaskArg(org.apache.ignite.internal.visor.query.VisorQueryCancelOnInitiatorTaskArg) VisorContinuousQueryCancelTaskArg(org.apache.ignite.internal.visor.query.VisorContinuousQueryCancelTaskArg) VisorTxTaskArg(org.apache.ignite.internal.visor.tx.VisorTxTaskArg) VisorCancelServiceTask(org.apache.ignite.internal.visor.service.VisorCancelServiceTask) VisorQueryCancelOnInitiatorTask(org.apache.ignite.internal.visor.query.VisorQueryCancelOnInitiatorTask) VisorCancelServiceTaskArg(org.apache.ignite.internal.visor.service.VisorCancelServiceTaskArg) VisorScanQueryCancelTaskArg(org.apache.ignite.internal.visor.query.VisorScanQueryCancelTaskArg) VisorConsistencyCancelTask(org.apache.ignite.internal.visor.consistency.VisorConsistencyCancelTask) VisorComputeCancelSessionTask(org.apache.ignite.internal.visor.compute.VisorComputeCancelSessionTask) BROADCAST_UUID(org.apache.ignite.internal.commandline.TaskExecutor.BROADCAST_UUID) UUID(java.util.UUID) VisorScanQueryCancelTask(org.apache.ignite.internal.visor.query.VisorScanQueryCancelTask) VisorComputeCancelSessionTaskArg(org.apache.ignite.internal.visor.compute.VisorComputeCancelSessionTaskArg) VisorTxTask(org.apache.ignite.internal.visor.tx.VisorTxTask) VisorSnapshotCancelTask(org.apache.ignite.internal.visor.snapshot.VisorSnapshotCancelTask)

Example 3 with VisorTxTaskArg

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

the class TxCommands method parseArguments.

/**
 * @param argIter Argument iterator.
 */
@Override
public void parseArguments(CommandArgIterator argIter) {
    VisorTxProjection proj = null;
    Integer limit = null;
    VisorTxSortOrder sortOrder = null;
    Long duration = null;
    Integer size = null;
    String lbRegex = null;
    List<String> consistentIds = null;
    VisorTxOperation op = VisorTxOperation.LIST;
    String xid = null;
    TxVerboseId txVerboseId = null;
    while (true) {
        String str = argIter.peekNextArg();
        if (str == null)
            break;
        TxCommandArg arg = CommandArgUtils.of(str, TxCommandArg.class);
        if (arg == null)
            break;
        switch(arg) {
            case TX_LIMIT:
                argIter.nextArg("");
                limit = (int) argIter.nextNonNegativeLongArg(TxCommandArg.TX_LIMIT.toString());
                break;
            case TX_ORDER:
                argIter.nextArg("");
                sortOrder = VisorTxSortOrder.valueOf(argIter.nextArg(TxCommandArg.TX_ORDER.toString()).toUpperCase());
                break;
            case TX_SERVERS:
                argIter.nextArg("");
                proj = VisorTxProjection.SERVER;
                break;
            case TX_CLIENTS:
                argIter.nextArg("");
                proj = VisorTxProjection.CLIENT;
                break;
            case TX_NODES:
                argIter.nextArg("");
                Set<String> ids = argIter.nextStringSet(TxCommandArg.TX_NODES.toString());
                if (ids.isEmpty()) {
                    throw new IllegalArgumentException("Consistent id list is empty.");
                }
                consistentIds = new ArrayList<>(ids);
                break;
            case TX_DURATION:
                argIter.nextArg("");
                duration = argIter.nextNonNegativeLongArg(TxCommandArg.TX_DURATION.toString()) * 1000L;
                break;
            case TX_SIZE:
                argIter.nextArg("");
                size = (int) argIter.nextNonNegativeLongArg(TxCommandArg.TX_SIZE.toString());
                break;
            case TX_LABEL:
                argIter.nextArg("");
                lbRegex = argIter.nextArg(TxCommandArg.TX_LABEL.toString());
                try {
                    Pattern.compile(lbRegex);
                } catch (PatternSyntaxException ignored) {
                    throw new IllegalArgumentException("Illegal regex syntax");
                }
                break;
            case TX_XID:
                argIter.nextArg("");
                xid = argIter.nextArg(TxCommandArg.TX_XID.toString());
                break;
            case TX_KILL:
                argIter.nextArg("");
                op = VisorTxOperation.KILL;
                break;
            case TX_INFO:
                argIter.nextArg("");
                op = VisorTxOperation.INFO;
                txVerboseId = TxVerboseId.fromString(argIter.nextArg(TX_INFO.argName()));
                break;
            default:
                throw new AssertionError();
        }
    }
    if (proj != null && consistentIds != null)
        throw new IllegalArgumentException("Projection can't be used together with list of consistent ids.");
    this.args = new VisorTxTaskArg(op, limit, duration, size, null, proj, consistentIds, xid, lbRegex, sortOrder, txVerboseId);
}
Also used : TxVerboseId(org.apache.ignite.internal.visor.tx.TxVerboseId) VisorTxTaskArg(org.apache.ignite.internal.visor.tx.VisorTxTaskArg) VisorTxProjection(org.apache.ignite.internal.visor.tx.VisorTxProjection) VisorTxOperation(org.apache.ignite.internal.visor.tx.VisorTxOperation) VisorTxSortOrder(org.apache.ignite.internal.visor.tx.VisorTxSortOrder) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 4 with VisorTxTaskArg

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

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

VisorTxTaskArg (org.apache.ignite.internal.visor.tx.VisorTxTaskArg)6 VisorTxTask (org.apache.ignite.internal.visor.tx.VisorTxTask)4 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 VisorTxProjection (org.apache.ignite.internal.visor.tx.VisorTxProjection)2 VisorTxSortOrder (org.apache.ignite.internal.visor.tx.VisorTxSortOrder)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 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 CacheException (javax.cache.CacheException)1 Ignite (org.apache.ignite.Ignite)1