Search in sources :

Example 1 with IgniteTxManager

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();
    }
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager)

Example 2 with IgniteTxManager

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()));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with IgniteTxManager

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);
    }
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 4 with IgniteTxManager

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);
}
Also used : CacheJtaManagerAdapter(org.apache.ignite.internal.processors.cache.jta.CacheJtaManagerAdapter) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.database.IgniteCacheDatabaseSharedManager)

Example 5 with IgniteTxManager

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()));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridNearCacheAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) IgniteException(org.apache.ignite.IgniteException) Transaction(org.apache.ignite.transactions.Transaction) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)

Aggregations

IgniteTxManager (org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager)9 IgniteKernal (org.apache.ignite.internal.IgniteKernal)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 IgniteInternalTx (org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 Ignite (org.apache.ignite.Ignite)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteException (org.apache.ignite.IgniteException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)2 GridNearCacheAdapter (org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter)2 IgniteFutureTimeoutException (org.apache.ignite.lang.IgniteFutureTimeoutException)2 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)2 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)2 Transaction (org.apache.ignite.transactions.Transaction)2