use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class PRSanityCheckMessage method schedule.
/**
* Send a sanity check message and schedule a timer to send another one in
* gemfire.PRSanityCheckInterval (default 5000) milliseconds. This can be enabled with
* gemfire.PRSanityCheckEnabled=true.
*/
public static void schedule(final PartitionedRegion pr) {
if (Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "PRSanityCheckEnabled")) {
final DM dm = pr.getDistributionManager();
// RegionAdvisor ra = pr.getRegionAdvisor();
// final Set recipients = ra.adviseAllPRNodes();
DistributedRegion prRoot = (DistributedRegion) PartitionedRegionHelper.getPRRoot(pr.getCache(), false);
if (prRoot == null) {
return;
}
final Set recipients = prRoot.getDistributionAdvisor().adviseGeneric();
if (recipients.size() <= 0) {
return;
}
final PRSanityCheckMessage delayedInstance = new PRSanityCheckMessage(recipients, pr.getPRId(), null, pr.getRegionIdentifier());
PRSanityCheckMessage instance = new PRSanityCheckMessage(recipients, pr.getPRId(), null, pr.getRegionIdentifier());
dm.putOutgoing(instance);
int sanityCheckInterval = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "PRSanityCheckInterval", 5000).intValue();
if (sanityCheckInterval != 0) {
final SystemTimer tm = new SystemTimer(dm.getSystem(), true);
SystemTimer.SystemTimerTask st = new SystemTimer.SystemTimerTask() {
@Override
public void run2() {
try {
if (!pr.isLocallyDestroyed && !pr.isClosed && !pr.isDestroyed()) {
dm.putOutgoing(delayedInstance);
}
} catch (CancelException cce) {
// cache is closed - can't send the message
} finally {
tm.cancel();
}
}
};
tm.schedule(st, sanityCheckInterval);
}
}
}
use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class ParallelGatewaySenderEventProcessor method enqueueEvent.
@Override
public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue) throws IOException, CacheException {
GatewaySenderEventImpl gatewayQueueEvent = null;
Region region = event.getRegion();
if (!(region instanceof DistributedRegion) && ((EntryEventImpl) event).getTailKey() == -1) {
// Fix for #49081 and EntryDestroyedException in #49367.
if (logger.isDebugEnabled()) {
logger.debug("ParallelGatewaySenderEventProcessor not enqueing the following event since tailKey is not set. {}", event);
}
return;
}
// TODO: Looks like for PDX region bucket id is set to -1.
boolean queuedEvent = false;
try {
EventID eventID = ((EntryEventImpl) event).getEventId();
// while merging 42004, kept substituteValue as it is(it is barry's
// change 42466). bucketID is merged with eventID.getBucketID
gatewayQueueEvent = new GatewaySenderEventImpl(operation, event, substituteValue, true, eventID.getBucketID());
if (getSender().beforeEnqueue(gatewayQueueEvent)) {
long start = getSender().getStatistics().startTime();
try {
queuedEvent = this.queue.put(gatewayQueueEvent);
} catch (InterruptedException e) {
e.printStackTrace();
}
getSender().getStatistics().endPut(start);
} else {
if (logger.isDebugEnabled()) {
logger.debug("The Event {} is filtered.", gatewayQueueEvent);
}
getSender().getStatistics().incEventsFiltered();
}
} finally {
if (!queuedEvent) {
// it was not queued for some reason
gatewayQueueEvent.release();
}
}
}
use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class ParallelGatewaySenderQueue method remove.
@Override
public void remove() throws CacheException {
if (!this.peekedEvents.isEmpty()) {
GatewaySenderEventImpl event = this.peekedEvents.remove();
try {
PartitionedRegion prQ = null;
int bucketId = -1;
Object key = null;
if (event.getRegion() != null) {
if (isDREvent(event)) {
prQ = this.userRegionNameToshadowPRMap.get(event.getRegion().getFullPath());
bucketId = event.getEventId().getBucketID();
key = event.getEventId();
} else {
prQ = this.userRegionNameToshadowPRMap.get(ColocationHelper.getLeaderRegion((PartitionedRegion) event.getRegion()).getFullPath());
bucketId = event.getBucketId();
key = event.getShadowKey();
}
} else {
String regionPath = event.getRegionPath();
InternalCache cache = this.sender.getCache();
Region region = (PartitionedRegion) cache.getRegion(regionPath);
if (region != null && !region.isDestroyed()) {
// TODO: We have to get colocated parent region for this region
if (region instanceof DistributedRegion) {
prQ = this.userRegionNameToshadowPRMap.get(region.getFullPath());
event.getBucketId();
key = event.getEventId();
} else {
prQ = this.userRegionNameToshadowPRMap.get(ColocationHelper.getLeaderRegion((PartitionedRegion) region).getFullPath());
event.getBucketId();
key = event.getShadowKey();
}
}
}
if (prQ != null) {
destroyEventFromQueue(prQ, bucketId, key);
}
} finally {
try {
event.release();
} catch (IllegalStateException e) {
logger.error("Exception caught and logged. The thread will continue running", e);
}
}
}
}
use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class MembershipViewRequest method process.
@Override
protected void process(DistributionManager dm) {
int initLevel = this.targetReinitializing ? LocalRegion.AFTER_INITIAL_IMAGE : LocalRegion.ANY_INIT;
int oldLevel = LocalRegion.setThreadInitLevelRequirement(initLevel);
PersistentMembershipView view = null;
ReplyException exception = null;
try {
// get the region from the path, but do NOT wait on initialization,
// otherwise we could have a distributed deadlock
Cache cache = CacheFactory.getInstance(dm.getSystem());
Region region = cache.getRegion(this.regionPath);
PersistenceAdvisor persistenceAdvisor = null;
if (region instanceof DistributedRegion) {
persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
} else if (region == null) {
Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
if (proxy != null) {
persistenceAdvisor = proxy.getPersistenceAdvisor();
}
}
if (persistenceAdvisor != null) {
view = persistenceAdvisor.getMembershipView();
}
} catch (RegionDestroyedException e) {
// exception = new ReplyException(e);
logger.debug("<RegionDestroyed> {}", this);
} catch (CancelException e) {
// exception = new ReplyException(e);
logger.debug("<CancelException> {}", this);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
exception = new ReplyException(t);
} finally {
LocalRegion.setThreadInitLevelRequirement(oldLevel);
MembershipViewReplyMessage replyMsg = new MembershipViewReplyMessage();
replyMsg.setRecipient(getSender());
replyMsg.setProcessorId(processorId);
replyMsg.view = view;
if (logger.isDebugEnabled()) {
logger.debug("MembershipViewRequest returning view {} for region {}", view, this.regionPath);
}
if (exception != null) {
replyMsg.setException(exception);
}
dm.putOutgoing(replyMsg);
}
}
use of org.apache.geode.internal.cache.DistributedRegion in project geode by apache.
the class PrepareNewPersistentMemberMessage method process.
@Override
protected void process(DistributionManager dm) {
// Set thread local flag to allow entrance through initialization Latch
int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
PersistentMemberState state = null;
PersistentMemberID myId = null;
ReplyException exception = null;
try {
// get the region from the path, but do NOT wait on initialization,
// otherwise we could have a distributed deadlock
Cache cache = CacheFactory.getInstance(dm.getSystem());
Region region = cache.getRegion(this.regionPath);
PersistenceAdvisor persistenceAdvisor = null;
if (region instanceof DistributedRegion) {
persistenceAdvisor = ((DistributedRegion) region).getPersistenceAdvisor();
} else if (region == null) {
Bucket proxy = PartitionedRegionHelper.getProxyBucketRegion(GemFireCacheImpl.getInstance(), this.regionPath, false);
if (proxy != null) {
persistenceAdvisor = proxy.getPersistenceAdvisor();
}
}
if (persistenceAdvisor != null) {
persistenceAdvisor.prepareNewMember(getSender(), oldId, newId);
}
} catch (RegionDestroyedException e) {
logger.debug("<RegionDestroyed> {}", this);
} catch (CancelException e) {
logger.debug("<CancelException> {}", this);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
exception = new ReplyException(t);
} finally {
LocalRegion.setThreadInitLevelRequirement(oldLevel);
ReplyMessage replyMsg = new ReplyMessage();
replyMsg.setRecipient(getSender());
replyMsg.setProcessorId(processorId);
if (exception != null) {
replyMsg.setException(exception);
}
dm.putOutgoing(replyMsg);
}
}
Aggregations