use of org.apache.geode.internal.offheap.annotations.Retained in project geode by apache.
the class AbstractRegionMap method copyRecoveredEntries.
public void copyRecoveredEntries(RegionMap rm) {
// We need to sort the tombstones before scheduling them,
// so that they will be in the correct order.
OrderedTombstoneMap<RegionEntry> tombstones = new OrderedTombstoneMap<RegionEntry>();
if (rm != null) {
CustomEntryConcurrentHashMap<Object, Object> other = ((AbstractRegionMap) rm)._getMap();
Iterator<Map.Entry<Object, Object>> it = other.entrySetWithReusableEntries().iterator();
while (it.hasNext()) {
Map.Entry<Object, Object> me = it.next();
// This removes the RegionEntry from "rm" but it does not decrement its
it.remove();
// refcount to an offheap value.
RegionEntry oldRe = (RegionEntry) me.getValue();
Object key = me.getKey();
@Retained @Released Object value = oldRe._getValueRetain((RegionEntryContext) ((AbstractRegionMap) rm)._getOwnerObject(), true);
try {
if (value == Token.NOT_AVAILABLE) {
// fix for bug 43993
value = null;
}
if (value == Token.TOMBSTONE && !_getOwner().getConcurrencyChecksEnabled()) {
continue;
}
RegionEntry newRe = getEntryFactory().createEntry((RegionEntryContext) _getOwnerObject(), key, value);
// TODO: passing value to createEntry causes a problem with the disk stats.
// The disk stats have already been set to track oldRe.
// So when we call createEntry we probably want to give it REMOVED_PHASE1
// and then set the value in copyRecoveredEntry it a way that does not
// change the disk stats. This also depends on DiskEntry.Helper.initialize not changing
// the stats for REMOVED_PHASE1
copyRecoveredEntry(oldRe, newRe);
// newRe is now in this._getMap().
if (newRe.isTombstone()) {
VersionTag tag = newRe.getVersionStamp().asVersionTag();
tombstones.put(tag, newRe);
} else {
_getOwner().updateSizeOnCreate(key, _getOwner().calculateRegionEntryValueSize(newRe));
}
incEntryCount(1);
lruEntryUpdate(newRe);
} finally {
OffHeapHelper.release(value);
if (oldRe instanceof OffHeapRegionEntry) {
((OffHeapRegionEntry) oldRe).release();
}
}
lruUpdateCallback();
}
} else {
for (Iterator<RegionEntry> iter = regionEntries().iterator(); iter.hasNext(); ) {
RegionEntry re = iter.next();
if (re.isTombstone()) {
if (re.getVersionStamp() == null) {
// bug #50992 - recovery from versioned to
// non-versioned
iter.remove();
continue;
} else {
tombstones.put(re.getVersionStamp().asVersionTag(), re);
}
} else {
_getOwner().updateSizeOnCreate(re.getKey(), _getOwner().calculateRegionEntryValueSize(re));
}
}
incEntryCount(size());
// Since lru was not being done during recovery call it now.
lruUpdateCallback();
}
// Schedule all of the tombstones, now that we have sorted them
Map.Entry<VersionTag, RegionEntry> entry;
while ((entry = tombstones.take()) != null) {
// refresh the tombstone so it doesn't time out too soon
_getOwner().scheduleTombstone(entry.getValue(), entry.getKey());
}
}
use of org.apache.geode.internal.offheap.annotations.Retained in project geode by apache.
the class DummyQRegion method asList.
@Override
public List asList() {
if (valueInList == null) {
valueInList = new ArrayList(1);
}
valueInList.clear();
Object val = this.entry.getValueOffHeapOrDiskWithoutFaultIn((LocalRegion) getRegion());
if (val instanceof StoredObject) {
@Retained @Released StoredObject ohval = (StoredObject) val;
try {
val = ohval.getDeserializedValue(getRegion(), this.entry);
} finally {
ohval.release();
}
} else if (val instanceof CachedDeserializable) {
val = ((CachedDeserializable) val).getDeserializedValue(getRegion(), this.entry);
}
valueInList.add(val);
return valueInList;
}
use of org.apache.geode.internal.offheap.annotations.Retained in project geode by apache.
the class GatewaySenderEventImpl method initializeValue.
// Initializes the value object. This function need a relook because the
// serialization of the value looks unnecessary.
@Retained(OffHeapIdentifier.GATEWAY_SENDER_EVENT_IMPL_VALUE)
protected void initializeValue(EntryEventImpl event) throws IOException {
// substituteValue (if set).
if (this.substituteValue == null) {
// If the value is already serialized, use it.
this.valueIsObject = 0x01;
/**
* so ends up being stored in this.valueObj
*/
@Retained(OffHeapIdentifier.GATEWAY_SENDER_EVENT_IMPL_VALUE) StoredObject so = null;
{
ReferenceCountHelper.setReferenceCountOwner(this);
so = event.getOffHeapNewValue();
ReferenceCountHelper.setReferenceCountOwner(null);
}
if (so != null) {
// if (so != null && !event.hasDelta()) {
// Since GatewaySenderEventImpl instances can live for a long time in the gateway region
// queue
// we do not want the StoredObject to be one that keeps the heap form cached.
// fixes 51999
so = so.getStoredObjectWithoutHeapForm();
this.valueObj = so;
if (!so.isSerialized()) {
this.valueIsObject = 0x00;
}
} else if (event.getCachedSerializedNewValue() != null) {
// We want this to have lower precedence than StoredObject so that the gateway
// can share a reference to the off-heap value.
this.value = event.getCachedSerializedNewValue();
} else {
final Object newValue = event.getRawNewValue();
// since we already called getOffHeapNewValue()
assert !(newValue instanceof StoredObject);
// and it returned null
if (newValue instanceof CachedDeserializable) {
this.value = ((CachedDeserializable) newValue).getSerializedValue();
} else if (newValue instanceof byte[]) {
// The value is byte[]. Set _valueIsObject flag to 0x00 (not an object)
this.value = (byte[]) newValue;
this.valueIsObject = 0x00;
} else {
// The value is an object. It will be serialized later when getSerializedValue is called.
this.valueObj = newValue;
// to prevent bug 48281 we need to serialize it now
this.getSerializedValue();
this.valueObj = null;
}
}
} else {
// The substituteValue is set. Use it.
if (this.substituteValue instanceof byte[]) {
// The substituteValue is byte[]. Set valueIsObject flag to 0x00 (not an object)
this.value = (byte[]) this.substituteValue;
this.valueIsObject = 0x00;
} else if (this.substituteValue == TOKEN_NULL) {
// The substituteValue represents null. Set the value and substituteValue to null.
this.value = null;
this.substituteValue = null;
this.valueIsObject = 0x01;
} else {
// The substituteValue is an object. Leave it as is.
this.valueIsObject = 0x01;
}
}
}
Aggregations