Search in sources :

Example 91 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class ParallelGatewaySenderImpl method setModifiedEventId.

@Override
protected void setModifiedEventId(EntryEventImpl clonedEvent) {
    int bucketId = -1;
    // merged from 42004
    if (clonedEvent.getRegion() instanceof DistributedRegion) {
        bucketId = PartitionedRegionHelper.getHashKey(clonedEvent.getKey(), getMaxParallelismForReplicatedRegion());
    } else {
        bucketId = PartitionedRegionHelper.getHashKey((EntryOperation) clonedEvent);
    }
    EventID originalEventId = clonedEvent.getEventId();
    long originatingThreadId = ThreadIdentifier.getRealThreadID(originalEventId.getThreadID());
    long newThreadId = ThreadIdentifier.createFakeThreadIDForParallelGSPrimaryBucket(bucketId, originatingThreadId, getEventIdIndex());
    // In case of parallel as all events go through primary buckets
    // we don't need to generate different threadId for secondary buckets
    // as they will be rejected if seen at PR level itself
    EventID newEventId = new EventID(originalEventId.getMembershipID(), newThreadId, originalEventId.getSequenceID(), bucketId);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Generated event id for event with key={}, bucketId={}, original event id={}, threadId={}, new event id={}, newThreadId={}", this, clonedEvent.getKey(), bucketId, originalEventId, originatingThreadId, newEventId, newThreadId);
    }
    clonedEvent.setEventId(newEventId);
}
Also used : EventID(org.apache.geode.internal.cache.EventID) EntryOperation(org.apache.geode.cache.EntryOperation) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion)

Example 92 with EventID

use of org.apache.geode.internal.cache.EventID 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)

Example 93 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class PutAllDUnitTest method putAll.

/**
   * does an update and return the eventid generated. Eventid is caught in the listener and stored
   * in a static variable*
   */
public static Object[] putAll() {
    Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(region);
    try {
        Map map = new LinkedHashMap();
        map.put(PUTALL_KEY1, PUTALL_VALUE1);
        map.put(PUTALL_KEY2, PUTALL_VALUE2);
        map.put(PUTALL_KEY3, PUTALL_VALUE3);
        map.put(PUTALL_KEY4, PUTALL_VALUE4);
        map.put(PUTALL_KEY5, PUTALL_VALUE5);
        region.putAll(map, "putAllCallbackArg");
        EventID[] evids = new EventID[5];
        evids[0] = putAlleventId1;
        evids[1] = putAlleventId2;
        evids[2] = putAlleventId3;
        evids[3] = putAlleventId4;
        evids[4] = putAlleventId5;
        assertNotNull(evids[0]);
        assertNotNull(evids[1]);
        assertNotNull(evids[2]);
        assertNotNull(evids[3]);
        assertNotNull(evids[4]);
        return evids;
    } catch (Exception e) {
        fail("put failed due to " + e);
    }
    return null;
}
Also used : Region(org.apache.geode.cache.Region) EventID(org.apache.geode.internal.cache.EventID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CacheException(org.apache.geode.cache.CacheException) LinkedHashMap(java.util.LinkedHashMap)

Example 94 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class PutAllDUnitTest method assertThreadIdToSequenceIdMapHasEntryIds.

/** function to assert that the ThreadIdtoSequence id Map is not Null and has only one entry **/
public static Object[] assertThreadIdToSequenceIdMapHasEntryIds() {
    EventID[] evids = new EventID[5];
    Map map = pool.getThreadIdToSequenceIdMap();
    assertNotNull(map);
    evids[0] = putAlleventId1;
    evids[1] = putAlleventId2;
    evids[2] = putAlleventId3;
    evids[3] = putAlleventId4;
    evids[4] = putAlleventId5;
    assertNotNull(evids[0]);
    assertNotNull(evids[1]);
    assertNotNull(evids[2]);
    assertNotNull(evids[3]);
    assertNotNull(evids[4]);
    return evids;
}
Also used : EventID(org.apache.geode.internal.cache.EventID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 95 with EventID

use of org.apache.geode.internal.cache.EventID in project geode by apache.

the class PutAllDUnitTest method assertThreadIdToSequenceIdMapHasEntryId.

/** function to assert that the ThreadIdtoSequence id Map is not Null and has only one entry **/
public static Object assertThreadIdToSequenceIdMapHasEntryId() {
    Map map = pool.getThreadIdToSequenceIdMap();
    assertNotNull(map);
    // The map size can now be 1 or 2 because of the server thread putting
    // the marker in the queue. If it is 2, the first entry is the server
    // thread; the second is the client thread. If it is 1, the entry is the
    // client thread. The size changes because of the map.clear call below.
    assertTrue(map.size() != 0);
    // Set the entry to the last entry
    Map.Entry entry = null;
    for (Iterator threadIdToSequenceIdMapIterator = map.entrySet().iterator(); threadIdToSequenceIdMapIterator.hasNext(); ) {
        entry = (Map.Entry) threadIdToSequenceIdMapIterator.next();
    }
    ThreadIdentifier tid = (ThreadIdentifier) entry.getKey();
    SequenceIdAndExpirationObject seo = (SequenceIdAndExpirationObject) entry.getValue();
    long sequenceId = seo.getSequenceId();
    EventID evId = new EventID(tid.getMembershipID(), tid.getThreadID(), sequenceId);
    synchronized (map) {
        map.clear();
    }
    return evId;
}
Also used : SequenceIdAndExpirationObject(org.apache.geode.cache.client.internal.QueueStateImpl.SequenceIdAndExpirationObject) Iterator(java.util.Iterator) EventID(org.apache.geode.internal.cache.EventID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

EventID (org.apache.geode.internal.cache.EventID)147 Test (org.junit.Test)66 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)58 IOException (java.io.IOException)41 Map (java.util.Map)33 CacheException (org.apache.geode.cache.CacheException)31 Conflatable (org.apache.geode.internal.cache.Conflatable)29 LocalRegion (org.apache.geode.internal.cache.LocalRegion)23 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)20 HashMap (java.util.HashMap)16 Part (org.apache.geode.internal.cache.tier.sockets.Part)16 ByteBuffer (java.nio.ByteBuffer)14 Iterator (java.util.Iterator)14 List (java.util.List)14 LinkedHashMap (java.util.LinkedHashMap)13 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)13 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12