use of org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue in project geode by apache.
the class BucketRegionQueue method conflateOldEntry.
private void conflateOldEntry(Conflatable object, Long tailKey) {
PartitionedRegion region = this.getPartitionedRegion();
Conflatable conflatableObject = object;
if (region.isConflationEnabled() && conflatableObject.shouldBeConflated()) {
Object keyToConflate = conflatableObject.getKeyToConflate();
String rName = object.getRegionToConflate();
if (logger.isDebugEnabled()) {
logger.debug(" The region name is : {}", rName);
}
Map latestIndexesForRegion = (Map) this.indexes.get(rName);
if (latestIndexesForRegion == null) {
latestIndexesForRegion = new ConcurrentHashMap();
this.indexes.put(rName, latestIndexesForRegion);
}
Long previousTailKey = (Long) latestIndexesForRegion.put(keyToConflate, tailKey);
if (previousTailKey != null) {
if (logger.isDebugEnabled()) {
logger.debug("{}: Conflating {} at queue index={} and previousTailKey: ", this, object, tailKey, previousTailKey);
}
AbstractGatewaySenderEventProcessor ep = region.getParallelGatewaySender().getEventProcessor();
if (ep == null)
return;
ConcurrentParallelGatewaySenderQueue queue = (ConcurrentParallelGatewaySenderQueue) ep.getQueue();
// Give the actual conflation work to another thread.
// ParallelGatewaySenderQueue takes care of maintaining a thread pool.
queue.conflateEvent(conflatableObject, getId(), previousTailKey);
} else {
region.getParallelGatewaySender().getStatistics().incConflationIndexesMapSize();
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("{}: Not conflating {}", this, object);
}
}
}
use of org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue in project geode by apache.
the class AbstractGatewaySender method destroy.
public void destroy(boolean initiator) {
try {
this.getLifeCycleLock().writeLock().lock();
// first, check if this sender is attached to any region. If so, throw
// GatewaySenderException
Set<LocalRegion> regions = this.cache.getApplicationRegions();
Iterator regionItr = regions.iterator();
while (regionItr.hasNext()) {
LocalRegion region = (LocalRegion) regionItr.next();
if (region.getAttributes().getGatewaySenderIds().contains(this.id)) {
throw new GatewaySenderException(LocalizedStrings.GatewaySender_COULD_NOT_DESTROY_SENDER_AS_IT_IS_STILL_IN_USE.toLocalizedString(this));
}
}
// close the GatewaySenderAdvisor
GatewaySenderAdvisor advisor = this.getSenderAdvisor();
if (advisor != null) {
if (logger.isDebugEnabled()) {
logger.debug("Stopping the GatewaySender advisor");
}
advisor.close();
}
// remove the sender from the cache
this.cache.removeGatewaySender(this);
// destroy the region underneath the sender's queue
if (initiator) {
Set<RegionQueue> regionQueues = getQueues();
if (regionQueues != null) {
for (RegionQueue regionQueue : regionQueues) {
try {
if (regionQueue instanceof ConcurrentParallelGatewaySenderQueue) {
Set<PartitionedRegion> queueRegions = ((ConcurrentParallelGatewaySenderQueue) regionQueue).getRegions();
for (PartitionedRegion queueRegion : queueRegions) {
queueRegion.destroyRegion();
}
} else {
// For SerialGatewaySenderQueue, do local destroy
regionQueue.getRegion().localDestroyRegion();
}
}// by several nodes simultaneously
catch (RegionDestroyedException e) {
// the region might have already been destroyed by other node. Just
// log
// the exception.
this.logger.info(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_REGION_0_UNDERLYING_GATEWAYSENDER_1_IS_ALREADY_DESTROYED, new Object[] { e.getRegionFullPath(), this }));
}
}
}
// END if (regionQueues != null)
}
} finally {
this.getLifeCycleLock().writeLock().unlock();
}
}
use of org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue in project geode by apache.
the class AbstractBucketRegionQueue method loadEventsFromTempQueue.
protected void loadEventsFromTempQueue() {
if (logger.isDebugEnabled()) {
logger.debug("For bucket {} about to load events from the temp queue...", getId());
}
Set queues = this.getPartitionedRegion().getParallelGatewaySender().getQueues();
if (queues != null) {
ConcurrentParallelGatewaySenderQueue prq = (ConcurrentParallelGatewaySenderQueue) queues.toArray()[0];
// synchronized (prq.getBucketToTempQueueMap()) {
BlockingQueue<GatewaySenderEventImpl> tempQueue = prq.getBucketTmpQueue(getId());
// .getBucketToTempQueueMap().get(getId());
if (tempQueue != null && !tempQueue.isEmpty()) {
synchronized (tempQueue) {
try {
// ParallelQueueRemovalMessage checks for the key in BucketRegionQueue
// and if not found there, it removes it from tempQueue. When tempQueue
// is getting loaded in BucketRegionQueue, it may not find the key in both.
// To fix this race, load the events in writeLock.
getInitializationLock().writeLock().lock();
// add the events from tempQueue to the region
GatewaySenderEventImpl event;
while ((event = tempQueue.poll()) != null) {
try {
event.setPossibleDuplicate(true);
if (this.addToQueue(event.getShadowKey(), event)) {
event = null;
}
} catch (ForceReattemptException e) {
if (logger.isDebugEnabled()) {
logger.debug("For bucket {} , enqueing event {} caused exception", getId(), event, e);
}
} finally {
if (event != null) {
event.release();
}
}
}
} finally {
if (!tempQueue.isEmpty()) {
for (GatewaySenderEventImpl e : tempQueue) {
e.release();
}
tempQueue.clear();
}
getInitializationLock().writeLock().unlock();
}
}
}
// }
}
}
use of org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue in project geode by apache.
the class AbstractBucketRegionQueue method notifyEventProcessor.
protected void notifyEventProcessor() {
AbstractGatewaySender sender = getPartitionedRegion().getParallelGatewaySender();
if (sender != null) {
AbstractGatewaySenderEventProcessor ep = sender.getEventProcessor();
if (ep != null) {
ConcurrentParallelGatewaySenderQueue queue = (ConcurrentParallelGatewaySenderQueue) ep.getQueue();
if (logger.isDebugEnabled()) {
logger.debug("notifyEventProcessor : {} event processor {} queue {}", sender, ep, queue);
}
queue.notifyEventProcessorIfRequired(this.getId());
}
}
}
use of org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue in project geode by apache.
the class WANTestBase method getPRQLocalSize.
/**
* To be used only for ParallelGatewaySender.
*
* @param senderId Id of the ParallelGatewaySender
*/
public static int getPRQLocalSize(String senderId) {
GatewaySender sender = null;
for (GatewaySender s : cache.getGatewaySenders()) {
if (s.getId().equals(senderId)) {
sender = s;
break;
}
}
if (sender.isParallel()) {
int totalSize = 0;
Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
for (RegionQueue q : queues) {
ConcurrentParallelGatewaySenderQueue prQ = (ConcurrentParallelGatewaySenderQueue) q;
totalSize += prQ.localSize();
}
return totalSize;
}
return -1;
}
Aggregations