use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager in project ignite by apache.
the class GridCachePartitionExchangeManager method dumpPendingObjects.
/**
* @param exchTopVer Exchange topology version.
*/
private void dumpPendingObjects(@Nullable AffinityTopologyVersion exchTopVer) {
IgniteTxManager tm = cctx.tm();
if (tm != null) {
U.warn(log, "Pending transactions:");
for (IgniteInternalTx tx : tm.activeTransactions()) {
if (exchTopVer != null) {
U.warn(log, ">>> [txVer=" + tx.topologyVersionSnapshot() + ", exchWait=" + tm.needWaitTransaction(tx, exchTopVer) + ", tx=" + tx + ']');
} else
U.warn(log, ">>> [txVer=" + tx.topologyVersionSnapshot() + ", tx=" + tx + ']');
}
}
GridCacheMvccManager mvcc = cctx.mvcc();
if (mvcc != null) {
U.warn(log, "Pending explicit locks:");
for (GridCacheExplicitLockSpan lockSpan : mvcc.activeExplicitLocks()) U.warn(log, ">>> " + lockSpan);
U.warn(log, "Pending cache futures:");
for (GridCacheFuture<?> fut : mvcc.activeFutures()) U.warn(log, ">>> " + fut);
U.warn(log, "Pending atomic cache futures:");
for (GridCacheFuture<?> fut : mvcc.atomicFutures()) U.warn(log, ">>> " + fut);
U.warn(log, "Pending data streamer futures:");
for (IgniteInternalFuture<?> fut : mvcc.dataStreamerFutures()) U.warn(log, ">>> " + fut);
if (tm != null) {
U.warn(log, "Pending transaction deadlock detection futures:");
for (IgniteInternalFuture<?> fut : tm.deadlockDetectionFutures()) U.warn(log, ">>> " + fut);
}
}
for (GridCacheContext ctx : cctx.cacheContexts()) {
if (ctx.isLocal())
continue;
GridCacheContext ctx0 = ctx.isNear() ? ctx.near().dht().context() : ctx;
GridCachePreloader preloader = ctx0.preloader();
if (preloader != null)
preloader.dumpDebugInfo();
GridCacheAffinityManager affMgr = ctx0.affinity();
if (affMgr != null)
affMgr.dumpDebugInfo();
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager in project ignite by apache.
the class IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest method testTxOriginatingNodeFails.
/**
* @param keys Keys to update.
* @param fullFailure Flag indicating whether to simulate rollback state.
* @throws Exception If failed.
*/
protected void testTxOriginatingNodeFails(Collection<Integer> keys, final boolean fullFailure) throws Exception {
assertFalse(keys.isEmpty());
final Collection<IgniteKernal> grids = new ArrayList<>();
ClusterNode txNode = grid(originatingNode()).localNode();
for (int i = 1; i < gridCount(); i++) grids.add((IgniteKernal) grid(i));
failingNodeId = grid(0).localNode().id();
final Map<Integer, String> map = new HashMap<>();
final String initVal = "initialValue";
for (Integer key : keys) {
grid(originatingNode()).cache(DEFAULT_CACHE_NAME).put(key, initVal);
map.put(key, String.valueOf(key));
}
Map<Integer, Collection<ClusterNode>> nodeMap = new HashMap<>();
info("Node being checked: " + grid(1).localNode().id());
for (Integer key : keys) {
Collection<ClusterNode> nodes = new ArrayList<>();
nodes.addAll(grid(1).affinity(DEFAULT_CACHE_NAME).mapKeyToPrimaryAndBackups(key));
nodes.remove(txNode);
nodeMap.put(key, nodes);
}
info("Starting tx [values=" + map + ", topVer=" + ((IgniteKernal) grid(1)).context().discovery().topologyVersion() + ']');
if (fullFailure)
ignoreMessages(ignoreMessageClasses(), F.asList(grid(1).localNode().id()));
final IgniteEx originatingNodeGrid = grid(originatingNode());
GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
IgniteCache<Integer, String> cache = originatingNodeGrid.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
Transaction tx = originatingNodeGrid.transactions().txStart();
assertEquals(PESSIMISTIC, tx.concurrency());
try {
cache.putAll(map);
info("Before commitAsync");
IgniteFuture<?> fut = tx.commitAsync();
info("Got future for commitAsync().");
fut.get(3, TimeUnit.SECONDS);
} catch (IgniteFutureTimeoutException ignored) {
info("Failed to wait for commit future completion [fullFailure=" + fullFailure + ']');
}
return null;
}
}).get();
info(">>> Stopping originating node " + txNode);
G.stop(grid(originatingNode()).name(), true);
ignoreMessages(Collections.<Class<?>>emptyList(), Collections.<UUID>emptyList());
info(">>> Stopped originating node: " + txNode.id());
boolean txFinished = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (IgniteKernal g : grids) {
GridCacheAdapter<?, ?> cache = g.internalCache(DEFAULT_CACHE_NAME);
IgniteTxManager txMgr = cache.isNear() ? ((GridNearCacheAdapter) cache).dht().context().tm() : cache.context().tm();
int txNum = txMgr.idMapSize();
if (txNum != 0)
return false;
}
return true;
}
}, 10000);
assertTrue(txFinished);
info("Transactions finished.");
for (Map.Entry<Integer, Collection<ClusterNode>> e : nodeMap.entrySet()) {
final Integer key = e.getKey();
final String val = map.get(key);
assertFalse(e.getValue().isEmpty());
for (ClusterNode node : e.getValue()) {
final UUID checkNodeId = node.id();
compute(G.ignite(checkNodeId).cluster().forNode(node)).call(new IgniteCallable<Void>() {
/** */
@IgniteInstanceResource
private Ignite ignite;
@Override
public Void call() throws Exception {
IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
assertEquals("Failed to check entry value on node: " + checkNodeId, fullFailure ? initVal : val, cache.localPeek(key));
return null;
}
});
}
}
for (Map.Entry<Integer, String> e : map.entrySet()) {
for (Ignite g : G.allGrids()) assertEquals(fullFailure ? initVal : e.getValue(), g.cache(DEFAULT_CACHE_NAME).get(e.getKey()));
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager in project ignite by apache.
the class GridCachePartitionExchangeManager method dumpLongRunningOperations.
/**
* @param timeout Operation timeout.
*/
public void dumpLongRunningOperations(long timeout) {
try {
GridDhtPartitionsExchangeFuture lastFut = lastInitializedFut;
// If exchange is in progress it will dump all hanging operations if any.
if (lastFut != null && !lastFut.isDone())
return;
long curTime = U.currentTimeMillis();
boolean found = false;
IgniteTxManager tm = cctx.tm();
if (tm != null) {
for (IgniteInternalTx tx : tm.activeTransactions()) {
if (curTime - tx.startTime() > timeout) {
found = true;
if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) {
U.warn(log, "Found long running transaction [startTime=" + formatTime(tx.startTime()) + ", curTime=" + formatTime(curTime) + ", tx=" + tx + ']');
} else
break;
}
}
}
GridCacheMvccManager mvcc = cctx.mvcc();
if (mvcc != null) {
for (GridCacheFuture<?> fut : mvcc.activeFutures()) {
if (curTime - fut.startTime() > timeout) {
found = true;
if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) {
U.warn(log, "Found long running cache future [startTime=" + formatTime(fut.startTime()) + ", curTime=" + formatTime(curTime) + ", fut=" + fut + ']');
} else
break;
}
}
for (GridCacheFuture<?> fut : mvcc.atomicFutures()) {
if (curTime - fut.startTime() > timeout) {
found = true;
if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) {
U.warn(log, "Found long running cache future [startTime=" + formatTime(fut.startTime()) + ", curTime=" + formatTime(curTime) + ", fut=" + fut + ']');
} else
break;
}
}
}
if (found) {
if (longRunningOpsDumpCnt < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) {
longRunningOpsDumpCnt++;
if (IgniteSystemProperties.getBoolean(IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT, false)) {
U.warn(log, "Found long running cache operations, dump threads.");
U.dumpThreads(log);
}
U.warn(log, "Found long running cache operations, dump IO statistics.");
// Dump IO manager statistics.
cctx.gridIO().dumpStats();
}
} else
longRunningOpsDumpCnt = 0;
} catch (Exception e) {
U.error(log, "Failed to dump debug information: " + e, e);
}
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager in project ignite by apache.
the class GridCacheProcessor method createSharedContext.
/**
* Creates shared context.
*
* @param kernalCtx Kernal context.
* @param storeSesLsnrs Store session listeners.
* @return Shared context.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("unchecked")
private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, Collection<CacheStoreSessionListener> storeSesLsnrs) throws IgniteCheckedException {
IgniteTxManager tm = new IgniteTxManager();
GridCacheMvccManager mvccMgr = new GridCacheMvccManager();
GridCacheVersionManager verMgr = new GridCacheVersionManager();
GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager();
GridCachePartitionExchangeManager exchMgr = new GridCachePartitionExchangeManager();
IgniteCacheDatabaseSharedManager dbMgr = ctx.plugins().createComponent(IgniteCacheDatabaseSharedManager.class);
if (dbMgr == null)
dbMgr = new IgniteCacheDatabaseSharedManager();
IgnitePageStoreManager pageStoreMgr = ctx.plugins().createComponent(IgnitePageStoreManager.class);
IgniteWriteAheadLogManager walMgr = ctx.plugins().createComponent(IgniteWriteAheadLogManager.class);
GridCacheIoManager ioMgr = new GridCacheIoManager();
CacheAffinitySharedManager topMgr = new CacheAffinitySharedManager();
GridCacheSharedTtlCleanupManager ttl = new GridCacheSharedTtlCleanupManager();
CacheJtaManagerAdapter jta = JTA.createOptional();
return new GridCacheSharedContext(kernalCtx, tm, verMgr, mvccMgr, pageStoreMgr, walMgr, dbMgr, depMgr, exchMgr, topMgr, ioMgr, ttl, jta, storeSesLsnrs);
}
use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager in project ignite by apache.
the class IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest method checkPrimaryNodeCrash.
/**
* Checks tx data consistency in case when primary node crashes.
*
* @param commmit Whether to commit or rollback a transaction.
* @throws Exception If failed.
*/
private void checkPrimaryNodeCrash(final boolean commmit) throws Exception {
Set<Integer> keys = new HashSet<>();
for (int i = 0; i < 20; i++) keys.add(i);
final Collection<IgniteKernal> grids = new ArrayList<>();
ClusterNode primaryNode = grid(1).localNode();
for (int i = 0; i < gridCount(); i++) {
if (i != 1)
grids.add((IgniteKernal) grid(i));
}
failingNodeId = primaryNode.id();
final Map<Integer, String> map = new HashMap<>();
final String initVal = "initialValue";
for (Integer key : keys) {
grid(originatingNode()).cache(DEFAULT_CACHE_NAME).put(key, initVal);
map.put(key, String.valueOf(key));
}
Map<Integer, Collection<ClusterNode>> nodeMap = new HashMap<>();
IgniteCache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME);
info("Failing node ID: " + grid(1).localNode().id());
for (Integer key : keys) {
Collection<ClusterNode> nodes = new ArrayList<>();
nodes.addAll(affinity(cache).mapKeyToPrimaryAndBackups(key));
nodes.remove(primaryNode);
nodeMap.put(key, nodes);
}
info("Starting tx [values=" + map + ", topVer=" + grid(1).context().discovery().topologyVersion() + ']');
assertNotNull(cache);
try (Transaction tx = grid(0).transactions().txStart()) {
cache.getAll(keys);
// Should not send any messages.
cache.putAll(map);
TransactionProxyImpl txProxy = (TransactionProxyImpl) tx;
GridNearTxLocal txEx = txProxy.tx();
assertTrue(txEx.pessimistic());
if (commmit) {
txEx.prepare();
// Fail the node in the middle of transaction.
info(">>> Stopping primary node " + primaryNode);
G.stop(Ignition.ignite(primaryNode.id()).name(), true);
info(">>> Stopped originating node, finishing transaction: " + primaryNode.id());
tx.commit();
} else {
// Fail the node in the middle of transaction.
info(">>> Stopping primary node " + primaryNode);
G.stop(G.ignite(primaryNode.id()).name(), true);
info(">>> Stopped originating node, finishing transaction: " + primaryNode.id());
tx.rollback();
}
}
boolean txFinished = GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
for (IgniteKernal g : grids) {
GridCacheAdapter<?, ?> cache = g.internalCache(DEFAULT_CACHE_NAME);
IgniteTxManager txMgr = cache.isNear() ? ((GridNearCacheAdapter) cache).dht().context().tm() : cache.context().tm();
int txNum = txMgr.idMapSize();
if (txNum != 0)
return false;
}
return true;
}
}, 10000);
assertTrue(txFinished);
info("Transactions finished.");
for (Map.Entry<Integer, Collection<ClusterNode>> e : nodeMap.entrySet()) {
final Integer key = e.getKey();
final String val = map.get(key);
assertFalse(e.getValue().isEmpty());
for (ClusterNode node : e.getValue()) {
final UUID checkNodeId = node.id();
compute(G.ignite(checkNodeId).cluster().forNode(node)).call(new IgniteCallable<Void>() {
/** */
@IgniteInstanceResource
private Ignite ignite;
@Override
public Void call() throws Exception {
IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
assertNotNull(cache);
assertEquals("Failed to check entry value on node: " + checkNodeId, !commmit ? initVal : val, cache.localPeek(key));
return null;
}
});
}
}
for (Map.Entry<Integer, String> e : map.entrySet()) {
for (Ignite g : G.allGrids()) assertEquals(!commmit ? initVal : e.getValue(), g.cache(DEFAULT_CACHE_NAME).get(e.getKey()));
}
}
Aggregations