Search in sources :

Example 1 with IgniteTxState

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

the class GridCacheIoManager method processMessage.

/**
     * @param nodeId Node ID.
     * @param msg Message.
     * @param c Closure.
     */
private void processMessage(UUID nodeId, GridCacheMessage msg, IgniteBiInClosure<UUID, GridCacheMessage> c) {
    try {
        c.apply(nodeId, msg);
        if (log.isDebugEnabled())
            log.debug("Finished processing cache communication message [nodeId=" + nodeId + ", msg=" + msg + ']');
    } catch (Throwable e) {
        U.error(log, "Failed processing message [senderId=" + nodeId + ", msg=" + msg + ']', e);
        if (e instanceof Error)
            throw e;
    } finally {
        // Reset thread local context.
        cctx.tm().resetContext();
        GridCacheMvccManager mvcc = cctx.mvcc();
        if (mvcc != null)
            mvcc.contextReset();
        // Unwind eviction notifications.
        if (msg instanceof IgniteTxStateAware) {
            IgniteTxState txState = ((IgniteTxStateAware) msg).txState();
            if (txState != null)
                txState.unwindEvicts(cctx);
        } else {
            GridCacheContext ctx = cctx.cacheContext(msg.cacheId());
            if (ctx != null)
                CU.unwindEvicts(ctx);
        }
    }
}
Also used : IgniteTxStateAware(org.apache.ignite.internal.processors.cache.transactions.IgniteTxStateAware) IgniteTxState(org.apache.ignite.internal.processors.cache.transactions.IgniteTxState)

Example 2 with IgniteTxState

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

the class ContentionClosure method call.

/**
 * {@inheritDoc}
 */
@Override
public ContentionInfo call() throws Exception {
    final IgniteTxManager tm = ignite.context().cache().context().tm();
    final Collection<IgniteInternalTx> activeTxs = tm.activeTransactions();
    ContentionInfo ci = new ContentionInfo();
    ci.setNode(ignite.localNode());
    ci.setEntries(new ArrayList<>());
    for (IgniteInternalTx tx : activeTxs) {
        if (ci.getEntries().size() == maxPrint)
            break;
        // Show only primary txs.
        if (tx.local()) {
            IgniteTxLocalAdapter tx0 = (IgniteTxLocalAdapter) tx;
            final IgniteTxLocalState state0 = tx0.txState();
            if (!(state0 instanceof IgniteTxStateImpl))
                continue;
            final IgniteTxStateImpl state = (IgniteTxStateImpl) state0;
            final Collection<IgniteTxEntry> entries = state.allEntriesCopy();
            IgniteTxEntry bad = null;
            int qSize = 0;
            for (IgniteTxEntry entry : entries) {
                Collection<GridCacheMvccCandidate> locs;
                GridCacheEntryEx cached = entry.cached();
                while (true) {
                    try {
                        locs = cached.localCandidates();
                        break;
                    } catch (GridCacheEntryRemovedException ignored) {
                        cached = entry.context().cache().entryEx(entry.key());
                    }
                }
                if (locs != null)
                    qSize += locs.size();
                final Collection<GridCacheMvccCandidate> rmts = cached.remoteMvccSnapshot();
                if (rmts != null)
                    qSize += rmts.size();
                if (qSize >= minQueueSize) {
                    bad = entry;
                    break;
                } else
                    qSize = 0;
            }
            if (bad != null) {
                StringBuilder b = new StringBuilder();
                b.append("TxEntry [cacheId=").append(bad.cacheId()).append(", key=").append(bad.key()).append(", queue=").append(qSize).append(", op=").append(bad.op()).append(", val=").append(bad.value()).append(", tx=").append(CU.txString(tx)).append(", other=[");
                final IgniteTxState st = tx.txState();
                if (st instanceof IgniteTxStateImpl) {
                    IgniteTxStateImpl st0 = (IgniteTxStateImpl) st;
                    final Collection<IgniteTxEntry> cp = st0.allEntriesCopy();
                    for (IgniteTxEntry entry : cp) {
                        if (entry == bad)
                            continue;
                        b.append(entry.toString()).append('\n');
                    }
                }
                b.append("]]");
                ci.getEntries().add(b.toString());
            }
        }
    }
    return ci;
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) IgniteTxStateImpl(org.apache.ignite.internal.processors.cache.transactions.IgniteTxStateImpl) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) IgniteTxState(org.apache.ignite.internal.processors.cache.transactions.IgniteTxState) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteTxLocalAdapter(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteTxLocalState(org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalState) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 3 with IgniteTxState

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

the class GridCacheIoManager method onMessageProcessed.

/**
 * @param msg Message.
 */
public void onMessageProcessed(GridCacheMessage msg) {
    // Reset thread local context.
    cctx.tm().resetContext();
    GridCacheMvccManager mvcc = cctx.mvcc();
    if (mvcc != null)
        mvcc.contextReset();
    // Unwind eviction notifications.
    if (msg instanceof IgniteTxStateAware) {
        IgniteTxState txState = ((IgniteTxStateAware) msg).txState();
        if (txState != null)
            txState.unwindEvicts(cctx);
    } else if (msg instanceof GridCacheIdMessage) {
        GridCacheContext ctx = cctx.cacheContext(((GridCacheIdMessage) msg).cacheId());
        if (ctx != null)
            CU.unwindEvicts(ctx);
    }
}
Also used : IgniteTxStateAware(org.apache.ignite.internal.processors.cache.transactions.IgniteTxStateAware) IgniteTxState(org.apache.ignite.internal.processors.cache.transactions.IgniteTxState)

Aggregations

IgniteTxState (org.apache.ignite.internal.processors.cache.transactions.IgniteTxState)3 IgniteTxStateAware (org.apache.ignite.internal.processors.cache.transactions.IgniteTxStateAware)2 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)1 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)1 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)1 IgniteInternalTx (org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)1 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)1 IgniteTxLocalAdapter (org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter)1 IgniteTxLocalState (org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalState)1 IgniteTxManager (org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager)1 IgniteTxStateImpl (org.apache.ignite.internal.processors.cache.transactions.IgniteTxStateImpl)1