use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class RegionCreation method createRoot.
/**
* Creates a root {@link Region} in a given <code>Cache</code> based on the description provided
* by this <code>RegionCreation</code>.
*
* @throws TimeoutException
* @throws CacheWriterException
* @throws RegionExistsException
*/
void createRoot(Cache cache) throws TimeoutException, CacheWriterException, RegionExistsException {
Region root = null;
// Validate the attributes before creating the root region
this.attrs.inheritAttributes(cache);
this.attrs.setIndexes(this.indexes);
this.attrs.prepareForValidation();
extensionPoint.beforeCreate(cache);
try {
root = ((InternalCache) cache).basicCreateRegion(this.name, new AttributesFactory(this.attrs).create());
} catch (RegionExistsException ex) {
root = ex.getRegion();
setMutableAttributes(root);
} catch (RegionDestroyedException ex) {
// Region was concurrently destroyed.
cache.getLoggerI18n().warning(LocalizedStrings.RegionCreation_REGION_DESTROYED_DURING_INITIALIZATION, this.name);
// do nothing
}
if (root != null) {
fillIn(root);
}
}
use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class AbstractGatewaySender method initializeEventIdIndexMetaDataRegion.
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
private static synchronized Region<String, Integer> initializeEventIdIndexMetaDataRegion(AbstractGatewaySender sender) {
final InternalCache cache = sender.getCache();
Region<String, Integer> region = cache.getRegion(META_DATA_REGION_NAME);
if (region == null) {
// Create region attributes (must be done this way to use InternalRegionArguments)
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
RegionAttributes ra = factory.create();
// Create a stats holder for the meta data stats
final HasCachePerfStats statsHolder = new HasCachePerfStats() {
public CachePerfStats getCachePerfStats() {
return new CachePerfStats(cache.getDistributedSystem(), META_DATA_REGION_NAME);
}
};
// Create internal region arguments
InternalRegionArguments ira = new InternalRegionArguments().setIsUsedForMetaRegion(true).setCachePerfStatsHolder(statsHolder);
// Create the region
try {
region = cache.createVMRegion(META_DATA_REGION_NAME, ra, ira);
} catch (RegionExistsException e) {
region = cache.getRegion(META_DATA_REGION_NAME);
} catch (Exception e) {
throw new IllegalStateException(LocalizedStrings.AbstractGatewaySender_META_REGION_CREATION_EXCEPTION_0.toLocalizedString(sender), e);
}
}
return region;
}
use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class RegionCreateFunction method execute.
@Override
public void execute(FunctionContext context) {
ResultSender<Object> resultSender = context.getResultSender();
Cache cache = CacheFactory.getAnyInstance();
String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
RegionFunctionArgs regionCreateArgs = (RegionFunctionArgs) context.getArguments();
if (regionCreateArgs.isSkipIfExists()) {
Region<Object, Object> region = cache.getRegion(regionCreateArgs.getRegionPath());
if (region != null) {
resultSender.lastResult(new CliFunctionResult(memberNameOrId, true, CliStrings.format(CliStrings.CREATE_REGION__MSG__SKIPPING_0_REGION_PATH_1_ALREADY_EXISTS, new Object[] { memberNameOrId, regionCreateArgs.getRegionPath() })));
return;
}
}
try {
Region<?, ?> createdRegion = createRegion(cache, regionCreateArgs);
XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", createdRegion.getName());
resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format(CliStrings.CREATE_REGION__MSG__REGION_0_CREATED_ON_1, new Object[] { createdRegion.getFullPath(), memberNameOrId })));
} catch (IllegalStateException e) {
String exceptionMsg = e.getMessage();
String localizedString = LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString();
if (localizedString.equals(e.getMessage())) {
exceptionMsg = exceptionMsg + " " + CliStrings.format(CliStrings.CREATE_REGION__MSG__USE_ONE_OF_THESE_SHORTCUTS_0, new Object[] { String.valueOf(CreateAlterDestroyRegionCommands.PERSISTENT_OVERFLOW_SHORTCUTS) });
}
resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, null));
} catch (IllegalArgumentException e) {
resultSender.lastResult(handleException(memberNameOrId, e.getMessage(), e));
} catch (RegionExistsException e) {
String exceptionMsg = CliStrings.format(CliStrings.CREATE_REGION__MSG__REGION_PATH_0_ALREADY_EXISTS_ON_1, new Object[] { regionCreateArgs.getRegionPath(), memberNameOrId });
resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, e));
} catch (CreateSubregionException e) {
resultSender.lastResult(handleException(memberNameOrId, e.getMessage(), e));
} catch (Exception e) {
String exceptionMsg = e.getMessage();
if (exceptionMsg == null) {
exceptionMsg = CliUtil.stackTraceAsString(e);
}
resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, e));
}
}
use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class QRegionInterfaceJUnitTest method testUnsupportedExceptionInSubregionsMethod.
@Test
public void testUnsupportedExceptionInSubregionsMethod() {
Region region1 = null;
Region region2 = null;
try {
region1 = CacheUtils.getRegion("/Portfolios").createSubregion("region1", CacheUtils.getRegion("/Portfolios").getAttributes());
region2 = CacheUtils.getRegion("/Portfolios").createSubregion("region2", CacheUtils.getRegion("/Portfolios").getAttributes());
} catch (RegionExistsException ree) {
fail("Test failed because of Exception= " + ree);
}
region1.put("5", new Portfolio(0));
region1.put("5", new Portfolio(1));
region2.put("6", new Portfolio(2));
region2.put("6", new Portfolio(3));
Query query = CacheUtils.getQueryService().newQuery("select distinct * from /Portfolios.subregions(false) where remove('5')!= null");
try {
query.execute();
assertTrue(!region1.containsKey("5"));
assertTrue(!region2.containsKey("5"));
fail("The test should have thrown TypeMismatchException exception");
} catch (TypeMismatchException tme) {
// Test has passed successfuly as this exception is expected
} catch (Exception e) {
fail("Test failed because of Exception= " + e);
}
}
use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class LocalRegion method recreate.
/** must be holding destroy lock */
private void recreate(InputStream inputStream, InternalDistributedMember imageTarget) throws TimeoutException, IOException, ClassNotFoundException {
String thePath = getFullPath();
Region newRegion = null;
try {
LocalRegion parent = this.parentRegion;
// as diskstore name any more
if (this.diskStoreImpl != null && this.diskStoreImpl.getName().equals(DiskStoreFactory.DEFAULT_DISK_STORE_NAME) && this.diskStoreName == null && !useDefaultDiskStore()) {
this.diskStoreName = this.diskStoreImpl.getName();
}
RegionAttributes attrs = this;
boolean getDestroyLock = false;
InternalRegionArguments internalRegionArguments = new InternalRegionArguments().setDestroyLockFlag(getDestroyLock).setSnapshotInputStream(inputStream).setImageTarget(imageTarget).setRecreateFlag(true);
if (this instanceof BucketRegion) {
BucketRegion me = (BucketRegion) this;
internalRegionArguments.setPartitionedRegionBucketRedundancy(me.getRedundancyLevel());
}
if (parent == null) {
newRegion = this.cache.createVMRegion(this.regionName, attrs, internalRegionArguments);
} else {
newRegion = parent.createSubregion(this.regionName, attrs, internalRegionArguments);
}
// note that createVMRegion and createSubregion now call regionReinitialized
} catch (RegionExistsException e) {
// shouldn't happen since we're holding the destroy lock
throw new InternalGemFireError(LocalizedStrings.LocalRegion_GOT_REGIONEXISTSEXCEPTION_IN_REINITIALIZE_WHEN_HOLDING_DESTROY_LOCK.toLocalizedString(), e);
} finally {
if (newRegion == null) {
// failed to create region
this.cache.unregisterReinitializingRegion(thePath);
}
}
}
Aggregations