Search in sources :

Example 11 with GridCacheMapEntry

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

the class GridDhtLocalPartition method clearAll.

/**
     * Clears values for this partition.
     *
     * @throws NodeStoppingException If node stopping.
     */
public void clearAll() throws NodeStoppingException {
    GridCacheVersion clearVer = cctx.versions().next();
    boolean rec = cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
    Iterator<GridCacheMapEntry> it = allEntries().iterator();
    GridCacheObsoleteEntryExtras extras = new GridCacheObsoleteEntryExtras(clearVer);
    while (it.hasNext()) {
        GridCacheMapEntry cached = null;
        cctx.shared().database().checkpointReadLock();
        try {
            cached = it.next();
            if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry) cached).clearInternal(clearVer, extras)) {
                removeEntry(cached);
                if (!cached.isInternal()) {
                    if (rec) {
                        cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), (IgniteUuid) null, null, EVT_CACHE_REBALANCE_OBJECT_UNLOADED, null, false, cached.rawGet(), cached.hasValue(), null, null, null, false);
                    }
                }
            }
        } catch (GridDhtInvalidPartitionException e) {
            assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']';
            // Partition is already concurrently cleared and evicted.
            break;
        } catch (NodeStoppingException e) {
            if (log.isDebugEnabled())
                log.debug("Failed to clear cache entry for evicted partition: " + cached.partition());
            rent.onDone(e);
            throw e;
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to clear cache entry for evicted partition: " + cached, e);
        } finally {
            cctx.shared().database().checkpointReadUnlock();
        }
    }
    if (!cctx.allowFastEviction()) {
        try {
            GridIterator<CacheDataRow> it0 = cctx.offheap().iterator(id);
            while (it0.hasNext()) {
                cctx.shared().database().checkpointReadLock();
                try {
                    CacheDataRow row = it0.next();
                    GridCacheMapEntry cached = putEntryIfObsoleteOrAbsent(cctx.affinity().affinityTopologyVersion(), row.key(), true, false);
                    if (cached instanceof GridDhtCacheEntry && ((GridDhtCacheEntry) cached).clearInternal(clearVer, extras)) {
                        if (rec) {
                            cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(), (IgniteUuid) null, null, EVT_CACHE_REBALANCE_OBJECT_UNLOADED, null, false, cached.rawGet(), cached.hasValue(), null, null, null, false);
                        }
                    }
                } catch (GridDhtInvalidPartitionException e) {
                    assert isEmpty() && state() == EVICTED : "Invalid error [e=" + e + ", part=" + this + ']';
                    // Partition is already concurrently cleared and evicted.
                    break;
                } finally {
                    cctx.shared().database().checkpointReadUnlock();
                }
            }
        } catch (NodeStoppingException e) {
            if (log.isDebugEnabled())
                log.debug("Failed to get iterator for evicted partition: " + id);
            rent.onDone(e);
            throw e;
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to get iterator for evicted partition: " + id, e);
        }
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheObsoleteEntryExtras(org.apache.ignite.internal.processors.cache.extras.GridCacheObsoleteEntryExtras) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry)

Example 12 with GridCacheMapEntry

use of org.apache.ignite.internal.processors.cache.GridCacheMapEntry 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, 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.key())) {
                    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)

Example 13 with GridCacheMapEntry

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

the class IgnitePartitionedQueueNoBackupsTest method testCollocation.

/**
     * @throws Exception If failed.
     */
public void testCollocation() throws Exception {
    IgniteQueue<Integer> queue = grid(0).queue("queue", 0, config(true));
    for (int i = 0; i < 1000; i++) assertTrue(queue.add(i));
    assertEquals(1000, queue.size());
    GridCacheContext cctx = GridTestUtils.getFieldValue(queue, "cctx");
    UUID setNodeId = null;
    for (int i = 0; i < gridCount(); i++) {
        IgniteKernal grid = (IgniteKernal) grid(i);
        Iterator<GridCacheMapEntry> entries = grid.context().cache().internalCache(cctx.name()).map().entries().iterator();
        if (entries.hasNext()) {
            if (setNodeId == null)
                setNodeId = grid.localNode().id();
            else
                fail("For collocated queue all items should be stored on single node.");
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) UUID(java.util.UUID)

Example 14 with GridCacheMapEntry

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

the class IgnitePartitionedSetNoBackupsSelfTest method testCollocation.

/**
     * @throws Exception If failed.
     */
public void testCollocation() throws Exception {
    Set<Integer> set0 = grid(0).set(SET_NAME, config(true));
    for (int i = 0; i < 1000; i++) assertTrue(set0.add(i));
    assertEquals(1000, set0.size());
    GridCacheContext cctx = GridTestUtils.getFieldValue(set0, "cctx");
    UUID setNodeId = null;
    for (int i = 0; i < gridCount(); i++) {
        IgniteKernal grid = (IgniteKernal) grid(i);
        Iterator<GridCacheMapEntry> entries = grid.context().cache().internalCache(cctx.name()).map().entries().iterator();
        if (entries.hasNext()) {
            if (setNodeId == null)
                setNodeId = grid.localNode().id();
            else
                fail("For collocated set all items should be stored on single node.");
        }
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheMapEntry(org.apache.ignite.internal.processors.cache.GridCacheMapEntry) UUID(java.util.UUID)

Aggregations

GridCacheMapEntry (org.apache.ignite.internal.processors.cache.GridCacheMapEntry)14 ArrayList (java.util.ArrayList)5 IgniteKernal (org.apache.ignite.internal.IgniteKernal)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)4 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)4 HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Ignite (org.apache.ignite.Ignite)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IgniteCache (org.apache.ignite.IgniteCache)2 IgniteException (org.apache.ignite.IgniteException)2