return cacheEntry;
}
}
public final MVCCEntry wrapEntryForWriting(InvocationContext ctx, Object key, boolean createIfAbsent, boolean forceLockIfAbsent, boolean alreadyLocked, boolean forRemoval) throws InterruptedException {
CacheEntry cacheEntry = ctx.lookupEntry(key);
MVCCEntry mvccEntry = null;
if (createIfAbsent && cacheEntry != null && cacheEntry.isNull()) cacheEntry = null;
if (cacheEntry != null) // exists in context! Just acquire lock if needed, and wrap.
{
if (trace) log.trace("Exists in context.");
// acquire lock if needed
if (alreadyLocked || acquireLock(ctx, key)) {
if (cacheEntry instanceof MVCCEntry && (!forRemoval || !(cacheEntry instanceof NullMarkerEntry))) {
mvccEntry = (MVCCEntry) cacheEntry;
} else {
// this is a read-only entry that needs to be copied to a proper read-write entry!!
mvccEntry = createWrappedEntry(key, cacheEntry.getValue(), false, forRemoval, cacheEntry.getLifespan());
cacheEntry = mvccEntry;
ctx.putLookedUpEntry(key, cacheEntry);
}
// create a copy of the underlying entry
mvccEntry.copyForUpdate(container, writeSkewCheck);
}
if (cacheEntry.isRemoved() && createIfAbsent) {
if (trace) log.trace("Entry is deleted in current scope. Need to un-delete.");
if (mvccEntry != cacheEntry) mvccEntry = (MVCCEntry) cacheEntry;
mvccEntry.setRemoved(false);
mvccEntry.setValid(true);
}
return mvccEntry;
} else {
// else, fetch from dataContainer.
cacheEntry = container.get(key);
if (cacheEntry != null) {
if (trace) log.trace("Retrieved from container.");
// exists in cache! Just acquire lock if needed, and wrap.
// do we need a lock?
boolean needToCopy = alreadyLocked || acquireLock(ctx, key) || ctx.hasFlag(Flag.SKIP_LOCKING); // even if we do not acquire a lock, if skip-locking is enabled we should copy
mvccEntry = createWrappedEntry(key, cacheEntry.getValue(), false, false, cacheEntry.getLifespan());
ctx.putLookedUpEntry(key, mvccEntry);
if (needToCopy) mvccEntry.copyForUpdate(container, writeSkewCheck);
cacheEntry = mvccEntry;
} else if (createIfAbsent) {
// this is the *only* point where new entries can be created!!