use of org.apache.geode.internal.cache.EntrySnapshot in project geode by apache.
the class GetEntry70 method getValueAndIsObject.
@Override
public Get70.Entry getValueAndIsObject(Region region, Object key, Object callbackArg, ServerConnection servConn) {
LocalRegion lregion = (LocalRegion) region;
Object data = null;
Region.Entry entry = region.getEntry(key);
if (logger.isDebugEnabled()) {
logger.debug("GetEntryCommand: for key: {} returning entry: {}", key, entry);
}
VersionTag tag = null;
if (entry != null) {
EntrySnapshot snap = new EntrySnapshot();
NonLocalRegionEntry re = new NonLocalRegionEntry(entry, lregion);
snap.setRegionEntry(re);
snap.setRegion(lregion);
data = snap;
tag = snap.getVersionTag();
}
Get70.Entry result = new Get70.Entry();
result.value = data;
result.isObject = true;
result.keyNotPresent = false;
result.versionTag = tag;
return result;
}
use of org.apache.geode.internal.cache.EntrySnapshot in project geode by apache.
the class BaseCommand method appendNewRegisterInterestResponseChunk.
public static void appendNewRegisterInterestResponseChunk(LocalRegion region, VersionedObjectList values, Object riKeys, Set<Map.Entry> set, ServerConnection servConn) throws IOException {
for (Entry entry : set) {
if (entry instanceof Region.Entry) {
// local entries
VersionTag vt;
Object key;
Object value;
if (entry instanceof EntrySnapshot) {
vt = ((EntrySnapshot) entry).getVersionTag();
key = ((EntrySnapshot) entry).getRegionEntry().getKey();
value = ((EntrySnapshot) entry).getRegionEntry().getValue(null);
updateValues(values, key, value, vt);
} else {
VersionStamp vs = ((NonTXEntry) entry).getRegionEntry().getVersionStamp();
vt = vs == null ? null : vs.asVersionTag();
key = entry.getKey();
value = ((NonTXEntry) entry).getRegionEntry()._getValueRetain(region, true);
try {
updateValues(values, key, value, vt);
} finally {
OffHeapHelper.release(value);
}
}
} else {
// Map.Entry (remote entries)
List list = (List) entry.getValue();
Object value = list.get(0);
VersionTag tag = (VersionTag) list.get(1);
updateValues(values, entry.getKey(), value, tag);
}
if (values.size() == MAXIMUM_CHUNK_SIZE) {
// Send the chunk and clear the list
sendNewRegisterInterestResponseChunk(region, riKeys != null ? riKeys : "ALL_KEYS", values, false, servConn);
values.clear();
}
}
// for
}
use of org.apache.geode.internal.cache.EntrySnapshot in project geode by apache.
the class PRFunctionExecutionDUnitTest method assertLocalEntrySet.
protected static void assertLocalEntrySet(final Integer key, final Set entrySet) {
assertEquals(1, entrySet.size());
Iterator esi = entrySet.iterator();
assertTrue(esi.hasNext());
Region.Entry re = (Entry) esi.next();
if (re instanceof EntrySnapshot) {
assertTrue(((EntrySnapshot) re).wasInitiallyLocal());
} else {
assertTrue(re.isLocal());
}
assertEquals(key, re.getKey());
assertEquals(key, re.getValue());
assertFalse(esi.hasNext());
}
use of org.apache.geode.internal.cache.EntrySnapshot 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[]);
}
}
use of org.apache.geode.internal.cache.EntrySnapshot in project geode by apache.
the class ElidedPutAllDUnitTest method testElidedPutAllOnPR.
/**
* bug #47425 - elided putAll event causes PutAllPartialResultException
*/
@Test
public void testElidedPutAllOnPR() throws Exception {
final String regionName = getUniqueName() + "Region";
final String key = "key-1";
Cache cache = getCache();
PartitionedRegion region = (PartitionedRegion) cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
region.put(key, "value-1");
region.put(key, "value-2");
Entry<?, ?> entry = region.getEntry(key);
assertTrue("expected entry to be in this vm", entry != null);
VM vm1 = Host.getHost(0).getVM(1);
vm1.invoke(new SerializableRunnable("perform conflicting update") {
@Override
public void run() {
Cache cache = getCache();
PartitionedRegion region = (PartitionedRegion) cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
try {
Entry<?, ?> entry = region.getEntry(key);
assertTrue(entry instanceof EntrySnapshot);
RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
final VersionTag<?> tag = regionEntry.getVersionStamp().asVersionTag();
tag.setEntryVersion(tag.getEntryVersion() - 1);
tag.setRegionVersion(1);
Map<String, String> map = new HashMap<String, String>();
map.put(key, "value-3");
DistributedPutAllOperation dpao = region.newPutAllOperation(map, null);
EntryEventImpl event = EntryEventImpl.create(region, Operation.PUTALL_CREATE, null, null, null, true, (DistributedMember) tag.getMemberID());
event.setOldValue("value-1");
event.setVersionTag(tag);
event.setEventId(new EventID(cache.getDistributedSystem()));
event.setKeyInfo(((PartitionedRegion) region).getKeyInfo(key));
dpao.addEntry(event, event.getKeyInfo().getBucketId());
// getLogWriter().info("dpao data = " + dpao.getPutAllEntryData()[0]);
VersionedObjectList successfulPuts = new VersionedObjectList(1, true, true);
successfulPuts.addKeyAndVersion(key, tag);
try {
region.postPutAllSend(dpao, successfulPuts);
} catch (ConcurrentCacheModificationException e) {
Assert.fail("Should not have received an exception for an elided operation", e);
} finally {
event.release();
dpao.getBaseEvent().release();
dpao.freeOffHeapResources();
}
} catch (Exception e) {
Assert.fail("caught unexpected exception", e);
}
}
});
entry = region.getEntry(key);
assertTrue("expected value-2: " + entry.getValue(), entry.getValue().equals("value-2"));
RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
final VersionTag<?> tag = regionEntry.getVersionStamp().asVersionTag();
assertTrue(tag.getEntryVersion() == 2);
}
Aggregations