Search in sources :

Example 1 with AbstractBucketRegionQueue

use of org.apache.geode.internal.cache.AbstractBucketRegionQueue 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 2 with AbstractBucketRegionQueue

use of org.apache.geode.internal.cache.AbstractBucketRegionQueue in project geode by apache.

the class ParallelGatewaySenderQueue method put.

public boolean put(Object object) throws InterruptedException, CacheException {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    boolean putDone = false;
    // Can this region ever be null? Should we work with regionName and not with region
    // instance.
    // It can't be as put is happeing on the region and its still under process
    GatewaySenderEventImpl value = (GatewaySenderEventImpl) object;
    boolean isDREvent = isDREvent(value);
    Region region = value.getRegion();
    String regionPath = null;
    if (isDREvent) {
        regionPath = region.getFullPath();
    } else {
        regionPath = ColocationHelper.getLeaderRegion((PartitionedRegion) region).getFullPath();
    }
    if (isDebugEnabled) {
        logger.debug("Put is for the region {}", region);
    }
    if (!this.userRegionNameToshadowPRMap.containsKey(regionPath)) {
        if (isDebugEnabled) {
            logger.debug("The userRegionNameToshadowPRMap is {}", userRegionNameToshadowPRMap);
        }
        logger.warn(LocalizedMessage.create(LocalizedStrings.NOT_QUEUING_AS_USERPR_IS_NOT_YET_CONFIGURED, value));
        // does not put into queue
        return false;
    }
    PartitionedRegion prQ = this.userRegionNameToshadowPRMap.get(regionPath);
    int bucketId = value.getBucketId();
    Object key = null;
    if (!isDREvent) {
        key = value.getShadowKey();
        if ((Long) key == -1) {
            // through listener, so return.
            if (isDebugEnabled) {
                logger.debug("ParallelGatewaySenderOrderedQueue not putting key {} : Value : {}", key, value);
            }
            // does not put into queue
            return false;
        }
    } else {
        key = value.getEventId();
    }
    if (isDebugEnabled) {
        logger.debug("ParallelGatewaySenderOrderedQueue putting key {} : Value : {}", key, value);
    }
    AbstractBucketRegionQueue brq = (AbstractBucketRegionQueue) prQ.getDataStore().getLocalBucketById(bucketId);
    try {
        if (brq == null) {
            // Set the threadInitLevel to BEFORE_INITIAL_IMAGE.
            int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
            try {
                // Full path of the bucket:
                final String bucketFullPath = Region.SEPARATOR + PartitionedRegionHelper.PR_ROOT_REGION_NAME + Region.SEPARATOR + prQ.getBucketName(bucketId);
                brq = (AbstractBucketRegionQueue) prQ.getCache().getRegionByPath(bucketFullPath);
                if (isDebugEnabled) {
                    logger.debug("ParallelGatewaySenderOrderedQueue : The bucket in the cache is bucketRegionName : {} bucket : {}", bucketFullPath, brq);
                }
                if (brq != null) {
                    brq.getInitializationLock().readLock().lock();
                    try {
                        putIntoBucketRegionQueue(brq, key, value);
                        putDone = true;
                    } finally {
                        brq.getInitializationLock().readLock().unlock();
                    }
                } else if (isDREvent) {
                // in case of DR with PGS, if shadow bucket is not found event after
                // above search then it means that bucket is not intended for this
                // node. So lets not add this event in temp queue event as we are
                // doing it for PRevent
                // does not put onto the queue
                } else {
                    // In that case we don't want to store this event.
                    if (((PartitionedRegion) prQ.getColocatedWithRegion()).getRegionAdvisor().getBucketAdvisor(bucketId).getShadowBucketDestroyed()) {
                        if (isDebugEnabled) {
                            logger.debug("ParallelGatewaySenderOrderedQueue not putting key {} : Value : {} as shadowPR bucket is destroyed.", key, value);
                        }
                    // does not put onto the queue
                    } else {
                        /*
               * This is to prevent data loss, in the scenario when bucket is not available in the
               * cache but we know that it will be created.
               */
                        BlockingQueue tempQueue = null;
                        synchronized (this.bucketToTempQueueMap) {
                            tempQueue = this.bucketToTempQueueMap.get(bucketId);
                            if (tempQueue == null) {
                                tempQueue = new LinkedBlockingQueue();
                                this.bucketToTempQueueMap.put(bucketId, tempQueue);
                            }
                        }
                        synchronized (tempQueue) {
                            brq = (AbstractBucketRegionQueue) prQ.getCache().getRegionByPath(bucketFullPath);
                            if (brq != null) {
                                brq.getInitializationLock().readLock().lock();
                                try {
                                    putIntoBucketRegionQueue(brq, key, value);
                                    putDone = true;
                                } finally {
                                    brq.getInitializationLock().readLock().unlock();
                                }
                            } else {
                                tempQueue.add(value);
                                putDone = true;
                                // For debugging purpose.
                                if (isDebugEnabled) {
                                    logger.debug("The value {} is enqueued to the tempQueue for the BucketRegionQueue.", value);
                                }
                            }
                        }
                    }
                }
            } finally {
                LocalRegion.setThreadInitLevelRequirement(oldLevel);
            }
        } else {
            boolean thisbucketDestroyed = false;
            if (!isDREvent) {
                thisbucketDestroyed = ((PartitionedRegion) prQ.getColocatedWithRegion()).getRegionAdvisor().getBucketAdvisor(bucketId).getShadowBucketDestroyed() || brq.isDestroyed();
            } else {
                thisbucketDestroyed = brq.isDestroyed();
            }
            if (!thisbucketDestroyed) {
                putIntoBucketRegionQueue(brq, key, value);
                putDone = true;
            } else {
                if (isDebugEnabled) {
                    logger.debug("ParallelGatewaySenderOrderedQueue not putting key {} : Value : {} as shadowPR bucket is destroyed.", key, value);
                }
            // does not put onto the queue
            }
        }
    } finally {
        notifyEventProcessorIfRequired();
    }
    return putDone;
}
Also used : AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Aggregations

AbstractBucketRegionQueue (org.apache.geode.internal.cache.AbstractBucketRegionQueue)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Region (org.apache.geode.cache.Region)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 AbstractGatewaySender (org.apache.geode.internal.cache.wan.AbstractGatewaySender)1 GatewaySenderEventImpl (org.apache.geode.internal.cache.wan.GatewaySenderEventImpl)1