Search in sources :

Example 16 with AbstractGatewaySender

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

the class ParallelQueueRemovalMessage method process.

@Override
protected void process(DistributionManager dm) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    final InternalCache cache;
    cache = GemFireCacheImpl.getInstance();
    if (cache != null) {
        int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
        try {
            for (Object name : regionToDispatchedKeysMap.keySet()) {
                final String regionName = (String) name;
                final PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
                if (region == null) {
                    continue;
                } else {
                    AbstractGatewaySender abstractSender = region.getParallelGatewaySender();
                    // Find the map: bucketId to dispatchedKeys
                    // Find the bucket
                    // Destroy the keys
                    Map bucketIdToDispatchedKeys = (Map) this.regionToDispatchedKeysMap.get(regionName);
                    for (Object bId : bucketIdToDispatchedKeys.keySet()) {
                        final String bucketFullPath = Region.SEPARATOR + PartitionedRegionHelper.PR_ROOT_REGION_NAME + Region.SEPARATOR + region.getBucketName((Integer) bId);
                        AbstractBucketRegionQueue brq = (AbstractBucketRegionQueue) cache.getRegionByPath(bucketFullPath);
                        if (isDebugEnabled) {
                            logger.debug("ParallelQueueRemovalMessage : The bucket in the cache is bucketRegionName : {} bucket: {}", bucketFullPath, brq);
                        }
                        List dispatchedKeys = (List) bucketIdToDispatchedKeys.get((Integer) bId);
                        if (dispatchedKeys != null) {
                            for (Object key : dispatchedKeys) {
                                // First, clear the Event from tempQueueEvents at AbstractGatewaySender level, if
                                // exists
                                // synchronize on AbstractGatewaySender.queuedEventsSync while doing so
                                abstractSender.removeFromTempQueueEvents(key);
                                if (brq != null) {
                                    if (brq.isInitialized()) {
                                        if (isDebugEnabled) {
                                            logger.debug("ParallelQueueRemovalMessage : The bucket {} is initialized. Destroying the key {} from BucketRegionQueue.", bucketFullPath, key);
                                        }
                                        // fix for #48082
                                        afterAckForSecondary_EventInBucket(abstractSender, brq, key);
                                        destroyKeyFromBucketQueue(brq, key, region);
                                    } else {
                                        // if bucket is not initialized, the event should either be in bucket or
                                        // tempQueue
                                        boolean isDestroyed = false;
                                        if (isDebugEnabled) {
                                            logger.debug("ParallelQueueRemovalMessage : The bucket {} is not yet initialized.", bucketFullPath);
                                        }
                                        brq.getInitializationLock().readLock().lock();
                                        try {
                                            if (brq.containsKey(key)) {
                                                // fix for #48082
                                                afterAckForSecondary_EventInBucket(abstractSender, brq, key);
                                                destroyKeyFromBucketQueue(brq, key, region);
                                                isDestroyed = true;
                                            }
                                            // Even if BucketRegionQueue does not have the key, it could be in the
                                            // tempQueue
                                            // remove it from there..defect #49196
                                            destroyFromTempQueue(brq.getPartitionedRegion(), (Integer) bId, key);
                                            // Finally, add the key to the failed batch removal keys so that it is
                                            // definitely removed from the bucket region queue
                                            brq.addToFailedBatchRemovalMessageKeys(key);
                                        } finally {
                                            brq.getInitializationLock().readLock().unlock();
                                        }
                                    }
                                } else {
                                    // brq is null. Destroy the event from tempQueue. Defect #49196
                                    destroyFromTempQueue(region, (Integer) bId, key);
                                }
                            }
                        }
                    }
                }
            }
        // for loop regionToDispatchedKeysMap.keySet()
        } finally {
            LocalRegion.setThreadInitLevelRequirement(oldLevel);
        }
    }
// cache != null
}
Also used : AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalCache(org.apache.geode.internal.cache.InternalCache) List(java.util.List) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with AbstractGatewaySender

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

the class ParallelGatewaySenderQueue method addShadowPartitionedRegionForUserRR.

