Search in sources :

Example 11 with EntrySnapshot

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;
}
Also used : Entry(org.apache.geode.cache.Region.Entry) NonLocalRegionEntry(org.apache.geode.internal.cache.NonLocalRegionEntry) Entry(org.apache.geode.cache.Region.Entry) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Region(org.apache.geode.cache.Region) LocalRegion(org.apache.geode.internal.cache.LocalRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) NonLocalRegionEntry(org.apache.geode.internal.cache.NonLocalRegionEntry) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 12 with EntrySnapshot

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
}
Also used : Entry(java.util.Map.Entry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) List(java.util.List) ArrayList(java.util.ArrayList) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 13 with EntrySnapshot

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());
}
Also used : Entry(org.apache.geode.cache.Region.Entry) Entry(org.apache.geode.cache.Region.Entry) Iterator(java.util.Iterator) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 14 with EntrySnapshot

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[]);
    }
}
Also used : Set(java.util.Set) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) Iterator(java.util.Iterator) RegionEntry(org.apache.geode.internal.cache.RegionEntry) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot)

Example 15 with EntrySnapshot

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);
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) DistributedPutAllOperation(org.apache.geode.internal.cache.DistributedPutAllOperation) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) RegionEntry(org.apache.geode.internal.cache.RegionEntry) Entry(org.apache.geode.cache.Region.Entry) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) DistributedMember(org.apache.geode.distributed.DistributedMember) RegionEntry(org.apache.geode.internal.cache.RegionEntry) EventID(org.apache.geode.internal.cache.EventID) HashMap(java.util.HashMap) Map(java.util.Map) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

EntrySnapshot (org.apache.geode.internal.cache.EntrySnapshot)16 Region (org.apache.geode.cache.Region)7 RegionEntry (org.apache.geode.internal.cache.RegionEntry)7 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)7 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 Entry (org.apache.geode.cache.Region.Entry)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)4 Test (org.junit.Test)4 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 NonLocalRegionEntry (org.apache.geode.internal.cache.NonLocalRegionEntry)2 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)2 Tombstone (org.apache.geode.internal.cache.Token.Tombstone)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1