Search in sources :

Example 36 with VersionedObjectList

use of org.apache.geode.internal.cache.tier.sockets.VersionedObjectList in project geode by apache.

the class LocalRegion method logKeys.

private void logKeys(List serverKeys, InterestResultPolicy pol) {
    int totalKeys = 0;
    StringBuffer buffer = new StringBuffer();
    for (final Object serverKey : serverKeys) {
        List keysList = (List) serverKey;
        // TODO: is this still possible?
        if (keysList == null) {
            continue;
        }
        int numThisChunk = keysList.size();
        totalKeys += numThisChunk;
        for (Object key : keysList) {
            if (key != null) {
                if (key instanceof VersionedObjectList) {
                    Set keys = ((VersionedObjectList) key).keySet();
                    for (Object k : keys) {
                        buffer.append("  ").append(k).append(getLineSeparator());
                    }
                } else {
                    buffer.append("  ").append(key).append(getLineSeparator());
                }
            }
        }
    }
    // for
    if (logger.isDebugEnabled()) {
        logger.debug("{} refreshEntriesFromServerKeys count={} policy={}{}{}", this, totalKeys, pol, getLineSeparator(), buffer);
    }
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) AbstractSet(java.util.AbstractSet) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) StoredObject(org.apache.geode.internal.offheap.StoredObject) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) ArrayList(java.util.ArrayList) List(java.util.List) Endpoint(org.apache.geode.cache.client.internal.Endpoint)

Example 37 with VersionedObjectList

use of org.apache.geode.internal.cache.tier.sockets.VersionedObjectList 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

VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)37 HashMap (java.util.HashMap)13 Map (java.util.Map)12 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)12 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)12 CacheClosedException (org.apache.geode.cache.CacheClosedException)10 PutAllPartialResult (org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult)10 ArrayList (java.util.ArrayList)9 Iterator (java.util.Iterator)9 List (java.util.List)9 CancelException (org.apache.geode.CancelException)9 CacheException (org.apache.geode.cache.CacheException)9 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)9 IOException (java.io.IOException)8 PutAllPartialResultException (org.apache.geode.internal.cache.PutAllPartialResultException)8 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)8 Released (org.apache.geode.internal.offheap.annotations.Released)8 ExecutionException (java.util.concurrent.ExecutionException)7 InternalGemFireException (org.apache.geode.InternalGemFireException)7 CacheWriterException (org.apache.geode.cache.CacheWriterException)7