Search in sources :

Example 1 with ConcurrentParallelGatewaySenderQueue

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);
        }
    }
}
Also used : ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.AbstractGatewaySenderEventProcessor)

Example 2 with ConcurrentParallelGatewaySenderQueue

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();
    }
}
Also used : ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Example 3 with ConcurrentParallelGatewaySenderQueue

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();
                }
            }
        }
    // }
    }
}
Also used : ConcurrentHashSet(org.apache.geode.internal.concurrent.ConcurrentHashSet) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl)

Example 4 with ConcurrentParallelGatewaySenderQueue

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());
        }
    }
}
Also used : ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) AbstractGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.AbstractGatewaySenderEventProcessor)

Example 5 with ConcurrentParallelGatewaySenderQueue

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;
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Aggregations

ConcurrentParallelGatewaySenderQueue (org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue)16 GatewaySender (org.apache.geode.cache.wan.GatewaySender)8 AbstractGatewaySender (org.apache.geode.internal.cache.wan.AbstractGatewaySender)7 RegionQueue (org.apache.geode.internal.cache.RegionQueue)5 AbstractGatewaySenderEventProcessor (org.apache.geode.internal.cache.wan.AbstractGatewaySenderEventProcessor)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 BucketRegion (org.apache.geode.internal.cache.BucketRegion)2 GatewaySenderEventImpl (org.apache.geode.internal.cache.wan.GatewaySenderEventImpl)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 CancelException (org.apache.geode.CancelException)1