use of org.apache.geode.CancelException in project geode by apache.
the class GemFireCacheImpl method getPartitionedRegionMap.
private SortedMap<String, PartitionedRegion> getPartitionedRegionMap() {
SortedMap<String, PartitionedRegion> prMap = new TreeMap<>();
for (Entry<String, Region<?, ?>> entry : this.pathToRegion.entrySet()) {
String regionName = entry.getKey();
Region<?, ?> region = entry.getValue();
// Don't wait for non partitioned regions
if (!(region instanceof PartitionedRegion)) {
continue;
}
// to finish initialization
try {
Region pr = getRegion(regionName);
if (pr instanceof PartitionedRegion) {
prMap.put(regionName, (PartitionedRegion) pr);
}
} catch (CancelException ignore) {
// if some region throws cancel exception during initialization,
// then no need to shutDownAll them gracefully
}
}
return prMap;
}
use of org.apache.geode.CancelException in project geode by apache.
the class GemFireCacheImpl method createVMRegion.
// TODO: createVMRegion method is too complex for IDE to analyze
@Override
public <K, V> Region<K, V> createVMRegion(String name, RegionAttributes<K, V> p_attrs, InternalRegionArguments internalRegionArgs) throws RegionExistsException, TimeoutException, IOException, ClassNotFoundException {
if (getMyId().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) {
if (!internalRegionArgs.isUsedForMetaRegion() && internalRegionArgs.getInternalMetaRegion() == null) {
throw new IllegalStateException("Regions can not be created in a locator.");
}
}
this.stopper.checkCancelInProgress(null);
LocalRegion.validateRegionName(name, internalRegionArgs);
RegionAttributes<K, V> attrs = p_attrs;
attrs = invokeRegionBefore(null, name, attrs, internalRegionArgs);
if (attrs == null) {
throw new IllegalArgumentException(LocalizedStrings.GemFireCache_ATTRIBUTES_MUST_NOT_BE_NULL.toLocalizedString());
}
LocalRegion region;
final InputStream snapshotInputStream = internalRegionArgs.getSnapshotInputStream();
InternalDistributedMember imageTarget = internalRegionArgs.getImageTarget();
final boolean recreate = internalRegionArgs.getRecreateFlag();
final boolean isPartitionedRegion = attrs.getPartitionAttributes() != null;
final boolean isReInitCreate = snapshotInputStream != null || imageTarget != null || recreate;
try {
for (; ; ) {
getCancelCriterion().checkCancelInProgress(null);
Future future = null;
synchronized (this.rootRegions) {
region = this.rootRegions.get(name);
if (region != null) {
throw new RegionExistsException(region);
}
if (!isReInitCreate) {
// fix bug 33523
String fullPath = Region.SEPARATOR + name;
future = (Future) this.reinitializingRegions.get(fullPath);
}
if (future == null) {
if (internalRegionArgs.getInternalMetaRegion() != null) {
region = internalRegionArgs.getInternalMetaRegion();
} else if (isPartitionedRegion) {
region = new PartitionedRegion(name, attrs, null, this, internalRegionArgs);
} else {
if (attrs.getScope().isLocal()) {
region = new LocalRegion(name, attrs, null, this, internalRegionArgs);
} else {
region = new DistributedRegion(name, attrs, null, this, internalRegionArgs);
}
}
this.rootRegions.put(name, region);
if (isReInitCreate) {
regionReinitialized(region);
}
break;
}
}
// synchronized
boolean interrupted = Thread.interrupted();
try {
// future != null
// wait on Future
LocalRegion localRegion = (LocalRegion) future.get();
throw new RegionExistsException(localRegion);
} catch (InterruptedException ignore) {
interrupted = true;
} catch (ExecutionException e) {
throw new Error(LocalizedStrings.GemFireCache_UNEXPECTED_EXCEPTION.toLocalizedString(), e);
} catch (CancellationException e) {
// future was cancelled
if (logger.isTraceEnabled()) {
logger.trace("future cancelled", e);
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
// for
boolean success = false;
try {
setRegionByPath(region.getFullPath(), region);
region.initialize(snapshotInputStream, imageTarget, internalRegionArgs);
success = true;
} catch (CancelException | RedundancyAlreadyMetException e) {
// don't print a call stack
throw e;
} catch (RuntimeException validationException) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GemFireCache_INITIALIZATION_FAILED_FOR_REGION_0, region.getFullPath()), validationException);
throw validationException;
} finally {
if (!success) {
try {
// do this before removing the region from
// the root set to fix bug 41982.
region.cleanupFailedInitialization();
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
this.stopper.checkCancelInProgress(t);
// bug #44672 - log the failure but don't override the original exception
logger.warn(LocalizedMessage.create(LocalizedStrings.GemFireCache_INIT_CLEANUP_FAILED_FOR_REGION_0, region.getFullPath()), t);
} finally {
// clean up if initialize fails for any reason
setRegionByPath(region.getFullPath(), null);
synchronized (this.rootRegions) {
Region rootRegion = this.rootRegions.get(name);
if (rootRegion == region) {
this.rootRegions.remove(name);
}
}
// synchronized
}
}
// success
}
region.postCreateRegion();
} catch (RegionExistsException ex) {
// outside of sync make sure region is initialized to fix bug 37563
LocalRegion localRegion = (LocalRegion) ex.getRegion();
// don't give out ref until initialized
localRegion.waitOnInitialization();
throw ex;
}
invokeRegionAfter(region);
// Added for M&M . Putting the callback here to avoid creating RegionMBean in case of Exception
if (!region.isInternalRegion()) {
this.system.handleResourceEvent(ResourceEvent.REGION_CREATE, region);
}
return region;
}
use of org.apache.geode.CancelException in project geode by apache.
the class PartitionedRegion method sendDestroyRegionMessage.
/**
* Sends the partitioned region specific destroy region message and waits for any responses. This
* message is also sent in close/localDestroyRegion operation. When it is sent in Cache
* close/Region close/localDestroyRegion operations, it results in updating of RegionAdvisor on
* recipient nodes.
*
* @param event the destruction event
* @param serials the bucket serials hosted locally
* @see Region#destroyRegion()
* @see Region#close()
* @see Region#localDestroyRegion()
* @see GemFireCacheImpl#close()
*/
private void sendDestroyRegionMessage(RegionEventImpl event, int[] serials) {
if (this.prRoot == null) {
if (logger.isDebugEnabled()) {
logger.debug("Partition region {} failed to initialize. Remove its profile from remote members.", this);
}
new UpdateAttributesProcessor(this, true).distribute(false);
return;
}
final HashSet configRecipients = new HashSet(getRegionAdvisor().adviseAllPRNodes());
// sent a CreateRegionProcessor message, bug 36048
try {
final PartitionRegionConfig prConfig = this.prRoot.get(getRegionIdentifier());
if (prConfig != null) {
// Fix for bug#34621 by Tushar
Iterator itr = prConfig.getNodes().iterator();
while (itr.hasNext()) {
InternalDistributedMember idm = ((Node) itr.next()).getMemberId();
if (!idm.equals(getMyId())) {
configRecipients.add(idm);
}
}
}
} catch (CancelException ignore) {
// ignore
}
try {
DestroyPartitionedRegionResponse resp = DestroyPartitionedRegionMessage.send(configRecipients, this, event, serials);
resp.waitForRepliesUninterruptibly();
} catch (ReplyException e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_PARTITIONEDREGION_SENDDESTROYREGIONMESSAGE_CAUGHT_EXCEPTION_DURING_DESTROYREGIONMESSAGE_SEND_AND_WAITING_FOR_RESPONSE), e);
}
}
use of org.apache.geode.CancelException in project geode by apache.
the class PartitionedRegion method postDestroyRegion.
/**
* This method is invoked from recursiveDestroyRegion method of LocalRegion. This method checks
* the region type and invokes the relevant method.
*
* @param destroyDiskRegion - true if the contents on disk should be destroyed
* @param event the RegionEvent
*/
@Override
protected void postDestroyRegion(boolean destroyDiskRegion, RegionEventImpl event) {
if (logger.isDebugEnabled()) {
logger.debug("PartitionedRegion#postDestroyRegion: {}", this);
}
Assert.assertTrue(this.isDestroyed || this.isClosed);
// Fixes 44551 - wait for persistent buckets to finish
// recovering before sending the destroy region message
// any GII or wait for persistent recovery will be aborted by the destroy
// flag being set to true, so this shouldn't take long.
this.redundancyProvider.waitForPersistentBucketRecovery();
// fix #39196 OOME caused by leak in GemFireCache.partitionedRegions
this.cache.removePartitionedRegion(this);
this.cache.getInternalResourceManager(false).removeResourceListener(this);
final Operation op = event.getOperation();
stopMissingColocatedRegionLogger();
if (op.isClose() || Operation.REGION_LOCAL_DESTROY.equals(op)) {
try {
if (Operation.CACHE_CLOSE.equals(op) || Operation.FORCED_DISCONNECT.equals(op)) {
int[] serials = getRegionAdvisor().getBucketSerials();
try {
getRegionAdvisor().closeBucketAdvisors();
// BUGFIX for bug#34672 by Tushar Apshankar. It would update the
// advisors on other nodes about cache closing of this PartitionedRegion
sendDestroyRegionMessage(event, serials);
// to log the fact that those buckets are destroyed here
if (RegionLogger.isEnabled()) {
PartitionedRegionDataStore store = getDataStore();
if (store != null) {
for (BucketRegion bucket : store.getAllLocalBucketRegions()) {
RegionLogger.logDestroy(bucket.getFullPath(), getMyId(), bucket.getPersistentID(), true);
}
}
}
} catch (CancelException ignore) {
// Don't throw this; we're just trying to remove the region.
if (logger.isDebugEnabled()) {
logger.debug("postDestroyRegion: failed sending DestroyRegionMessage due to cache closure");
}
} finally {
// Since we are not calling closePartitionedRegion
// we need to cleanup any diskStore we own here.
// Why don't we call closePartitionedRegion?
// Instead of closing it, we need to register it to be closed later
// Otherwise, when the cache close tries to close all of the bucket regions,
// they'll fail because their disk store is already closed.
DiskStoreImpl dsi = getDiskStore();
if (dsi != null && dsi.getOwnedByRegion()) {
cache.addDiskStore(dsi);
}
}
// Majority of cache close operations handled by
// afterRegionsClosedByCacheClose(GemFireCache
// cache) or GemFireCache.close()
} else {
if (logger.isDebugEnabled()) {
logger.debug("Making closePartitionedRegion call for {} with origin = {} op= {}", this, event.isOriginRemote(), op);
}
try {
closePartitionedRegion(event);
} finally {
if (Operation.REGION_LOCAL_DESTROY.equals(op)) {
DiskStoreImpl dsi = getDiskStore();
if (dsi != null && dsi.getOwnedByRegion()) {
dsi.destroy();
}
}
}
}
} finally {
// tell other members to recover redundancy for any buckets
this.getRegionAdvisor().close();
getPrStats().close();
}
} else if (Operation.REGION_DESTROY.equals(op) || Operation.REGION_EXPIRE_DESTROY.equals(op)) {
if (logger.isDebugEnabled()) {
logger.debug("PartitionedRegion#postDestroyRegion: Making destroyPartitionedRegion call for {} with originRemote = {}", this, event.isOriginRemote());
}
destroyPartitionedRegion(event);
} else {
Assert.assertTrue(false, "Unknown op" + op);
}
// DistributedCacheOperation.distribute().
if (!isUsedForMetaRegion() && !isUsedForPartitionedRegionAdmin() && !isUsedForPartitionedRegionBucket() && !isUsedForParallelGatewaySenderQueue()) {
FilterRoutingInfo localCqFrInfo = getFilterProfile().getFilterRoutingInfoPart1(event, FilterProfile.NO_PROFILES, Collections.emptySet());
FilterRoutingInfo localCqInterestFrInfo = getFilterProfile().getFilterRoutingInfoPart2(localCqFrInfo, event);
if (localCqInterestFrInfo != null) {
event.setLocalFilterInfo(localCqInterestFrInfo.getLocalFilterInfo());
}
}
if (destroyDiskRegion) {
DiskStoreImpl dsi = getDiskStore();
if (dsi != null && getDataPolicy().withPersistence()) {
dsi.removePersistentPR(getFullPath());
// config from the parent disk store, if we are removing the region.
if (colocatedWithRegion != null && colocatedWithRegion.getDiskStore() != null && colocatedWithRegion.getDiskStore() != dsi) {
colocatedWithRegion.getDiskStore().removePersistentPR(getFullPath());
}
}
}
if (colocatedWithRegion != null) {
colocatedWithRegion.getColocatedByList().remove(this);
}
RegionLogger.logDestroy(getName(), this.cache.getInternalDistributedSystem().getDistributedMember(), null, op.isClose());
}
use of org.apache.geode.CancelException 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);
}
}
Aggregations