Search in sources :

Example 11 with IgniteInternalTx

use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.

the class CacheTxFastFinishTest method checkFastTxFinish.

/**
     * @param tx Transaction.
     * @param commit Commit flag.
     */
private void checkFastTxFinish(Transaction tx, boolean commit) {
    if (commit)
        tx.commit();
    else
        tx.rollback();
    IgniteInternalTx tx0 = ((TransactionProxyImpl) tx).tx();
    assertNull(fieldValue(tx0, "prepFut"));
    assertNull(fieldValue(tx0, "commitFut"));
    assertNull(fieldValue(tx0, "rollbackFut"));
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)

Example 12 with IgniteInternalTx

use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.

the class GridHashMapLoadTest method testMapEntry.

/**
     * @throws Exception If failed.
     */
public void testMapEntry() throws Exception {
    Map<Integer, GridCacheMapEntry> map = new HashMap<>(5 * 1024 * 1024);
    int i = 0;
    GridCacheTestContext<Integer, Integer> ctx = new GridCacheTestContext<>(new GridTestKernalContext(new GridTestLog4jLogger()));
    while (true) {
        Integer key = i++;
        map.put(key, new GridCacheMapEntry(ctx, ctx.toCacheKeyObject(key)) {

            @Override
            public boolean tmLock(IgniteInternalTx tx, long timeout, @Nullable GridCacheVersion serOrder, GridCacheVersion serReadVer, boolean read) {
                return false;
            }

            @Override
            protected void checkThreadChain(GridCacheMvccCandidate owner) {
            // No-op.
            }

            @Override
            public void txUnlock(IgniteInternalTx tx) {
            // No-op.
            }

            @Override
            public boolean removeLock(GridCacheVersion ver) {
                return false;
            }
        });
        if (i % 100000 == 0)
            info("Inserted objects: " + i / 2);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 13 with IgniteInternalTx

use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.

the class GridCacheNearTxMultiNodeSelfTest method checkTm.

/**
     * @param g Grid.
     * @param tm Transaction manager.
     */
@SuppressWarnings({ "unchecked" })
private void checkTm(Ignite g, IgniteTxManager tm) {
    Collection<IgniteInternalTx> txs = tm.txs();
    info(">>> Number of transactions in the set [size=" + txs.size() + ", nodeId=" + g.cluster().localNode().id() + ']');
    for (IgniteInternalTx tx : txs) assert tx.done() : "Transaction is not finished: " + tx;
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)

Example 14 with IgniteInternalTx

use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx in project ignite by apache.

the class GridDhtCacheEntry method addReader.

/**
     * @param nodeId Reader to add.
     * @param msgId Message ID.
     * @param topVer Topology version.
     * @return Future for all relevant transactions that were active at the time of adding reader,
     *      or {@code null} if reader was added
     * @throws GridCacheEntryRemovedException If entry was removed.
     */
@SuppressWarnings("unchecked")
@Nullable
public IgniteInternalFuture<Boolean> addReader(UUID nodeId, long msgId, AffinityTopologyVersion topVer) throws GridCacheEntryRemovedException {
    // Don't add local node as reader.
    if (cctx.nodeId().equals(nodeId))
        return null;
    ClusterNode node = cctx.discovery().node(nodeId);
    if (node == null) {
        if (log.isDebugEnabled())
            log.debug("Ignoring near reader because node left the grid: " + nodeId);
        return null;
    }
    // If remote node has no near cache, don't add it.
    if (!cctx.discovery().cacheNearNode(node, cacheName())) {
        if (log.isDebugEnabled())
            log.debug("Ignoring near reader because near cache is disabled: " + nodeId);
        return null;
    }
    // If remote node is (primary?) or back up, don't add it as a reader.
    if (cctx.affinity().partitionBelongs(node, partition(), topVer)) {
        if (log.isDebugEnabled())
            log.debug("Ignoring near reader because remote node is affinity node [locNodeId=" + cctx.localNodeId() + ", rmtNodeId=" + nodeId + ", key=" + key + ']');
        return null;
    }
    boolean ret = false;
    GridCacheMultiTxFuture txFut = null;
    Collection<GridCacheMvccCandidate> cands = null;
    ReaderId reader;
    synchronized (this) {
        checkObsolete();
        reader = readerId(nodeId);
        if (reader == null) {
            reader = new ReaderId(nodeId, msgId);
            ReaderId[] rdrs = Arrays.copyOf(this.rdrs, this.rdrs.length + 1);
            rdrs[rdrs.length - 1] = reader;
            // Seal.
            this.rdrs = rdrs;
            // No transactions in ATOMIC cache.
            if (!cctx.atomic()) {
                txFut = reader.getOrCreateTxFuture(cctx);
                cands = localCandidates();
                ret = true;
            }
        } else {
            txFut = reader.txFuture();
            long id = reader.messageId();
            if (id < msgId)
                reader.messageId(msgId);
        }
    }
    if (ret) {
        assert txFut != null;
        if (!F.isEmpty(cands)) {
            for (GridCacheMvccCandidate c : cands) {
                IgniteInternalTx tx = cctx.tm().tx(c.version());
                if (tx != null && tx.local())
                    txFut.addTx(tx);
            }
        }
        txFut.init();
        if (!txFut.isDone()) {
            final ReaderId reader0 = reader;
            txFut.listen(new CI1<IgniteInternalFuture<?>>() {

                @Override
                public void apply(IgniteInternalFuture<?> f) {
                    cctx.kernalContext().closure().runLocalSafe(new GridPlainRunnable() {

                        @Override
                        public void run() {
                            synchronized (this) {
                                // Release memory.
                                reader0.resetTxFuture();
                            }
                        }
                    });
                }
            });
        } else {
            synchronized (this) {
                // Release memory.
                reader.resetTxFuture();
            }
            txFut = null;
        }
    }
    return txFut;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) GridCacheMultiTxFuture(org.apache.ignite.internal.processors.cache.GridCacheMultiTxFuture) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with IgniteInternalTx

use of org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx 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)

Aggregations

IgniteInternalTx (org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)29 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 IgniteException (org.apache.ignite.IgniteException)3 IgfsPath (org.apache.ignite.igfs.IgfsPath)3 IgniteTxManager (org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager)3 TransactionProxyImpl (org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 HashMap (java.util.HashMap)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)2 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)2 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)2 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)2 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)2 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)2 IgniteTxHeuristicCheckedException (org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException)2