use of org.apache.geode.internal.offheap.annotations.Retained in project geode by apache.
the class LocalRegion method getDeserialized.
/**
* @param disableCopyOnRead if true then do not make a copy on read
* @param preferCachedDeserializable true if the preferred result form is CachedDeserializable
* @param retainResult if true then the result may be a retained off-heap reference
* @return the value found, which can be
* <ul>
* <li>null if the value was removed from the region entry
* <li>Token.INVALID if the value of the region entry is invalid
* <li>Token.LOCAL_INVALID if the value of the region entry is local invalid
* </ul>
*/
@Retained
Object getDeserialized(RegionEntry regionEntry, boolean updateStats, boolean disableCopyOnRead, boolean preferCachedDeserializable, boolean retainResult) {
assert !retainResult || preferCachedDeserializable;
boolean disabledLRUCallback = this.entries.disableLruUpdateCallback();
try {
@Retained Object value;
try {
if (retainResult) {
value = regionEntry.getValueRetain(this);
} else {
value = regionEntry.getValue(this);
}
} catch (DiskAccessException dae) {
this.handleDiskAccessException(dae);
throw dae;
}
// skip updating the stats if the value is null
if (value == null) {
return null;
}
if (value instanceof CachedDeserializable) {
if (!preferCachedDeserializable) {
if (isCopyOnRead()) {
if (disableCopyOnRead) {
value = ((CachedDeserializable) value).getDeserializedForReading();
} else {
value = ((CachedDeserializable) value).getDeserializedWritableCopy(this, regionEntry);
}
} else {
value = ((CachedDeserializable) value).getDeserializedValue(this, regionEntry);
}
}
} else if (!disableCopyOnRead) {
value = conditionalCopy(value);
}
if (updateStats) {
updateStatsForGet(regionEntry, value != null && !Token.isInvalid(value));
}
return value;
} catch (IllegalArgumentException i) {
throw new IllegalArgumentException(LocalizedStrings.DONT_RELEASE.toLocalizedString("Error while deserializing value for key=" + regionEntry.getKey()), i);
} finally {
if (disabledLRUCallback) {
this.entries.enableLruUpdateCallback();
this.entries.lruUpdateCallback();
}
}
}
use of org.apache.geode.internal.offheap.annotations.Retained in project geode by apache.
the class LocalRegion method nonTXbasicGetValueInVM.
@Retained
Object nonTXbasicGetValueInVM(KeyInfo keyInfo) {
RegionEntry regionEntry = this.entries.getEntry(keyInfo.getKey());
if (regionEntry == null) {
checkEntryNotFound(keyInfo.getKey());
}
// OFFHEAP returned to callers
Object value = regionEntry.getValueInVM(this);
if (Token.isRemoved(value)) {
checkEntryNotFound(keyInfo.getKey());
}
if (value == Token.NOT_AVAILABLE) {
return null;
}
return value;
}
use of org.apache.geode.internal.offheap.annotations.Retained in project geode by apache.
the class Oplog method getBytesAndBitsForCompaction.
/**
* This function retrieves the value for an entry being compacted subject to entry referencing the
* oplog being compacted. Attempt is made to retrieve the value from in memory , if available,
* else from asynch buffers ( if asynch mode is enabled), else from the Oplog being compacted. It
* is invoked from switchOplog as well as OplogCompactor's compact function.
*
* @param entry DiskEntry being compacted referencing the Oplog being compacted
* @param wrapper Object of type BytesAndBitsForCompactor. The data if found is set in the wrapper
* Object. The wrapper Object also contains the user bit associated with the entry
* @return boolean false indicating that entry need not be compacted. If true it means that
* wrapper has been appropriately filled with data
*/
private boolean getBytesAndBitsForCompaction(DiskRegionView dr, DiskEntry entry, BytesAndBitsForCompactor wrapper) {
// caller is synced on did
DiskId did = entry.getDiskId();
byte userBits = 0;
long oplogOffset = did.getOffsetInOplog();
ReferenceCountHelper.skipRefCountTracking();
@Retained @Released Object value = entry._getValueRetain(dr, true);
ReferenceCountHelper.unskipRefCountTracking();
boolean foundData = false;
if (value == null) {
// If the mode is synch it is guaranteed to be present in the disk
foundData = basicGetForCompactor(dr, oplogOffset, false, did.getValueLength(), did.getUserBits(), wrapper);
// it is impossible for this oplogId to change.
if (did.getOplogId() != getOplogId()) {
// if it is not then no need to compact it
return false;
} else {
// then we should have found data
assert foundData : "compactor get failed on oplog#" + getOplogId();
}
userBits = wrapper.getBits();
if (EntryBits.isAnyInvalid(userBits)) {
if (EntryBits.isInvalid(userBits)) {
wrapper.setData(DiskEntry.INVALID_BYTES, userBits, DiskEntry.INVALID_BYTES.length, false);
} else {
wrapper.setData(DiskEntry.LOCAL_INVALID_BYTES, userBits, DiskEntry.LOCAL_INVALID_BYTES.length, false);
}
} else if (EntryBits.isTombstone(userBits)) {
wrapper.setData(DiskEntry.TOMBSTONE_BYTES, userBits, DiskEntry.TOMBSTONE_BYTES.length, false);
}
if (EntryBits.isWithVersions(did.getUserBits())) {
userBits = EntryBits.setWithVersions(userBits, true);
}
} else {
foundData = true;
userBits = 0;
if (EntryBits.isRecoveredFromDisk(did.getUserBits())) {
userBits = EntryBits.setRecoveredFromDisk(userBits, true);
}
if (EntryBits.isWithVersions(did.getUserBits())) {
userBits = EntryBits.setWithVersions(userBits, true);
}
// (the compactor) are writing the value out to disk.
if (value == Token.INVALID) {
userBits = EntryBits.setInvalid(userBits, true);
wrapper.setData(DiskEntry.INVALID_BYTES, userBits, DiskEntry.INVALID_BYTES.length, false);
} else if (value == Token.LOCAL_INVALID) {
userBits = EntryBits.setLocalInvalid(userBits, true);
wrapper.setData(DiskEntry.LOCAL_INVALID_BYTES, userBits, DiskEntry.LOCAL_INVALID_BYTES.length, false);
} else if (value == Token.TOMBSTONE) {
userBits = EntryBits.setTombstone(userBits, true);
wrapper.setData(DiskEntry.TOMBSTONE_BYTES, userBits, DiskEntry.TOMBSTONE_BYTES.length, false);
} else if (value instanceof CachedDeserializable) {
CachedDeserializable proxy = (CachedDeserializable) value;
if (proxy instanceof StoredObject) {
@Released StoredObject ohproxy = (StoredObject) proxy;
try {
ohproxy.fillSerializedValue(wrapper, userBits);
} finally {
OffHeapHelper.releaseWithNoTracking(ohproxy);
}
} else {
userBits = EntryBits.setSerialized(userBits, true);
proxy.fillSerializedValue(wrapper, userBits);
}
} else if (value instanceof byte[]) {
byte[] valueBytes = (byte[]) value;
// If the value is already a byte array then the user bit
// is 0, which is the default value of the userBits variable,
// indicating that it is non serialized data. Thus it is
// to be used as it is & not to be deserialized to
// convert into Object
wrapper.setData(valueBytes, userBits, valueBytes.length, false);
} else if (Token.isRemoved(value) && value != Token.TOMBSTONE) {
// TODO - RVV - We need to handle tombstones differently here!
if (entry.getDiskId().isPendingAsync()) {
entry.getDiskId().setPendingAsync(false);
try {
getOplogSet().getChild().basicRemove(dr, entry, false, false);
} catch (IOException ex) {
getParent().getCancelCriterion().checkCancelInProgress(ex);
throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_WRITING_KEY_TO_0.toLocalizedString(this.diskFile.getPath()), ex, dr.getName());
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
getParent().getCache().getCancelCriterion().checkCancelInProgress(ie);
throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_WRITING_KEY_TO_0_DUE_TO_FAILURE_IN_ACQUIRING_READ_LOCK_FOR_ASYNCH_WRITING.toLocalizedString(this.diskFile.getPath()), ie, dr.getName());
}
} else {
rmLive(dr, entry);
}
foundData = false;
} else {
userBits = EntryBits.setSerialized(userBits, true);
EntryEventImpl.fillSerializedValue(wrapper, value, userBits);
}
}
if (foundData) {
// since the compactor is writing it out clear the async flag
entry.getDiskId().setPendingAsync(false);
}
return foundData;
}
use of org.apache.geode.internal.offheap.annotations.Retained in project geode by apache.
the class LocalRegion method nonTxnFindObject.
/**
* optimized to only allow one thread to do a search/load, other threads wait on a future
*
* @param isCreate true if call found no entry; false if updating an existing entry
* @param localValue the value retrieved from the region for this object.
* @param disableCopyOnRead if true then do not make a copy
* @param preferCD true if the preferred result form is CachedDeserializable
* @param clientEvent the client event, if any
* @param returnTombstones whether to return tombstones
*/
@Retained
Object nonTxnFindObject(KeyInfo keyInfo, boolean isCreate, boolean generateCallbacks, Object localValue, boolean disableCopyOnRead, boolean preferCD, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones) throws TimeoutException, CacheLoaderException {
@Retained Object result = null;
FutureResult thisFuture = new FutureResult(this.stopper);
Future otherFuture = (Future) this.getFutures.putIfAbsent(keyInfo.getKey(), thisFuture);
// only one thread can get their future into the map for this key at a time
if (otherFuture != null) {
try {
Object[] valueAndVersion = (Object[]) otherFuture.get();
if (valueAndVersion != null) {
result = valueAndVersion[0];
if (clientEvent != null) {
clientEvent.setVersionTag((VersionTag) valueAndVersion[1]);
}
if (!preferCD && result instanceof CachedDeserializable) {
CachedDeserializable cd = (CachedDeserializable) result;
// fix for bug 43023
if (!disableCopyOnRead && isCopyOnRead()) {
result = cd.getDeserializedWritableCopy(null, null);
} else {
result = cd.getDeserializedForReading();
}
} else if (!disableCopyOnRead) {
result = conditionalCopy(result);
}
// what was a miss is now a hit
if (isCreate) {
RegionEntry regionEntry = basicGetEntry(keyInfo.getKey());
updateStatsForGet(regionEntry, true);
}
return result;
}
// if value == null, try our own search/load
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
// TODO check a CancelCriterion here?
return null;
} catch (ExecutionException e) {
// NOTE: this was creating InternalGemFireError and initCause with itself
throw new InternalGemFireError(LocalizedStrings.LocalRegion_UNEXPECTED_EXCEPTION.toLocalizedString(), e);
}
}
// condition where the future was just removed by another thread
try {
boolean partitioned = this.getDataPolicy().withPartitioning();
if (!partitioned) {
localValue = getDeserializedValue(null, keyInfo, isCreate, disableCopyOnRead, preferCD, clientEvent, false, false);
// stats have now been updated
if (localValue != null && !Token.isInvalid(localValue)) {
result = localValue;
return result;
}
isCreate = localValue == null;
result = findObjectInSystem(keyInfo, isCreate, null, generateCallbacks, localValue, disableCopyOnRead, preferCD, requestingClient, clientEvent, returnTombstones);
} else {
// For PRs we don't want to deserialize the value and we can't use findObjectInSystem
// because it can invoke code that is transactional.
result = getSharedDataView().findObject(keyInfo, this, isCreate, generateCallbacks, localValue, disableCopyOnRead, preferCD, requestingClient, clientEvent, returnTombstones);
}
if (result == null && localValue != null) {
if (localValue != Token.TOMBSTONE || returnTombstones) {
result = localValue;
}
}
// findObjectInSystem does not call conditionalCopy
} finally {
if (result != null) {
VersionTag tag = clientEvent == null ? null : clientEvent.getVersionTag();
thisFuture.set(new Object[] { result, tag });
} else {
thisFuture.set(null);
}
this.getFutures.remove(keyInfo.getKey());
}
if (!disableCopyOnRead) {
result = conditionalCopy(result);
}
return result;
}
use of org.apache.geode.internal.offheap.annotations.Retained in project geode by apache.
the class PutAllPRMessage method getEventFromEntry.
@Retained
public static EntryEventImpl getEventFromEntry(LocalRegion r, InternalDistributedMember myId, InternalDistributedMember eventSender, int idx, DistributedPutAllOperation.PutAllEntryData[] data, boolean notificationOnly, ClientProxyMembershipID bridgeContext, boolean posDup, boolean skipCallbacks) {
PutAllEntryData prd = data[idx];
// EntryEventImpl ev = EntryEventImpl.create(r,
// prd.getOp(),
// prd.getKey(), null/* value */, null /* callbackArg */,
// false /* originRemote */,
// eventSender,
// true/* generate Callbacks */,
// prd.getEventID());
@Retained EntryEventImpl ev = EntryEventImpl.create(r, prd.getOp(), prd.getKey(), prd.getValue(), null, false, eventSender, !skipCallbacks, prd.getEventID());
boolean evReturned = false;
try {
if (prd.getValue() == null && ev.getRegion().getAttributes().getDataPolicy() == DataPolicy.NORMAL) {
ev.setLocalInvalid(true);
}
ev.setNewValue(prd.getValue());
ev.setOldValue(prd.getOldValue());
if (bridgeContext != null) {
ev.setContext(bridgeContext);
}
ev.setInvokePRCallbacks(!notificationOnly);
ev.setPossibleDuplicate(posDup);
if (prd.filterRouting != null) {
ev.setLocalFilterInfo(prd.filterRouting.getFilterInfo(myId));
}
if (prd.versionTag != null) {
prd.versionTag.replaceNullIDs(eventSender);
ev.setVersionTag(prd.versionTag);
}
// ev.setLocalFilterInfo(r.getFilterProfile().getLocalFilterRouting(ev));
if (notificationOnly) {
ev.setTailKey(-1L);
} else {
ev.setTailKey(prd.getTailKey());
}
evReturned = true;
return ev;
} finally {
if (!evReturned) {
ev.release();
}
}
}
Aggregations