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);
}
}
}
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;
}
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.");
}
}
}
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.");
}
}
}
Aggregations