Search in sources :

Example 1 with GridDhtColocatedLockFuture

use of org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture in project ignite by apache.

the class IgniteTxManager method txLocksInfo.

/**
 * @param txKeys Tx keys.
 * @return Transactions locks and nodes.
 */
private TxLocksResponse txLocksInfo(Collection<IgniteTxKey> txKeys) {
    TxLocksResponse res = new TxLocksResponse();
    Collection<IgniteInternalTx> txs = activeTransactions();
    for (IgniteInternalTx tx : txs) {
        boolean nearTxLoc = tx instanceof GridNearTxLocal;
        if (!(nearTxLoc || tx instanceof GridDhtTxLocal) || !hasKeys(tx, txKeys))
            continue;
        IgniteTxState state = tx.txState();
        assert state instanceof IgniteTxStateImpl || state instanceof IgniteTxImplicitSingleStateImpl;
        Collection<IgniteTxEntry> txEntries = state instanceof IgniteTxStateImpl ? ((IgniteTxStateImpl) state).allEntriesCopy() : state.allEntries();
        Set<IgniteTxKey> requestedKeys = null;
        // in order to reduce amount of requests to remote nodes.
        if (nearTxLoc) {
            if (tx.pessimistic()) {
                GridDhtColocatedLockFuture fut = (GridDhtColocatedLockFuture) mvccFuture(tx, GridDhtColocatedLockFuture.class);
                if (fut != null)
                    requestedKeys = fut.requestedKeys();
                GridNearLockFuture nearFut = (GridNearLockFuture) mvccFuture(tx, GridNearLockFuture.class);
                if (nearFut != null) {
                    Set<IgniteTxKey> nearRequestedKeys = nearFut.requestedKeys();
                    if (nearRequestedKeys != null) {
                        if (requestedKeys == null)
                            requestedKeys = nearRequestedKeys;
                        else
                            requestedKeys = nearRequestedKeys;
                    }
                }
            } else {
                GridNearOptimisticTxPrepareFuture fut = (GridNearOptimisticTxPrepareFuture) mvccFuture(tx, GridNearOptimisticTxPrepareFuture.class);
                if (fut != null)
                    requestedKeys = fut.requestedKeys();
            }
        }
        for (IgniteTxEntry txEntry : txEntries) {
            IgniteTxKey txKey = txEntry.txKey();
            if (res.txLocks(txKey) == null) {
                GridCacheMapEntry e = (GridCacheMapEntry) txEntry.cached();
                List<GridCacheMvccCandidate> locs = e.mvccAllLocal();
                if (locs != null) {
                    boolean owner = false;
                    for (GridCacheMvccCandidate loc : locs) {
                        if (!owner && loc.owner() && loc.tx())
                            owner = true;
                        if (// Skip all candidates in case when no tx that owns lock.
                        !owner)
                            break;
                        if (loc.tx()) {
                            UUID nearNodeId = loc.otherNodeId();
                            GridCacheVersion txId = loc.otherVersion();
                            TxLock txLock = new TxLock(txId == null ? loc.version() : txId, nearNodeId == null ? loc.nodeId() : nearNodeId, // We can get outdated value of thread ID, but this value only for information here.
                            loc.threadId(), loc.owner() ? TxLock.OWNERSHIP_OWNER : TxLock.OWNERSHIP_CANDIDATE);
                            res.addTxLock(txKey, txLock);
                        }
                    }
                } else // Special case for optimal sequence of nodes processing.
                if (nearTxLoc && requestedKeys != null && requestedKeys.contains(txKey)) {
                    TxLock txLock = new TxLock(tx.nearXidVersion(), tx.nodeId(), tx.threadId(), TxLock.OWNERSHIP_REQUESTED);
                    res.addTxLock(txKey, txLock);
                } else
                    res.addKey(txKey);
            }
        }
    }
    return res;
}
Also used : GridDhtTxLocal(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxLocal) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) GridNearLockFuture(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockFuture) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridDhtColocatedLockFuture(org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture) GridNearOptimisticTxPrepareFuture(org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFuture) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) UUID(java.util.UUID) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Aggregations

UUID (java.util.UUID)1 GridCacheMapEntry (org.apache.ignite.internal.processors.cache.GridCacheMapEntry)1 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)1 GridDhtTxLocal (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxLocal)1 GridDhtColocatedLockFuture (org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedLockFuture)1 GridNearLockFuture (org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockFuture)1 GridNearOptimisticTxPrepareFuture (org.apache.ignite.internal.processors.cache.distributed.near.GridNearOptimisticTxPrepareFuture)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)1