Search in sources :

Example 1 with IgniteTxStateImpl

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

Aggregations

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 IgniteTxState (org.apache.ignite.internal.processors.cache.transactions.IgniteTxState)1 IgniteTxStateImpl (org.apache.ignite.internal.processors.cache.transactions.IgniteTxStateImpl)1