Search in sources :

Example 6 with BucketRegionQueue

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

the class ParallelGatewaySenderQueue method getRandomPrimaryBucket.

protected int getRandomPrimaryBucket(PartitionedRegion prQ) {
    if (prQ != null) {
        Set<Map.Entry<Integer, BucketRegion>> allBuckets = prQ.getDataStore().getAllLocalBuckets();
        List<Integer> thisProcessorBuckets = new ArrayList<Integer>();
        for (Map.Entry<Integer, BucketRegion> bucketEntry : allBuckets) {
            BucketRegion bucket = bucketEntry.getValue();
            if (bucket.getBucketAdvisor().isPrimary()) {
                int bId = bucket.getId();
                if (bId % this.nDispatcher == this.index) {
                    thisProcessorBuckets.add(bId);
                }
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("getRandomPrimaryBucket: total {} for this processor: {}", allBuckets.size(), thisProcessorBuckets.size());
        }
        int nTry = thisProcessorBuckets.size();
        while (nTry-- > 0) {
            if (pickBucketId >= thisProcessorBuckets.size())
                pickBucketId = 0;
            BucketRegionQueue br = getBucketRegionQueueByBucketId(prQ, thisProcessorBuckets.get(pickBucketId++));
            if (br != null && br.isReadyForPeek()) {
                return br.getId();
            }
        }
    // TODO:REF: instead of shuffle use random number, in this method we are
    // returning id instead we should return BRQ itself
    }
    return -1;
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 7 with BucketRegionQueue

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

the class ParallelGatewaySenderQueue method peek.

// Need to improve here.If first peek returns NULL then look in another bucket.
@Override
public Object peek() throws InterruptedException, CacheException {
    Object object = null;
    int bucketId = -1;
    PartitionedRegion prQ = getRandomShadowPR();
    if (prQ != null && prQ.getDataStore().getAllLocalBucketRegions().size() > 0 && ((bucketId = getRandomPrimaryBucket(prQ)) != -1)) {
        BucketRegionQueue brq;
        try {
            brq = ((BucketRegionQueue) prQ.getDataStore().getInitializedBucketForId(null, bucketId));
            object = brq.peek();
        } catch (BucketRegionQueueUnavailableException e) {
            // since this is not set, it would be null
            return object;
        } catch (ForceReattemptException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Remove: Got ForceReattemptException for {} for bucke = {}", this, bucketId);
            }
        }
    }
    // OFFHEAP: ok since only callers uses it to check for empty queue
    return object;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 8 with BucketRegionQueue

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

the class ParallelGatewaySenderQueue method destroyEventFromQueue.

private void destroyEventFromQueue(PartitionedRegion prQ, int bucketId, Object key) {
    boolean isPrimary = prQ.getRegionAdvisor().getBucketAdvisor(bucketId).isPrimary();
    BucketRegionQueue brq = getBucketRegionQueueByBucketId(prQ, bucketId);
    // before destroying a key from it
    try {
        if (brq != null) {
            brq.destroyKey(key);
        }
        stats.decQueueSize();
    } catch (EntryNotFoundException e) {
        if (!this.sender.isBatchConflationEnabled() && logger.isDebugEnabled()) {
            logger.debug("ParallelGatewaySenderQueue#remove: Got EntryNotFoundException while removing key {} for {} for bucket = {} for GatewaySender {}", key, this, bucketId, this.sender);
        }
    } catch (ForceReattemptException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Bucket :{} moved to other member", bucketId);
        }
    } catch (PrimaryBucketException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Primary bucket :{} moved to other member", bucketId);
        }
    } catch (RegionDestroyedException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Caught RegionDestroyedException attempting to remove key {} from bucket {} in {}", key, bucketId, prQ.getFullPath());
        }
    }
    addRemovedEvent(prQ, bucketId, key);
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException)

Example 9 with BucketRegionQueue

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

the class ParallelGatewaySenderQueue method addPeekedEvents.

private void addPeekedEvents(List<GatewaySenderEventImpl> batch, int batchSize) {
    if (this.resetLastPeeked) {
        // This will prevent repeatedly trying to dispatch non-primary events
        for (Iterator<GatewaySenderEventImpl> iterator = peekedEvents.iterator(); iterator.hasNext(); ) {
            GatewaySenderEventImpl event = iterator.next();
            final int bucketId = event.getBucketId();
            final PartitionedRegion region = (PartitionedRegion) event.getRegion();
            if (!region.getRegionAdvisor().isPrimaryForBucket(bucketId)) {
                iterator.remove();
                BucketRegionQueue brq = getBucketRegionQueueByBucketId(getRandomShadowPR(), bucketId);
                if (brq != null) {
                    brq.pushKeyIntoQueue(event.getShadowKey());
                }
            }
        }
        if (this.peekedEventsProcessingInProgress) {
            // Peeked event processing is in progress. This means that the original peekedEvents
            // contained > batch size events due to a reduction in the batch size. Create a batch
            // from the peekedEventsProcessing queue.
            addPreviouslyPeekedEvents(batch, batchSize);
        } else if (peekedEvents.size() <= batchSize) {
            // This is the normal case. The connection was lost while processing a batch.
            // This recreates the batch from the current peekedEvents.
            batch.addAll(peekedEvents);
            this.resetLastPeeked = false;
        } else {
            // The peekedEvents queue is > batch size. This means that the previous batch size was
            // reduced due to MessageTooLargeException. Create a batch from the peekedEventsProcessing
            // queue.
            this.peekedEventsProcessing.addAll(this.peekedEvents);
            this.peekedEventsProcessingInProgress = true;
            addPreviouslyPeekedEvents(batch, batchSize);
        }
        if (logger.isDebugEnabled()) {
            StringBuffer buffer = new StringBuffer();
            for (Object ge : batch) {
                buffer.append("event :");
                buffer.append(ge);
            }
            logger.debug("Adding already peeked events to the batch {}", buffer);
        }
    }
}
Also used : BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl)

Example 10 with BucketRegionQueue

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

the class ParallelGatewaySenderQueue method peekAhead.

protected Object peekAhead(PartitionedRegion prQ, int bucketId) throws CacheException {
    Object object = null;
    BucketRegionQueue brq = getBucketRegionQueueByBucketId(prQ, bucketId);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Peekahead for the bucket {}", this, bucketId);
    }
    try {
        object = brq.peek();
    } catch (BucketRegionQueueUnavailableException e) {
        // this will be null
        return object;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Peeked object from bucket {} object: {}", this, bucketId, object);
    }
    if (object == null) {
        if (this.stats != null) {
            this.stats.incEventsNotQueuedConflated();
        }
    }
    // OFFHEAP: ok since callers are careful to do destroys on region queue after
    return object;
// finished with peeked object.
}
Also used : BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue)

Aggregations

BucketRegionQueue (org.apache.geode.internal.cache.BucketRegionQueue)10 AbstractBucketRegionQueue (org.apache.geode.internal.cache.AbstractBucketRegionQueue)9 ArrayList (java.util.ArrayList)5 GatewaySenderEventImpl (org.apache.geode.internal.cache.wan.GatewaySenderEventImpl)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Queue (java.util.Queue)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 Test (org.junit.Test)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 GatewaySenderStats (org.apache.geode.internal.cache.wan.GatewaySenderStats)3 HashMap (java.util.HashMap)2 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1