Search in sources :

Example 6 with ThreadIdentifier

use of org.apache.geode.internal.cache.ha.ThreadIdentifier in project geode by apache.

the class QueueStateImpl method verifyIfDuplicate.

public boolean verifyIfDuplicate(EventID eid, boolean addToMap) {
    ThreadIdentifier tid = new ThreadIdentifier(eid.getMembershipID(), eid.getThreadID());
    long seqId = eid.getSequenceID();
    SequenceIdAndExpirationObject seo = null;
    // while the objects are being expired
    synchronized (this.threadIdToSequenceId) {
        seo = (SequenceIdAndExpirationObject) this.threadIdToSequenceId.get(tid);
        if (seo != null && seo.getSequenceId() >= seqId) {
            if (logger.isDebugEnabled()) {
                logger.debug(" got a duplicate entry with EventId {}. Ignoring the entry", eid);
            }
            // bug #41289: send ack to this server since it's sending old events
            seo.setAckSend(false);
            // seo.getSequenceId()));
            return true;
        } else if (addToMap) {
            ThreadIdentifier real_tid = new ThreadIdentifier(eid.getMembershipID(), ThreadIdentifier.getRealThreadIDIncludingWan(eid.getThreadID()));
            if (ThreadIdentifier.isPutAllFakeThreadID(eid.getThreadID())) {
                // it's a putAll
                seo = (SequenceIdAndExpirationObject) this.threadIdToSequenceId.get(real_tid);
                if (seo != null && seo.getSequenceId() >= seqId) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("got a duplicate putAll entry with eventId {}. Other operation with same thread id and bigger seqno {} has happened. Ignoring the entry", eid, seo.getSequenceId());
                    }
                    // bug #41289: send ack to servers that send old events
                    seo.setAckSend(false);
                    return true;
                } else {
                    // save the seqno for real thread id into a putAllSequenceId
                    this.threadIdToSequenceId.remove(real_tid);
                    this.threadIdToSequenceId.put(real_tid, seo == null ? new SequenceIdAndExpirationObject(-1, seqId) : new SequenceIdAndExpirationObject(seo.getSequenceId(), seqId));
                    // save seqno for tid
                    // here tid!=real_tid, for fake tid, putAllSeqno should be 0
                    this.threadIdToSequenceId.remove(tid);
                    this.threadIdToSequenceId.put(tid, new SequenceIdAndExpirationObject(seqId, -1));
                }
            } else {
                // non-putAll operation:
                // check putAllSeqno for real thread id
                // if request's seqno is smaller, reject
                // otherwise, update the seqno for tid
                seo = (SequenceIdAndExpirationObject) this.threadIdToSequenceId.get(real_tid);
                if (seo != null && seo.getPutAllSequenceId() >= seqId) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("got a duplicate non-putAll entry with eventId {}. One putAll operation with same real thread id and bigger seqno {} has happened. Ignoring the entry", eid, seo.getPutAllSequenceId());
                    }
                    // bug #41289: send ack to servers that send old events
                    seo.setAckSend(false);
                    return true;
                } else {
                    // here tid==real_tid
                    this.threadIdToSequenceId.remove(tid);
                    this.threadIdToSequenceId.put(tid, seo == null ? new SequenceIdAndExpirationObject(seqId, -1) : new SequenceIdAndExpirationObject(seqId, seo.getPutAllSequenceId()));
                }
            }
        }
    }
    return false;
}
Also used : ThreadIdentifier(org.apache.geode.internal.cache.ha.ThreadIdentifier)

Example 7 with ThreadIdentifier

use of org.apache.geode.internal.cache.ha.ThreadIdentifier in project geode by apache.

the class CacheClientNotifier method processDispatchedMessage.

/**
   * Adds or updates entry in the dispatched message map when client sends an ack.
   *
   * @return success
   */
public boolean processDispatchedMessage(ClientProxyMembershipID proxyId, EventID eid) {
    boolean success = false;
    CacheClientProxy proxy = getClientProxy(proxyId);
    if (proxy != null) {
        HARegionQueue harq = proxy.getHARegionQueue();
        harq.addDispatchedMessage(new ThreadIdentifier(eid.getMembershipID(), eid.getThreadID()), eid.getSequenceID());
        success = true;
    }
    return success;
}
Also used : ThreadIdentifier(org.apache.geode.internal.cache.ha.ThreadIdentifier) HARegionQueue(org.apache.geode.internal.cache.ha.HARegionQueue)

Example 8 with ThreadIdentifier

use of org.apache.geode.internal.cache.ha.ThreadIdentifier in project geode by apache.

the class EventTrackerDUnitTest method checkEventTracker.

private void checkEventTracker(LocalRegion region, int numberOfEvents) {
    EventTracker tracker = region.getEventTracker();
    ConcurrentMap<ThreadIdentifier, BulkOpHolder> memberToTags = tracker.getRecordedBulkOpVersionTags();
    assertEquals("memberToTags=" + memberToTags, 1, memberToTags.size());
    BulkOpHolder holder = memberToTags.values().iterator().next();
    // We expect the holder to retain only the last putAll that was performed.
    assertEquals("entryToVersionTags=" + holder.entryVersionTags, numberOfEvents, holder.entryVersionTags.size());
}
Also used : BulkOpHolder(org.apache.geode.internal.cache.EventTracker.BulkOpHolder) ThreadIdentifier(org.apache.geode.internal.cache.ha.ThreadIdentifier)

