Search in sources :

Example 6 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 7 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 8 with ConcurrentParallelGatewaySenderQueue

use of org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue in project geode by apache.

the class CommonParallelGatewaySenderDUnitTest method validateParallelSenderQueueAllBucketsDrained.

public static void validateParallelSenderQueueAllBucketsDrained(final String senderId) {
    Set<GatewaySender> senders = cache.getGatewaySenders();
    GatewaySender sender = null;
    for (GatewaySender s : senders) {
        if (s.getId().equals(senderId)) {
            sender = s;
            break;
        }
    }
    ConcurrentParallelGatewaySenderQueue regionQueue = (ConcurrentParallelGatewaySenderQueue) ((AbstractGatewaySender) sender).getQueues().toArray(new RegionQueue[1])[0];
    Set<PartitionedRegion> shadowPRs = (Set<PartitionedRegion>) regionQueue.getRegions();
    for (PartitionedRegion shadowPR : shadowPRs) {
        Set<BucketRegion> buckets = shadowPR.getDataStore().getAllLocalBucketRegions();
        for (final BucketRegion bucket : buckets) {
            WaitCriterion wc = new WaitCriterion() {

                public boolean done() {
                    if (bucket.keySet().size() == 0) {
                        LogWriterUtils.getLogWriter().info("Bucket " + bucket.getId() + " is empty");
                        return true;
                    }
                    return false;
                }

                public String description() {
                    return "Expected bucket entries for bucket: " + bucket.getId() + " is: 0 but actual entries: " + bucket.keySet().size() + " This bucket isPrimary: " + bucket.getBucketAdvisor().isPrimary() + " KEYSET: " + bucket.keySet();
                }
            };
            Wait.waitForCriterion(wc, 180000, 50, true);
        }
    // for loop ends
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) Set(java.util.Set) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 9 with ConcurrentParallelGatewaySenderQueue

use of org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue in project geode by apache.

the class PartitionedRegion method addGatewaySenderId.

public void addGatewaySenderId(String gatewaySenderId) {
    super.addGatewaySenderId(gatewaySenderId);
    new UpdateAttributesProcessor(this).distribute();
    ((PartitionedRegion) this).distributeUpdatedProfileOnSenderCreation();
    GatewaySender sender = getCache().getGatewaySender(gatewaySenderId);
    if (sender != null && sender.isParallel() && sender.isRunning()) {
        AbstractGatewaySender senderImpl = (AbstractGatewaySender) sender;
        ((ConcurrentParallelGatewaySenderQueue) senderImpl.getQueues().toArray(new RegionQueue[1])[0]).addShadowPartitionedRegionForUserPR(this);
    }
}
Also used : AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) GatewaySender(org.apache.geode.cache.wan.GatewaySender) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 10 with ConcurrentParallelGatewaySenderQueue

use of org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue in project geode by apache.

the class PartitionedRegionDataStore method clearAllTempQueueForShadowPR.

protected void clearAllTempQueueForShadowPR(final int bucketId) {
    List<PartitionedRegion> colocatedWithList = ColocationHelper.getColocatedChildRegions(partitionedRegion);
    for (PartitionedRegion childRegion : colocatedWithList) {
        if (childRegion.isShadowPR()) {
            AbstractGatewaySender sender = childRegion.getParallelGatewaySender();
            if (sender == null) {
                return;
            }
            AbstractGatewaySenderEventProcessor eventProcessor = sender.getEventProcessor();
            if (eventProcessor == null) {
                return;
            }
            ConcurrentParallelGatewaySenderQueue queue = (ConcurrentParallelGatewaySenderQueue) eventProcessor.getQueue();
            if (queue == null) {
                return;
            }
            BlockingQueue<GatewaySenderEventImpl> tempQueue = queue.getBucketTmpQueue(bucketId);
            if (tempQueue != null) {
                synchronized (tempQueue) {
                    for (GatewaySenderEventImpl event : tempQueue) {
                        event.release();
                    }
                    tempQueue.clear();
                }
            }
        }
    }
}
Also used : ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) AbstractGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.AbstractGatewaySenderEventProcessor)

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