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));
}
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);
}
}
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);
}
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();
}
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());
}
}
Aggregations