Search in sources :

Example 1 with RegionExistsException

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

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;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionExistsException(org.apache.geode.cache.RegionExistsException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException)

Example 3 with RegionExistsException

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));
    }
}
Also used : RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CreateSubregionException(org.apache.geode.management.internal.cli.exceptions.CreateSubregionException) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CreateSubregionException(org.apache.geode.management.internal.cli.exceptions.CreateSubregionException) Cache(org.apache.geode.cache.Cache)

Example 4 with RegionExistsException

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);
    }
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) Region(org.apache.geode.cache.Region) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionExistsException(org.apache.geode.cache.RegionExistsException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with RegionExistsException

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

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