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