use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridDhtCacheAdapter method updateTtl.
/**
* @param cache Cache.
* @param keys Entries keys.
* @param vers Entries versions.
* @param ttl TTL.
*/
private void updateTtl(GridCacheAdapter<K, V> cache, List<KeyCacheObject> keys, List<GridCacheVersion> vers, long ttl) {
assert !F.isEmpty(keys);
assert keys.size() == vers.size();
int size = keys.size();
for (int i = 0; i < size; i++) {
try {
GridCacheEntryEx entry = null;
try {
while (true) {
try {
entry = cache.entryEx(keys.get(i));
entry.unswap(false);
entry.updateTtl(vers.get(i), ttl);
break;
} catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Got removed entry: " + entry);
} catch (GridDhtInvalidPartitionException e) {
if (log.isDebugEnabled())
log.debug("Got GridDhtInvalidPartitionException: " + e);
break;
}
}
} finally {
if (entry != null)
cache.context().evicts().touch(entry, AffinityTopologyVersion.NONE);
}
} catch (IgniteCheckedException e) {
log.error("Failed to unswap entry.", e);
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridDhtTxLocalAdapter method mapExplicitLocks.
/**
* Map explicit locks.
*/
protected void mapExplicitLocks() {
if (!mapped) {
// Explicit locks may participate in implicit transactions only.
if (!implicit()) {
mapped = true;
return;
}
Map<ClusterNode, List<GridDhtCacheEntry>> dhtEntryMap = null;
Map<ClusterNode, List<GridDhtCacheEntry>> nearEntryMap = null;
for (IgniteTxEntry e : allEntries()) {
assert e.cached() != null;
GridCacheContext cacheCtx = e.cached().context();
if (cacheCtx.isNear())
continue;
if (e.cached().obsolete()) {
GridCacheEntryEx cached = cacheCtx.cache().entryEx(e.key(), topologyVersion());
e.cached(cached);
}
if (e.cached().detached() || e.cached().isLocal())
continue;
while (true) {
try {
// Map explicit locks.
if (e.explicitVersion() != null && !e.explicitVersion().equals(xidVer)) {
if (dhtEntryMap == null)
dhtEntryMap = new GridLeanMap<>();
if (nearEntryMap == null)
nearEntryMap = new GridLeanMap<>();
cacheCtx.dhtMap((GridDhtCacheEntry) e.cached(), e.explicitVersion(), log, dhtEntryMap, nearEntryMap);
}
break;
} catch (GridCacheEntryRemovedException ignore) {
GridCacheEntryEx cached = cacheCtx.cache().entryEx(e.key(), topologyVersion());
e.cached(cached);
}
}
}
if (!F.isEmpty(dhtEntryMap))
addDhtNodeEntryMapping(dhtEntryMap);
if (!F.isEmpty(nearEntryMap))
addNearNodeEntryMapping(nearEntryMap);
mapped = true;
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridDhtTxLocalAdapter method lockAllAsync.
/**
* @param cacheCtx Cache context.
* @param entries Entries to lock.
* @param msgId Message ID.
* @param read Read flag.
* @param createTtl TTL for create operation.
* @param accessTtl TTL for read operation.
* @param needRetVal Return value flag.
* @param skipStore Skip store flag.
* @return Lock future.
*/
@SuppressWarnings("ForLoopReplaceableByForEach")
IgniteInternalFuture<GridCacheReturn> lockAllAsync(GridCacheContext cacheCtx, List<GridCacheEntryEx> entries, long msgId, final boolean read, final boolean needRetVal, long createTtl, long accessTtl, boolean skipStore, boolean keepBinary) {
try {
checkValid();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
if (F.isEmpty(entries))
return new GridFinishedFuture<>(ret);
init();
onePhaseCommit(onePhaseCommit);
try {
Set<KeyCacheObject> skipped = null;
AffinityTopologyVersion topVer = topologyVersion();
GridDhtCacheAdapter dhtCache = cacheCtx.isNear() ? cacheCtx.near().dht() : cacheCtx.dht();
// Enlist locks into transaction.
for (int i = 0; i < entries.size(); i++) {
GridCacheEntryEx entry = entries.get(i);
KeyCacheObject key = entry.key();
IgniteTxEntry txEntry = entry(entry.txKey());
// First time access.
if (txEntry == null) {
GridDhtCacheEntry cached;
while (true) {
try {
cached = dhtCache.entryExx(key, topVer);
cached.unswap(read);
break;
} catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Get removed entry: " + key);
}
}
addActiveCache(dhtCache.context(), false);
txEntry = addEntry(NOOP, null, null, null, cached, null, CU.empty0(), false, -1L, -1L, null, skipStore, keepBinary);
if (read)
txEntry.ttl(accessTtl);
txEntry.cached(cached);
addReader(msgId, cached, txEntry, topVer);
} else {
if (skipped == null)
skipped = new GridLeanSet<>();
skipped.add(key);
}
}
assert pessimistic();
Collection<KeyCacheObject> keys = F.viewReadOnly(entries, CU.entry2Key());
// Acquire locks only after having added operation to the write set.
// Otherwise, during rollback we will not know whether locks need
// to be rolled back.
// Loose all skipped and previously locked (we cannot reenter locks here).
final Collection<KeyCacheObject> passedKeys = skipped != null ? F.view(keys, F0.notIn(skipped)) : keys;
if (log.isDebugEnabled())
log.debug("Lock keys: " + passedKeys);
return obtainLockAsync(cacheCtx, ret, passedKeys, read, needRetVal, createTtl, accessTtl, skipStore, keepBinary);
} catch (IgniteCheckedException e) {
setRollbackOnly();
return new GridFinishedFuture<>(e);
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridDhtTxPrepareFuture method addDhtValues.
/**
* @param res Response being sent.
*/
private void addDhtValues(GridNearTxPrepareResponse res) {
// Interceptor on near node needs old values to execute callbacks.
if (!F.isEmpty(writes)) {
for (IgniteTxEntry e : writes) {
IgniteTxEntry txEntry = tx.entry(e.txKey());
assert txEntry != null : "Missing tx entry for key [tx=" + tx + ", key=" + e.txKey() + ']';
GridCacheContext cacheCtx = txEntry.context();
while (true) {
try {
GridCacheEntryEx entry = txEntry.cached();
GridCacheVersion dhtVer = entry.version();
CacheObject val0 = entry.valueBytes();
if (val0 != null)
res.addOwnedValue(txEntry.txKey(), dhtVer, val0);
break;
} catch (GridCacheEntryRemovedException ignored) {
// Retry.
txEntry.cached(cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion()));
}
}
}
}
for (Map.Entry<IgniteTxKey, GridCacheVersion> ver : dhtVerMap.entrySet()) {
IgniteTxEntry txEntry = tx.entry(ver.getKey());
if (res.hasOwnedValue(ver.getKey()))
continue;
assert txEntry != null : ver;
GridCacheContext cacheCtx = txEntry.context();
while (true) {
try {
GridCacheEntryEx entry = txEntry.cached();
GridCacheVersion dhtVer = entry.version();
if (ver.getValue() == null || !ver.getValue().equals(dhtVer)) {
CacheObject val0 = entry.valueBytes();
res.addOwnedValue(txEntry.txKey(), dhtVer, val0);
}
break;
} catch (GridCacheEntryRemovedException ignored) {
// Retry.
txEntry.cached(cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion()));
}
}
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridDistributedTxRemoteAdapter method doneRemote.
/**
* Adds completed versions to an entry.
*
* @param txEntry Entry.
* @param baseVer Base version for completed versions.
* @param committedVers Completed versions relative to base version.
* @param rolledbackVers Rolled back versions relative to base version.
* @param pendingVers Pending versions.
*/
private void doneRemote(IgniteTxEntry txEntry, GridCacheVersion baseVer, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers, Collection<GridCacheVersion> pendingVers) {
while (true) {
GridDistributedCacheEntry entry = (GridDistributedCacheEntry) txEntry.cached();
try {
// Handle explicit locks.
GridCacheVersion doneVer = txEntry.explicitVersion() != null ? txEntry.explicitVersion() : xidVer;
entry.doneRemote(doneVer, baseVer, pendingVers, committedVers, rolledbackVers, isSystemInvalidate());
break;
} catch (GridCacheEntryRemovedException ignored) {
assert entry.obsoleteVersion() != null;
if (log.isDebugEnabled())
log.debug("Replacing obsolete entry in remote transaction [entry=" + entry + ", tx=" + this + ']');
// Replace the entry.
txEntry.cached(txEntry.context().cache().entryEx(txEntry.key(), topologyVersion()));
}
}
}
Aggregations