use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.
the class AbstractIndex method verifyEntryAndIndexValue.
/**
* This will verify the consistency between RegionEntry and IndexEntry. RangeIndex has following
* entry structure,
*
* IndexKey --> [RegionEntry, [Iterator1, Iterator2....., IteratorN]]
*
* Where Iterator1 to IteratorN are iterators defined in index from clause.
*
* For example: "/portfolio p, p.positions.values pos" from clause has two iterators where p is
* independent iterator and pos is dependent iterator.
*
* Query iterators can be a subset, superset or exact match of index iterators. But we take query
* iterators which are matching with index iterators to evaluate RegionEntry for new value and
* compare it with index value which could be a plain object or a Struct.
*
* Note: Struct evaluated from RegionEntry can NOT have more field values than Index Value Struct
* as we filter out iterators in query context before evaluating Struct from RegionEntry.
*
* @return True if Region and Index entries are consistent.
*/
// package-private to avoid synthetic accessor
boolean verifyEntryAndIndexValue(RegionEntry re, Object value, ExecutionContext context) {
IMQEvaluator evaluator = (IMQEvaluator) getEvaluator();
List valuesInRegion = null;
Object valueInIndex = null;
try {
// change. So no need to verify anything just return true.
if (evaluator.isFirstItrOnKey()) {
return true;
} else if (evaluator.isFirstItrOnEntry()) {
valuesInRegion = evaluateIndexIteratorsFromRE(re, context);
valueInIndex = verifyAndGetPdxDomainObject(value);
} else {
Object val = re.getValueInVM(context.getPartitionedRegion());
if (val instanceof CachedDeserializable) {
val = ((CachedDeserializable) val).getDeserializedValue(getRegion(), re);
}
val = verifyAndGetPdxDomainObject(val);
valueInIndex = verifyAndGetPdxDomainObject(value);
valuesInRegion = evaluateIndexIteratorsFromRE(val, context);
}
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Exception occurred while verifying a Region Entry value during a Query when the Region Entry is under update operation", e);
}
}
// We could have many index keys available in one Region entry or just one.
if (!valuesInRegion.isEmpty()) {
for (Object valueInRegion : valuesInRegion) {
if (compareStructWithNonStruct(valueInRegion, valueInIndex)) {
return true;
}
}
return false;
} else {
// Seems like value has been invalidated.
return false;
}
}
use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.
the class Get70 method getValueAndIsObject.
// take the result 3 element "result" as argument instead of
// returning as the result to avoid creating the array repeatedly
// for large number of entries like in getAll. Third element added in
// 7.0 for retrieving version information
public Entry getValueAndIsObject(Region region, Object key, Object callbackArg, ServerConnection servConn) {
// Region.Entry entry;
String regionName = region.getFullPath();
if (servConn != null) {
servConn.setModificationInfo(true, regionName, key);
}
VersionTag versionTag = null;
// LocalRegion lregion = (LocalRegion)region;
// entry = lregion.getEntry(key, true);
boolean isObject = true;
Object data = null;
// if (entry != null && region.getAttributes().getConcurrencyChecksEnabled()) {
// RegionEntry re;
// if (entry instanceof NonTXEntry) {
// re = ((NonTXEntry)entry).getRegionEntry();
// } else if (entry instanceof EntrySnapshot) {
// re = ((EntrySnapshot)entry).getRegionEntry();
// } else if (entry instanceof TXEntry) {
// re = null; // versioning not supported in tx yet
// data = entry.getValue(); // can I get a serialized form??
// } else {
// re = (RegionEntry)entry;
// }
// if (re != null) {
// data = re.getValueInVM();
// VersionStamp stamp = re.getVersionStamp();
// if (stamp != null) {
// versionHolder.setVersionTag(stamp.asVersionTag());
// }
// }
// } else {
ClientProxyMembershipID id = servConn == null ? null : servConn.getProxyID();
VersionTagHolder versionHolder = new VersionTagHolder();
data = ((LocalRegion) region).get(key, callbackArg, true, true, true, id, versionHolder, true);
// }
versionTag = versionHolder.getVersionTag();
// If the value in the VM is a CachedDeserializable,
// get its value. If it is Token.REMOVED, Token.DESTROYED,
// Token.INVALID, or Token.LOCAL_INVALID
// set it to null. If it is NOT_AVAILABLE, get the value from
// disk. If it is already a byte[], set isObject to false.
boolean wasInvalid = false;
if (data instanceof CachedDeserializable) {
CachedDeserializable cd = (CachedDeserializable) data;
if (!cd.isSerialized()) {
// it is a byte[]
isObject = false;
data = cd.getDeserializedForReading();
} else {
data = cd.getValue();
}
} else if (data == Token.REMOVED_PHASE1 || data == Token.REMOVED_PHASE2 || data == Token.DESTROYED) {
data = null;
} else if (data == Token.INVALID || data == Token.LOCAL_INVALID) {
// fix for bug 35884
data = null;
wasInvalid = true;
} else if (data instanceof byte[]) {
isObject = false;
}
Entry result = new Entry();
result.value = data;
result.isObject = isObject;
result.keyNotPresent = !wasInvalid && (data == null || data == Token.TOMBSTONE);
result.versionTag = versionTag;
return result;
}
use of org.apache.geode.internal.cache.CachedDeserializable 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.cache.CachedDeserializable 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;
}
}
}
use of org.apache.geode.internal.cache.CachedDeserializable in project geode by apache.
the class LuceneIndexMaintenanceIntegrationTest method verifySerializedValues.
private void verifySerializedValues(Region region) {
Set entries = region.entrySet();
assertFalse(entries.isEmpty());
for (Iterator i = entries.iterator(); i.hasNext(); ) {
EntrySnapshot entry = (EntrySnapshot) i.next();
RegionEntry re = entry.getRegionEntry();
Object reValue = re.getValue(null);
assertTrue(reValue instanceof CachedDeserializable);
Object cdValue = ((CachedDeserializable) reValue).getValue();
assertTrue(cdValue instanceof byte[]);
}
}
Aggregations