Search in sources :

Example 11 with RegionExistsException

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;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Scope(org.apache.geode.cache.Scope) RegionAttributes(org.apache.geode.cache.RegionAttributes) RegionExistsException(org.apache.geode.cache.RegionExistsException) Cache(org.apache.geode.cache.Cache)

Example 12 with RegionExistsException

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());
        }
    }
}
Also used : Region(org.apache.geode.cache.Region) RegionExistsException(org.apache.geode.cache.RegionExistsException)

Example 13 with RegionExistsException

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();
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 14 with RegionExistsException

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);
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionExistsException(org.apache.geode.cache.RegionExistsException)

Example 15 with RegionExistsException

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;
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) StoredObject(org.apache.geode.internal.offheap.StoredObject) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) CancelException(org.apache.geode.CancelException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException)

Aggregations

RegionExistsException (org.apache.geode.cache.RegionExistsException)18 AttributesFactory (org.apache.geode.cache.AttributesFactory)9 Region (org.apache.geode.cache.Region)7 RegionAttributes (org.apache.geode.cache.RegionAttributes)6 Cache (org.apache.geode.cache.Cache)5 IOException (java.io.IOException)4 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)4 CancelException (org.apache.geode.CancelException)3 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)3 InternalRegionArguments (org.apache.geode.internal.cache.InternalRegionArguments)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 InternalGemFireError (org.apache.geode.InternalGemFireError)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 CacheXmlException (org.apache.geode.cache.CacheXmlException)2 TimeoutException (org.apache.geode.cache.TimeoutException)2 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 CachePerfStats (org.apache.geode.internal.cache.CachePerfStats)2