use of org.apache.ignite.internal.processors.cache.CacheObject 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.CacheObject in project ignite by apache.
the class GridLocalCacheEntry method readyLocal.
/**
* @param cand Candidate.
*/
void readyLocal(GridCacheMvccCandidate cand) {
CacheObject val;
CacheLockCandidates prev = null;
CacheLockCandidates owner = null;
synchronized (this) {
GridCacheMvcc mvcc = mvccExtras();
if (mvcc != null) {
prev = mvcc.localOwners();
owner = mvcc.readyLocal(cand);
if (mvcc.isEmpty())
mvccExtras(null);
}
val = this.val;
}
checkOwnerChanged(prev, owner, val);
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridLocalCacheEntry method recheck.
/**
* Rechecks if lock should be reassigned.
*/
public void recheck() {
CacheObject val;
CacheLockCandidates prev = null;
CacheLockCandidates owner = null;
synchronized (this) {
GridCacheMvcc mvcc = mvccExtras();
if (mvcc != null) {
prev = mvcc.allOwners();
owner = mvcc.recheck();
if (mvcc.isEmpty())
mvccExtras(null);
}
val = this.val;
}
checkOwnerChanged(prev, owner, val);
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridLocalCacheEntry method releaseLocal.
/**
* Releases local lock.
*
* @param threadId Thread ID.
*/
private void releaseLocal(long threadId) {
CacheObject val;
CacheLockCandidates prev = null;
CacheLockCandidates owner = null;
synchronized (this) {
GridCacheMvcc mvcc = mvccExtras();
if (mvcc != null) {
prev = mvcc.localOwners();
mvcc.releaseLocal(threadId);
if (mvcc.isEmpty())
mvccExtras(null);
else
owner = mvcc.allOwners();
}
val = this.val;
}
if (prev != null) {
for (int i = 0; i < prev.size(); i++) {
GridCacheMvccCandidate cand = prev.candidate(i);
boolean unlocked = owner == null || !owner.hasCandidate(cand.version());
if (unlocked)
checkThreadChain(cand);
}
}
checkOwnerChanged(prev, owner, val);
}
use of org.apache.ignite.internal.processors.cache.CacheObject in project ignite by apache.
the class GridLocalAtomicCache method getAllInternal.
/**
* Entry point to all public API get methods.
*
* @param keys Keys to remove.
* @param storeEnabled Store enabled flag.
* @param taskName Task name.
* @param deserializeBinary Deserialize binary .
* @param skipVals Skip value flag.
* @param needVer Need version.
* @return Key-value map.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("ConstantConditions")
private Map<K, V> getAllInternal(@Nullable Collection<? extends K> keys, boolean storeEnabled, String taskName, boolean deserializeBinary, boolean skipVals, boolean needVer) throws IgniteCheckedException {
ctx.checkSecurity(SecurityPermission.CACHE_READ);
if (F.isEmpty(keys))
return Collections.emptyMap();
CacheOperationContext opCtx = ctx.operationContextPerCall();
UUID subjId = ctx.subjectIdPerCall(null, opCtx);
Map<K, V> vals = U.newHashMap(keys.size());
if (keyCheck)
validateCacheKeys(keys);
final IgniteCacheExpiryPolicy expiry = expiryPolicy(opCtx != null ? opCtx.expiry() : null);
boolean success = true;
boolean readNoEntry = ctx.readNoEntry(expiry, false);
final boolean evt = !skipVals;
for (K key : keys) {
if (key == null)
throw new NullPointerException("Null key.");
KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
boolean skipEntry = readNoEntry;
if (readNoEntry) {
CacheDataRow row = ctx.offheap().read(cacheKey);
if (row != null) {
long expireTime = row.expireTime();
if (expireTime == 0 || expireTime > U.currentTimeMillis()) {
ctx.addResult(vals, cacheKey, row.value(), skipVals, false, deserializeBinary, true, null, row.version(), 0, 0, needVer);
if (configuration().isStatisticsEnabled() && !skipVals)
metrics0().onRead(true);
if (evt) {
ctx.events().readEvent(cacheKey, null, row.value(), subjId, taskName, !deserializeBinary);
}
} else
skipEntry = false;
} else
success = false;
}
if (!skipEntry) {
GridCacheEntryEx entry = null;
while (true) {
try {
entry = entryEx(cacheKey);
if (entry != null) {
CacheObject v;
if (needVer) {
EntryGetResult res = entry.innerGetVersioned(null, null, /*update-metrics*/
false, /*event*/
evt, subjId, null, taskName, expiry, !deserializeBinary, null);
if (res != null) {
ctx.addResult(vals, cacheKey, res, skipVals, false, deserializeBinary, true, needVer);
} else
success = false;
} else {
v = entry.innerGet(null, null, /*read-through*/
false, /*update-metrics*/
true, /*event*/
evt, subjId, null, taskName, expiry, !deserializeBinary);
if (v != null) {
ctx.addResult(vals, cacheKey, v, skipVals, false, deserializeBinary, true, null, 0, 0);
} else
success = false;
}
} else {
if (!storeEnabled && configuration().isStatisticsEnabled() && !skipVals)
metrics0().onRead(false);
success = false;
}
// While.
break;
} catch (GridCacheEntryRemovedException ignored) {
// No-op, retry.
} finally {
if (entry != null)
ctx.evicts().touch(entry, ctx.affinity().affinityTopologyVersion());
}
if (!success && storeEnabled)
break;
}
}
}
if (success || !storeEnabled)
return vals;
return getAllAsync(keys, null, opCtx == null || !opCtx.skipStore(), false, subjId, taskName, deserializeBinary, opCtx != null && opCtx.recovery(), /*force primary*/
false, expiry, skipVals, /*can remap*/
true, needVer).get();
}
Aggregations