Example 9 with ThreadIdentifier

use of org.apache.geode.internal.cache.ha.ThreadIdentifier in project geode by apache.

the class ConnectionProxyJUnitTest method testNoAckSendByClient.

// No ack will be send if Redundancy level = 0
@Test
public void testNoAckSendByClient() {
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server = null;
    try {
        try {
            server = this.cache.addCacheServer();
            server.setPort(port);
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Failed to create server");
        }
        try {
            PoolFactory pf = PoolManager.createFactory();
            pf.addServer("localhost", port);
            pf.setSubscriptionEnabled(true);
            pf.setSubscriptionRedundancy(1);
            pf.setReadTimeout(20000);
            pf.setSubscriptionMessageTrackingTimeout(8000);
            pf.setSubscriptionAckInterval(2000);
            proxy = (PoolImpl) pf.create("clientPool");
            EventID eid = new EventID(new byte[0], 1, 1);
            if (proxy.verifyIfDuplicate(eid)) {
                fail(" eid should not be duplicate as it is a new entry");
            }
            seo = (SequenceIdAndExpirationObject) proxy.getThreadIdToSequenceIdMap().get(new ThreadIdentifier(new byte[0], 1));
            assertFalse(seo.getAckSend());
            // should not send an ack as redundancy level = 0;
            seo = (SequenceIdAndExpirationObject) proxy.getThreadIdToSequenceIdMap().get(new ThreadIdentifier(new byte[0], 1));
            verifyAckSend(30 * 1000, false);
            // should expire without sending an ack as redundancy level = 0.
            verifyExpiry(90 * 1000);
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Test testPeriodicAckSendByClient Failed");
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) ThreadIdentifier(org.apache.geode.internal.cache.ha.ThreadIdentifier) CacheServer(org.apache.geode.cache.server.CacheServer) EventID(org.apache.geode.internal.cache.EventID) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 10 with ThreadIdentifier

use of org.apache.geode.internal.cache.ha.ThreadIdentifier in project geode by apache.

the class ConnectionProxyJUnitTest method testPeriodicAckSendByClient.

@Test
public void testPeriodicAckSendByClient() {
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server = null;
    try {
        try {
            server = this.cache.addCacheServer();
            server.setPort(port);
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Failed to create server");
        }
        try {
            PoolFactory pf = PoolManager.createFactory();
            pf.addServer("localhost", port);
            pf.setSubscriptionEnabled(true);
            pf.setSubscriptionRedundancy(1);
            pf.setReadTimeout(20000);
            pf.setSubscriptionMessageTrackingTimeout(15000);
            pf.setSubscriptionAckInterval(5000);
            proxy = (PoolImpl) pf.create("clientPool");
            EventID eid = new EventID(new byte[0], 1, 1);
            if (proxy.verifyIfDuplicate(eid)) {
                fail(" eid should not be duplicate as it is a new entry");
            }
            seo = (SequenceIdAndExpirationObject) proxy.getThreadIdToSequenceIdMap().get(new ThreadIdentifier(new byte[0], 1));
            assertFalse(seo.getAckSend());
            // should send the ack to server
            seo = (SequenceIdAndExpirationObject) proxy.getThreadIdToSequenceIdMap().get(new ThreadIdentifier(new byte[0], 1));
            verifyAckSend(60 * 1000, true);
            // New update on same threadId
            eid = new EventID(new byte[0], 1, 2);
            if (proxy.verifyIfDuplicate(eid)) {
                fail(" eid should not be duplicate as it is a new entry");
            }
            seo = (SequenceIdAndExpirationObject) proxy.getThreadIdToSequenceIdMap().get(new ThreadIdentifier(new byte[0], 1));
            assertFalse(seo.getAckSend());
            // should send another ack to server
            seo = (SequenceIdAndExpirationObject) proxy.getThreadIdToSequenceIdMap().get(new ThreadIdentifier(new byte[0], 1));
            verifyAckSend(6000, true);
            // should expire with the this mentioned.
            verifyExpiry(15 * 1000);
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Test testPeriodicAckSendByClient Failed");
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) ThreadIdentifier(org.apache.geode.internal.cache.ha.ThreadIdentifier) CacheServer(org.apache.geode.cache.server.CacheServer) EventID(org.apache.geode.internal.cache.EventID) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

ThreadIdentifier (org.apache.geode.internal.cache.ha.ThreadIdentifier)20 HashMap (java.util.HashMap)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 EventID (org.apache.geode.internal.cache.EventID)4 Test (org.junit.Test)4 Map (java.util.Map)3 BulkOpHolder (org.apache.geode.internal.cache.EventTracker.BulkOpHolder)3 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 PoolFactory (org.apache.geode.cache.client.PoolFactory)2 CacheServer (org.apache.geode.cache.server.CacheServer)2 BucketRegion (org.apache.geode.internal.cache.BucketRegion)2 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)2 EventSeqnoHolder (org.apache.geode.internal.cache.EventTracker.EventSeqnoHolder)2 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)2 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)2 PutAllPartialResultException (org.apache.geode.internal.cache.PutAllPartialResultException)2 PutAllPartialResult (org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult)2 DispatchedAndCurrentEvents (org.apache.geode.internal.cache.ha.HARegionQueue.DispatchedAndCurrentEvents)2 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)2