use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class PartitionedRegionWithSameNameDUnitTest method createMultipleDistributedlRegion.
CacheSerializableRunnable createMultipleDistributedlRegion(final String prPrefix, final int startIndexForRegion, final int endIndexForRegion, final Scope scope, final boolean firstCreationFlag, final boolean multipleVMFlag) {
CacheSerializableRunnable createLocalRegion = new CacheSerializableRunnable("createDistributedRegion") {
String innerPrPrefix = prPrefix;
int innerStartIndexForRegion = startIndexForRegion;
int innerEndIndexForRegion = endIndexForRegion;
Scope innerScope = scope;
boolean innerFirstCreationFlag = firstCreationFlag;
public void run2() throws CacheException {
Cache cache = getCache();
AttributesFactory af = new AttributesFactory();
af.setScope(innerScope);
RegionAttributes ra = af.create();
if (firstCreationFlag) {
for (int i = innerStartIndexForRegion; i < innerEndIndexForRegion; i++) {
try {
cache.createRegion(innerPrPrefix + i, ra);
} catch (RegionExistsException ex) {
Assert.fail("Got incorrect exception because the partition region being created prior to local region", ex);
}
}
} else {
for (int i = innerStartIndexForRegion; i < innerEndIndexForRegion; i++) {
if (!multipleVMFlag) {
try {
cache.createRegion(innerPrPrefix + i, ra);
fail("test failed : Distributed region with same name as Partitioned region gets created");
} catch (RegionExistsException expected) {
// getLogWriter()
// .info(
// "Expected exception RegionExistsException for creating
// distributed region with the same name as Partition Region"
// + ex);
}
} else {
final String expectedExceptions = IllegalStateException.class.getName();
getCache().getLogger().info("<ExpectedException action=add>" + expectedExceptions + "</ExpectedException>");
try {
cache.createRegion(innerPrPrefix + i, ra);
fail("test failed : Distributed region with same name as Partitioned region gets created");
} catch (IllegalStateException expected) {
// getLogWriter()
// .info(
// "Expected exception IllegalStateException for creating
// distributed region with the same name as Partition Region"
// + ex);
}
getCache().getLogger().info("<ExpectedException action=remove>" + expectedExceptions + "</ExpectedException>");
}
}
}
}
};
return createLocalRegion;
}
use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class RegionConfigurationCacheListener method afterRegionCreate.
public void afterRegionCreate(RegionEvent<String, RegionConfiguration> event) {
StringBuilder builder1 = null, builder2 = null;
Region<String, RegionConfiguration> region = event.getRegion();
if (this.cache.getLogger().fineEnabled()) {
builder1 = new StringBuilder();
int regionSize = region.size();
if (regionSize > 0) {
builder1.append("RegionConfigurationCacheListener region ").append(region.getName()).append(" has been initialized with the following ").append(regionSize).append(" region configurations:\n");
builder2 = new StringBuilder();
builder2.append("RegionConfigurationCacheListener created the following ").append(regionSize).append(" regions:\n");
} else {
builder1.append("RegionConfigurationCacheListener region ").append(region.getName()).append(" has been initialized with no region configurations");
}
}
for (RegionConfiguration configuration : region.values()) {
if (this.cache.getLogger().fineEnabled()) {
builder1.append("\t").append(configuration);
}
try {
Region createRegion = RegionHelper.createRegion(this.cache, configuration);
if (this.cache.getLogger().fineEnabled()) {
builder2.append("\t").append(createRegion);
}
} catch (RegionExistsException exists) {
// could have been concurrently created by another function
if (this.cache.getLogger().fineEnabled()) {
builder2.append("\t").append(" region existed");
}
}
}
if (this.cache.getLogger().fineEnabled()) {
this.cache.getLogger().fine(builder1.toString());
if (builder2 != null) {
this.cache.getLogger().fine(builder2.toString());
}
}
}
use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class CacheXml66DUnitTest method testCreateSameSubregionTwice.
/**
* Tests to make sure that we cannot create the same subregion multiple times in a
* {@code cache.xml} file.
*/
@Test
public void testCreateSameSubregionTwice() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
String name = this.getUniqueName();
Region root = cache.createRegion("root", attrs);
root.createSubregion(name, attrs);
try {
root.createSubregion(name, attrs);
fail("Should have thrown a RegionExistsException");
} catch (RegionExistsException ex) {
// pass...
}
setXmlFile(findFile("sameSubregion.xml"));
IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
try {
getCache();
fail("Should have thrown a CacheXmlException");
} catch (CacheXmlException ex) {
Throwable cause = ex.getCause();
assertTrue(cause instanceof SAXException);
cause = ((SAXException) cause).getException();
if (!(cause instanceof RegionExistsException)) {
Assert.fail("Expected a RegionExistsException, not a " + cause.getClass().getName(), cause);
}
} finally {
expectedException.remove();
}
}
use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class RegionCreation method create.
/**
* Creates a {@link Region} with the given parent using the description provided by this
* <code>RegionCreation</code>.
*
* @throws TimeoutException
* @throws CacheWriterException
* @throws RegionExistsException
* @throws IllegalStateException
*/
void create(Region parent) throws TimeoutException, CacheWriterException, RegionExistsException {
// Validate the attributes before creating the sub-region
this.attrs.inheritAttributes(parent.getCache());
this.attrs.prepareForValidation();
this.attrs.setIndexes(this.indexes);
Region me = null;
try {
me = parent.createSubregion(this.name, new AttributesFactory(this.attrs).create());
} catch (RegionExistsException ex) {
me = ex.getRegion();
setMutableAttributes(me);
} catch (RegionDestroyedException ex) {
// Region was concurrently destroyed.
cache.getLoggerI18n().warning(LocalizedStrings.RegionCreation_REGION_DESTROYED_DURING_INITIALIZATION, this.name);
// do nothing
}
if (me != null) {
// Register named region attributes
String id = this.attrs.getId();
if (id != null) {
RegionAttributes realAttrs = me.getAttributes();
me.getCache().setRegionAttributes(id, realAttrs);
}
fillIn(me);
}
}
use of org.apache.geode.cache.RegionExistsException in project geode by apache.
the class LocalRegion method createSubregion.
// TODO: createSubregion method is too complex for IDE to analyze
public Region createSubregion(String subregionName, RegionAttributes attrs, InternalRegionArguments internalRegionArgs) throws RegionExistsException, TimeoutException, IOException, ClassNotFoundException {
checkReadiness();
RegionAttributes regionAttributes = attrs;
// TODO: attrs is reassigned but never used
attrs = this.cache.invokeRegionBefore(this, subregionName, attrs, internalRegionArgs);
final InputStream snapshotInputStream = internalRegionArgs.getSnapshotInputStream();
final boolean getDestroyLock = internalRegionArgs.getDestroyLockFlag();
final InternalDistributedMember imageTarget = internalRegionArgs.getImageTarget();
LocalRegion newRegion = null;
try {
if (getDestroyLock)
acquireDestroyLock();
LocalRegion existing = null;
try {
if (isDestroyed()) {
if (this.reinitialized_old) {
throw new RegionReinitializedException(toString(), getFullPath());
}
throw new RegionDestroyedException(toString(), getFullPath());
}
validateRegionName(subregionName, internalRegionArgs);
validateSubregionAttributes(regionAttributes);
// deadlock)
synchronized (this.subregionsLock) {
existing = (LocalRegion) this.subregions.get(subregionName);
if (existing == null) {
if (regionAttributes.getScope().isDistributed() && internalRegionArgs.isUsedForPartitionedRegionBucket()) {
final PartitionedRegion pr = internalRegionArgs.getPartitionedRegion();
internalRegionArgs.setUserAttribute(pr.getUserAttribute());
if (pr.isShadowPR()) {
newRegion = new BucketRegionQueue(subregionName, regionAttributes, this, this.cache, internalRegionArgs);
} else {
newRegion = new BucketRegion(subregionName, regionAttributes, this, this.cache, internalRegionArgs);
}
} else if (regionAttributes.getPartitionAttributes() != null) {
newRegion = new PartitionedRegion(subregionName, regionAttributes, this, this.cache, internalRegionArgs);
} else {
boolean local = regionAttributes.getScope().isLocal();
newRegion = local ? new LocalRegion(subregionName, regionAttributes, this, this.cache, internalRegionArgs) : new DistributedRegion(subregionName, regionAttributes, this, this.cache, internalRegionArgs);
}
Object previousValue = this.subregions.putIfAbsent(subregionName, newRegion);
Assert.assertTrue(previousValue == null);
Assert.assertTrue(!newRegion.isInitialized());
if (logger.isDebugEnabled()) {
logger.debug("Subregion created: {}", newRegion.getFullPath());
}
if (snapshotInputStream != null || imageTarget != null || internalRegionArgs.getRecreateFlag()) {
// fix for bug 33534
this.cache.regionReinitialized(newRegion);
}
}
// endif: existing == null
}
// end synchronization
} finally {
if (getDestroyLock) {
releaseDestroyLock();
}
}
// Fix for bug 42127 - moved to outside of the destroy lock.
if (existing != null) {
// now outside of synchronization we must wait for appropriate
// initialization on existing region before returning a reference to
// it
existing.waitOnInitialization();
// fix for bug 32570
throw new RegionExistsException(existing);
}
boolean success = false;
try {
newRegion.checkReadiness();
this.cache.setRegionByPath(newRegion.getFullPath(), newRegion);
if (regionAttributes instanceof UserSpecifiedRegionAttributes) {
internalRegionArgs.setIndexes(((UserSpecifiedRegionAttributes) regionAttributes).getIndexes());
}
// releases initialization Latches
newRegion.initialize(snapshotInputStream, imageTarget, internalRegionArgs);
// register the region with resource manager to get memory events
if (!newRegion.isInternalRegion()) {
if (!newRegion.isDestroyed) {
this.cache.getInternalResourceManager().addResourceListener(ResourceType.MEMORY, newRegion);
if (!newRegion.getOffHeap()) {
newRegion.initialCriticalMembers(this.cache.getInternalResourceManager().getHeapMonitor().getState().isCritical(), this.cache.getResourceAdvisor().adviseCritialMembers());
} else {
newRegion.initialCriticalMembers(this.cache.getInternalResourceManager().getHeapMonitor().getState().isCritical() || this.cache.getInternalResourceManager().getOffHeapMonitor().getState().isCritical(), this.cache.getResourceAdvisor().adviseCritialMembers());
}
// synchronization would be done on ManagementAdapter.regionOpLock
// instead of destroyLock in LocalRegion? ManagementAdapter is one
// of the Resource Event listeners
InternalDistributedSystem system = this.cache.getInternalDistributedSystem();
system.handleResourceEvent(ResourceEvent.REGION_CREATE, newRegion);
}
}
success = true;
} catch (CancelException | RegionDestroyedException | RedundancyAlreadyMetException e) {
// don't print a call stack
throw e;
} catch (RuntimeException validationException) {
logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_INITIALIZATION_FAILED_FOR_REGION_0, getFullPath()), validationException);
throw validationException;
} finally {
if (!success) {
this.cache.setRegionByPath(newRegion.getFullPath(), null);
initializationFailed(newRegion);
this.cache.getInternalResourceManager(false).removeResourceListener(newRegion);
}
}
newRegion.postCreateRegion();
} finally {
// have occurred
if (newRegion != null && !newRegion.isInitialized()) {
if (logger.isDebugEnabled()) {
logger.debug("Region initialize latch is closed, Error must have occurred");
}
}
}
this.cache.invokeRegionAfter(newRegion);
return newRegion;
}
Aggregations