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;
}
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;
}
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());
}
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();
}
}
}
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();
}
}
}
Aggregations