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;
}
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;
}
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);
}
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);
}
}
}
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.
}
Aggregations