public void addShadowPartitionedRegionForUserRR(DistributedRegion userRegion) {
    this.sender.getLifeCycleLock().writeLock().lock();
    PartitionedRegion prQ = null;
    if (logger.isDebugEnabled()) {
        logger.debug("addShadowPartitionedRegionForUserRR: Going to create shadowpr for userRegion {}", userRegion.getFullPath());
    }
    try {
        String regionName = userRegion.getFullPath();
        if (this.userRegionNameToshadowPRMap.containsKey(regionName))
            return;
        InternalCache cache = sender.getCache();
        final String prQName = getQueueName(sender.getId(), userRegion.getFullPath());
        prQ = (PartitionedRegion) cache.getRegion(prQName);
        if (prQ == null) {
            // TODO:REF:Avoid deprecated apis
            AttributesFactory fact = new AttributesFactory();
            // Fix for 48621 - don't enable concurrency checks
            // for queue buckets., event with persistence
            fact.setConcurrencyChecksEnabled(false);
            PartitionAttributesFactory pfact = new PartitionAttributesFactory();
            pfact.setTotalNumBuckets(sender.getMaxParallelismForReplicatedRegion());
            int localMaxMemory = userRegion.getDataPolicy().withStorage() ? sender.getMaximumQueueMemory() : 0;
            pfact.setLocalMaxMemory(localMaxMemory);
            // TODO:Kishor : THis need to be handled nicely
            pfact.setRedundantCopies(3);
            pfact.setPartitionResolver(new RREventIDResolver());
            if (sender.isPersistenceEnabled()) {
                fact.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            }
            fact.setDiskStoreName(sender.getDiskStoreName());
            // optimize with above check of enable persistence
            if (sender.isPersistenceEnabled())
                fact.setDiskSynchronous(sender.isDiskSynchronous());
            else {
                fact.setDiskSynchronous(false);
            }
            // allow for no overflow directory
            EvictionAttributes ea = EvictionAttributes.createLIFOMemoryAttributes(sender.getMaximumQueueMemory(), EvictionAction.OVERFLOW_TO_DISK);
            fact.setEvictionAttributes(ea);
            fact.setPartitionAttributes(pfact.create());
            final RegionAttributes ra = fact.create();
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Attempting to create queue region: {}", this, prQName);
            }
            ParallelGatewaySenderQueueMetaRegion meta = new ParallelGatewaySenderQueueMetaRegion(prQName, ra, null, cache, sender);
            try {
                prQ = (PartitionedRegion) cache.createVMRegion(prQName, ra, new InternalRegionArguments().setInternalMetaRegion(meta).setDestroyLockFlag(true).setSnapshotInputStream(null).setImageTarget(null));
                if (logger.isDebugEnabled()) {
                    logger.debug("Region created  : {} partition Attributes : {}", prQ, prQ.getPartitionAttributes());
                }
                // TODO This should not be set on the PR but on the GatewaySender
                prQ.enableConflation(sender.isBatchConflationEnabled());
                // This is required in case of persistent PR and sender.
                if (prQ.getLocalMaxMemory() != 0) {
                    Iterator<Integer> itr = prQ.getRegionAdvisor().getBucketSet().iterator();
                    while (itr.hasNext()) {
                        itr.next();
                    }
                }
            // In case of Replicated Region it may not be necessary.
            } catch (IOException veryUnLikely) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), veryUnLikely);
            } catch (ClassNotFoundException alsoUnlikely) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), alsoUnlikely);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Created queue region: {}", this, prQ);
            }
        } else {
            // started from stop operation)
            if (// HItesh: for first processor only
            this.index == 0)
                handleShadowPRExistsScenario(cache, prQ);
        }
        /*
       * Here, enqueueTempEvents need to be invoked when a sender is already running and userPR is
       * created later. When the flow comes here through start() method of sender i.e. userPR
       * already exists and sender is started later, the enqueueTempEvents is done in the start()
       * method of ParallelGatewaySender
       */
        if ((this.index == this.nDispatcher - 1) && this.sender.isRunning()) {
            ((AbstractGatewaySender) sender).enqueueTempEvents();
        }
    } finally {
        if (prQ != null) {
            this.userRegionNameToshadowPRMap.put(userRegion.getFullPath(), prQ);
        }
        this.sender.getLifeCycleLock().writeLock().unlock();
    }
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionAttributes(org.apache.geode.cache.RegionAttributes) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 18 with AbstractGatewaySender

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

the class LuceneTestUtilities method pauseSender.

public static void pauseSender(final Cache cache) {
    final AsyncEventQueueImpl queue = (AsyncEventQueueImpl) getIndexQueue(cache);
    if (queue == null) {
        return;
    }
    queue.getSender().pause();
    AbstractGatewaySender sender = (AbstractGatewaySender) queue.getSender();
    sender.getEventProcessor().waitForDispatcherToPause();
}
Also used : AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 19 with AbstractGatewaySender

use of org.apache.geode.internal.cache.wan.AbstractGatewaySender 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 20 with AbstractGatewaySender

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

the class ConcurrentSerialGatewaySenderEventProcessorJUnitTest method setUp.

@Before
public void setUp() throws Exception {
    AbstractGatewaySender sender = mock(AbstractGatewaySender.class);
    processor = new ConcurrentSerialGatewaySenderEventProcessor(sender);
    queue = mock(RegionQueue.class);
    when(queue.size()).thenReturn(3);
}
Also used : AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) RegionQueue(org.apache.geode.internal.cache.RegionQueue) Before(org.junit.Before)

Aggregations

AbstractGatewaySender (org.apache.geode.internal.cache.wan.AbstractGatewaySender)40 GatewaySender (org.apache.geode.cache.wan.GatewaySender)23 AttributesFactory (org.apache.geode.cache.AttributesFactory)6 ConcurrentParallelGatewaySenderQueue (org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue)6 IgnoredException (org.apache.geode.test.dunit.IgnoredException)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 Test (org.junit.Test)6 RegionQueue (org.apache.geode.internal.cache.RegionQueue)5 Properties (java.util.Properties)4 Set (java.util.Set)4 Region (org.apache.geode.cache.Region)4 GatewayEventFilter (org.apache.geode.cache.wan.GatewayEventFilter)4 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)4 GatewayTransportFilter (org.apache.geode.cache.wan.GatewayTransportFilter)4 MyGatewayEventFilter1 (org.apache.geode.cache30.MyGatewayEventFilter1)4 MyGatewayTransportFilter1 (org.apache.geode.cache30.MyGatewayTransportFilter1)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AsyncEventQueueImpl (org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl)3 MyGatewayTransportFilter2 (org.apache.geode.cache30.MyGatewayTransportFilter2)3