use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridNearTxLocal method loadMissing.
/**
* @param cacheCtx Cache context.
* @param keys Keys to load.
* @param filter Filter.
* @param ret Return value.
* @param needReadVer Read version flag.
* @param singleRmv {@code True} for single remove operation.
* @param hasFilters {@code True} if filters not empty.
* @param readThrough Read through flag.
* @param retval Return value flag.
* @param expiryPlc Expiry policy.
* @return Load future.
*/
private IgniteInternalFuture<Void> loadMissing(final GridCacheContext cacheCtx, final AffinityTopologyVersion topVer, final Set<KeyCacheObject> keys, final CacheEntryPredicate[] filter, final GridCacheReturn ret, final boolean needReadVer, final boolean singleRmv, final boolean hasFilters, final boolean readThrough, final boolean retval, final boolean keepBinary, final boolean recovery, final ExpiryPolicy expiryPlc) {
GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c = new GridInClosure3<KeyCacheObject, Object, GridCacheVersion>() {
@Override
public void apply(KeyCacheObject key, @Nullable Object val, @Nullable GridCacheVersion loadVer) {
if (log.isDebugEnabled())
log.debug("Loaded value from remote node [key=" + key + ", val=" + val + ']');
IgniteTxEntry e = entry(new IgniteTxKey(key, cacheCtx.cacheId()));
assert e != null;
if (needReadVer) {
assert loadVer != null;
e.entryReadVersion(singleRmv && val != null ? SER_READ_NOT_EMPTY_VER : loadVer);
}
if (singleRmv) {
assert !hasFilters && !retval;
assert val == null || Boolean.TRUE.equals(val) : val;
ret.set(cacheCtx, null, val != null, keepBinary);
} else {
CacheObject cacheVal = cacheCtx.toCacheObject(val);
if (e.op() == TRANSFORM) {
GridCacheVersion ver;
e.readValue(cacheVal);
try {
ver = e.cached().version();
} catch (GridCacheEntryRemovedException ex) {
assert optimistic() : e;
if (log.isDebugEnabled())
log.debug("Failed to get entry version: [msg=" + ex.getMessage() + ']');
ver = null;
}
addInvokeResult(e, cacheVal, ret, ver);
} else {
boolean success;
if (hasFilters) {
success = isAll(e.context(), key, cacheVal, filter);
if (!success)
e.value(cacheVal, false, false);
} else
success = true;
ret.set(cacheCtx, cacheVal, success, keepBinary);
}
}
}
};
return loadMissing(cacheCtx, topVer, readThrough, /*async*/
true, keys, /*skipVals*/
singleRmv, needReadVer, keepBinary, recovery, expiryPlc, c);
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridNearTxLocal method localCacheLoadMissing.
/**
* @param cacheCtx Cache context.
* @param readThrough Read through flag.
* @param async if {@code True}, then loading will happen in a separate thread.
* @param keys Keys.
* @param skipVals Skip values flag.
* @param needVer If {@code true} version is required for loaded values.
* @param c Closure to be applied for loaded values.
* @param expiryPlc Expiry policy.
* @return Future with {@code True} value if loading took place.
*/
private IgniteInternalFuture<Void> localCacheLoadMissing(final GridCacheContext cacheCtx, final AffinityTopologyVersion topVer, final boolean readThrough, boolean async, final Collection<KeyCacheObject> keys, boolean skipVals, boolean needVer, boolean keepBinary, boolean recovery, final ExpiryPolicy expiryPlc, final GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c) {
assert cacheCtx.isLocal() : cacheCtx.name();
if (!readThrough || !cacheCtx.readThrough()) {
for (KeyCacheObject key : keys) c.apply(key, null, SER_READ_EMPTY_ENTRY_VER);
return new GridFinishedFuture<>();
}
try {
IgniteCacheExpiryPolicy expiryPlc0 = optimistic() ? accessPolicy(cacheCtx, keys) : cacheCtx.cache().expiryPolicy(expiryPlc);
Map<KeyCacheObject, GridCacheVersion> misses = null;
for (KeyCacheObject key : keys) {
while (true) {
IgniteTxEntry txEntry = entry(cacheCtx.txKey(key));
GridCacheEntryEx entry = txEntry == null ? cacheCtx.cache().entryEx(key) : txEntry.cached();
if (entry == null)
continue;
try {
EntryGetResult res = entry.innerGetVersioned(null, this, /*update-metrics*/
!skipVals, /*event*/
!skipVals, CU.subjectId(this, cctx), null, resolveTaskName(), expiryPlc0, txEntry == null ? keepBinary : txEntry.keepBinary(), null);
if (res == null) {
if (misses == null)
misses = new LinkedHashMap<>();
misses.put(key, entry.version());
} else
c.apply(key, skipVals ? true : res.value(), res.version());
break;
} catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Got removed entry, will retry: " + key);
if (txEntry != null)
txEntry.cached(cacheCtx.cache().entryEx(key, topologyVersion()));
}
}
}
if (misses != null) {
final Map<KeyCacheObject, GridCacheVersion> misses0 = misses;
cacheCtx.store().loadAll(this, misses.keySet(), new CI2<KeyCacheObject, Object>() {
@Override
public void apply(KeyCacheObject key, Object val) {
GridCacheVersion ver = misses0.remove(key);
assert ver != null : key;
if (val != null) {
CacheObject cacheVal = cacheCtx.toCacheObject(val);
while (true) {
GridCacheEntryEx entry = cacheCtx.cache().entryEx(key, topVer);
try {
cacheCtx.shared().database().ensureFreeSpace(cacheCtx.memoryPolicy());
EntryGetResult verVal = entry.versionedValue(cacheVal, ver, null, null, null);
if (log.isDebugEnabled()) {
log.debug("Set value loaded from store into entry [" + "oldVer=" + ver + ", newVer=" + verVal.version() + ", entry=" + entry + ']');
}
ver = verVal.version();
break;
} catch (GridCacheEntryRemovedException ignore) {
if (log.isDebugEnabled())
log.debug("Got removed entry, (will retry): " + entry);
} catch (IgniteCheckedException e) {
// Wrap errors (will be unwrapped).
throw new GridClosureException(e);
}
}
} else
ver = SER_READ_EMPTY_ENTRY_VER;
c.apply(key, val, ver);
}
});
for (KeyCacheObject key : misses0.keySet()) c.apply(key, null, SER_READ_EMPTY_ENTRY_VER);
}
return new GridFinishedFuture<>();
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridNearTxRemote method addEntry.
/**
* @param cacheCtx Cache context.
* @param key Key to add to read set.
* @param op Operation.
* @param val Value.
* @param drVer Data center replication version.
* @param skipStore Skip store flag.
* @throws IgniteCheckedException If failed.
* @return {@code True} if entry has been enlisted.
*/
public boolean addEntry(GridCacheContext cacheCtx, IgniteTxKey key, GridCacheOperation op, CacheObject val, @Nullable GridCacheVersion drVer, boolean skipStore, boolean keepBinary) throws IgniteCheckedException {
checkInternal(key);
GridNearCacheEntry cached = cacheCtx.near().peekExx(key.key());
try {
if (cached == null) {
evicted.add(key);
return false;
} else {
cached.unswap();
CacheObject peek = cached.peek(null);
if (peek == null && cached.evictInternal(xidVer, null, false)) {
cached.context().cache().removeIfObsolete(key.key());
evicted.add(key);
return false;
} else {
IgniteTxEntry txEntry = new IgniteTxEntry(cacheCtx, this, op, val, -1L, -1L, cached, drVer, skipStore, keepBinary);
txState.addWriteEntry(key, txEntry);
return true;
}
}
} catch (GridCacheEntryRemovedException ignore) {
evicted.add(key);
if (log.isDebugEnabled())
log.debug("Got removed entry when adding reads to remote transaction (will ignore): " + cached);
return false;
}
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridLocalLockFuture method addEntries.
/**
* @param keys Keys.
* @return {@code False} in case of error.
* @throws IgniteCheckedException If failed.
*/
public boolean addEntries(Collection<KeyCacheObject> keys) throws IgniteCheckedException {
for (KeyCacheObject key : keys) {
while (true) {
GridLocalCacheEntry entry = null;
try {
entry = cache.entryExx(key);
entry.unswap(false);
if (!cctx.isAll(entry, filter)) {
onFailed();
return false;
}
// Removed exception may be thrown here.
GridCacheMvccCandidate cand = addEntry(entry);
if (cand == null && isDone())
return false;
break;
} catch (GridCacheEntryRemovedException ignored) {
if (log.isDebugEnabled())
log.debug("Got removed entry in lockAsync(..) method (will retry): " + entry);
}
}
}
if (timeout > 0) {
timeoutObj = new LockTimeoutObject();
cctx.time().addTimeoutObject(timeoutObj);
}
return true;
}
use of org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException in project ignite by apache.
the class GridNearTransactionalCache method clearLocks.
/**
* @param nodeId Node ID.
* @param req Request.
*/
@SuppressWarnings({ "RedundantTypeArguments" })
public void clearLocks(UUID nodeId, GridDhtUnlockRequest req) {
assert nodeId != null;
GridCacheVersion obsoleteVer = ctx.versions().next();
List<KeyCacheObject> keys = req.nearKeys();
if (keys != null) {
AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
for (KeyCacheObject key : keys) {
while (true) {
GridDistributedCacheEntry entry = peekExx(key);
try {
if (entry != null) {
entry.doneRemote(req.version(), req.version(), null, req.committedVersions(), req.rolledbackVersions(), /*system invalidate*/
false);
// we are about to remove.
if (entry.removeLock(req.version())) {
if (log.isDebugEnabled())
log.debug("Removed lock [lockId=" + req.version() + ", key=" + key + ']');
// Try to evict near entry dht-mapped locally.
evictNearEntry(entry, obsoleteVer, topVer);
} else {
if (log.isDebugEnabled())
log.debug("Received unlock request for unknown candidate " + "(added to cancelled locks set): " + req);
}
ctx.evicts().touch(entry, topVer);
} else if (log.isDebugEnabled())
log.debug("Received unlock request for entry that could not be found: " + req);
break;
} catch (GridCacheEntryRemovedException ignored) {
if (log.isDebugEnabled())
log.debug("Received remove lock request for removed entry (will retry) [entry=" + entry + ", req=" + req + ']');
}
}
}
}
}
Aggregations