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