Search in sources :

Example 11 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.

the class ParallelGatewaySenderQueue method addShadowPartitionedRegionForUserPR.

public void addShadowPartitionedRegionForUserPR(PartitionedRegion userPR) {
    if (logger.isDebugEnabled()) {
        logger.debug("{} addShadowPartitionedRegionForUserPR: Attempting to create queue region: {}", this, userPR.getDisplayName());
    }
    this.sender.getLifeCycleLock().writeLock().lock();
    PartitionedRegion prQ = null;
    try {
        String regionName = userPR.getFullPath();
        // Find if there is any parent region for this userPR
        // if there is then no need to add another q for the same
        String leaderRegionName = ColocationHelper.getLeaderRegion(userPR).getFullPath();
        if (!regionName.equals(leaderRegionName)) {
            // colocation chain
            if (!this.userRegionNameToshadowPRMap.containsKey(leaderRegionName)) {
                addShadowPartitionedRegionForUserPR(ColocationHelper.getLeaderRegion(userPR));
            }
            return;
        }
        if (this.userRegionNameToshadowPRMap.containsKey(regionName))
            return;
        if (userPR.getDataPolicy().withPersistence() && !sender.isPersistenceEnabled()) {
            throw new GatewaySenderException(LocalizedStrings.ParallelGatewaySenderQueue_NON_PERSISTENT_GATEWAY_SENDER_0_CAN_NOT_BE_ATTACHED_TO_PERSISTENT_REGION_1.toLocalizedString(new Object[] { this.sender.getId(), userPR.getFullPath() }));
        }
        InternalCache cache = sender.getCache();
        boolean isAccessor = (userPR.getLocalMaxMemory() == 0);
        final String prQName = sender.getId() + QSTRING + convertPathToName(userPR.getFullPath());
        prQ = (PartitionedRegion) cache.getRegion(prQName);
        if (prQ == null) {
            // TODO:REF:Avoid deprecated apis
            AttributesFactory fact = new AttributesFactory();
            fact.setConcurrencyChecksEnabled(false);
            PartitionAttributesFactory pfact = new PartitionAttributesFactory();
            pfact.setTotalNumBuckets(userPR.getTotalNumberOfBuckets());
            pfact.setRedundantCopies(userPR.getRedundantCopies());
            pfact.setColocatedWith(regionName);
            // EITHER set localMaxMemory to 0 for accessor node
            // OR override shadowPRs default local max memory with the sender's max
            // queue memory (Fix for bug#44254)
            int localMaxMemory = isAccessor ? 0 : sender.getMaximumQueueMemory();
            pfact.setLocalMaxMemory(localMaxMemory);
            pfact.setStartupRecoveryDelay(userPR.getPartitionAttributes().getStartupRecoveryDelay());
            pfact.setRecoveryDelay(userPR.getPartitionAttributes().getRecoveryDelay());
            if (sender.isPersistenceEnabled() && !isAccessor) {
                fact.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            }
            fact.setDiskStoreName(sender.getDiskStoreName());
            // else set it to false
            if (sender.isPersistenceEnabled())
                fact.setDiskSynchronous(sender.isDiskSynchronous());
            else {
                fact.setDiskSynchronous(false);
            }
            // allow for no overflow directory
            EvictionAttributes ea = EvictionAttributes.createLIFOMemoryAttributes(sender.getMaximumQueueMemory(), EvictionAction.OVERFLOW_TO_DISK);
            fact.setEvictionAttributes(ea);
            fact.setPartitionAttributes(pfact.create());
            final RegionAttributes ra = fact.create();
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Attempting to create queue region: {}", this, prQName);
            }
            ParallelGatewaySenderQueueMetaRegion meta = metaRegionFactory.newMetataRegion(cache, prQName, ra, sender);
            try {
                prQ = (PartitionedRegion) cache.createVMRegion(prQName, ra, new InternalRegionArguments().setInternalMetaRegion(meta).setDestroyLockFlag(true).setInternalRegion(true).setSnapshotInputStream(null).setImageTarget(null));
                // at this point we should be able to assert prQ == meta;
                // TODO This should not be set on the PR but on the GatewaySender
                prQ.enableConflation(sender.isBatchConflationEnabled());
                if (isAccessor)
                    // return from here if accessor node
                    return;
                // Wait for buckets to be recovered.
                prQ.shadowPRWaitForBucketRecovery();
            } catch (IOException | ClassNotFoundException veryUnLikely) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), veryUnLikely);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Created queue region: {}", this, prQ);
            }
        } else {
            if (isAccessor)
                // return from here if accessor node
                return;
            // started from stop operation)
            if (// HItesh:for first parallelGatewaySenderQueue only
            this.index == 0)
                handleShadowPRExistsScenario(cache, prQ);
        }
    } finally {
        if (prQ != null) {
            this.userRegionNameToshadowPRMap.put(userPR.getFullPath(), prQ);
        }
        /*
       * Here, enqueueTempEvents need to be invoked when a sender is already running and userPR is
       * created later. When the flow comes here through start() method of sender i.e. userPR
       * already exists and sender is started later, the enqueueTempEvents is done in the start()
       * method of ParallelGatewaySender
       */
        if ((this.index == this.nDispatcher - 1) && this.sender.isRunning()) {
            ((AbstractGatewaySender) sender).enqueueTempEvents();
        }
        afterRegionAdd(userPR);
        this.sender.getLifeCycleLock().writeLock().unlock();
    }
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionAttributes(org.apache.geode.cache.RegionAttributes) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 12 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments 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 13 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.

the class ParallelGatewaySenderQueue method addShadowPartitionedRegionForUserRR.

public void addShadowPartitionedRegionForUserRR(DistributedRegion userRegion) {
    this.sender.getLifeCycleLock().writeLock().lock();
    PartitionedRegion prQ = null;
    if (logger.isDebugEnabled()) {
        logger.debug("addShadowPartitionedRegionForUserRR: Going to create shadowpr for userRegion {}", userRegion.getFullPath());
    }
    try {
        String regionName = userRegion.getFullPath();
        if (this.userRegionNameToshadowPRMap.containsKey(regionName))
            return;
        InternalCache cache = sender.getCache();
        final String prQName = getQueueName(sender.getId(), userRegion.getFullPath());
        prQ = (PartitionedRegion) cache.getRegion(prQName);
        if (prQ == null) {
            // TODO:REF:Avoid deprecated apis
            AttributesFactory fact = new AttributesFactory();
            // Fix for 48621 - don't enable concurrency checks
            // for queue buckets., event with persistence
            fact.setConcurrencyChecksEnabled(false);
            PartitionAttributesFactory pfact = new PartitionAttributesFactory();
            pfact.setTotalNumBuckets(sender.getMaxParallelismForReplicatedRegion());
            int localMaxMemory = userRegion.getDataPolicy().withStorage() ? sender.getMaximumQueueMemory() : 0;
            pfact.setLocalMaxMemory(localMaxMemory);
            // TODO:Kishor : THis need to be handled nicely
            pfact.setRedundantCopies(3);
            pfact.setPartitionResolver(new RREventIDResolver());
            if (sender.isPersistenceEnabled()) {
                fact.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            }
            fact.setDiskStoreName(sender.getDiskStoreName());
            // optimize with above check of enable persistence
            if (sender.isPersistenceEnabled())
                fact.setDiskSynchronous(sender.isDiskSynchronous());
            else {
                fact.setDiskSynchronous(false);
            }
            // allow for no overflow directory
            EvictionAttributes ea = EvictionAttributes.createLIFOMemoryAttributes(sender.getMaximumQueueMemory(), EvictionAction.OVERFLOW_TO_DISK);
            fact.setEvictionAttributes(ea);
            fact.setPartitionAttributes(pfact.create());
            final RegionAttributes ra = fact.create();
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Attempting to create queue region: {}", this, prQName);
            }
            ParallelGatewaySenderQueueMetaRegion meta = new ParallelGatewaySenderQueueMetaRegion(prQName, ra, null, cache, sender);
            try {
                prQ = (PartitionedRegion) cache.createVMRegion(prQName, ra, new InternalRegionArguments().setInternalMetaRegion(meta).setDestroyLockFlag(true).setSnapshotInputStream(null).setImageTarget(null));
                if (logger.isDebugEnabled()) {
                    logger.debug("Region created  : {} partition Attributes : {}", prQ, prQ.getPartitionAttributes());
                }
                // TODO This should not be set on the PR but on the GatewaySender
                prQ.enableConflation(sender.isBatchConflationEnabled());
                // This is required in case of persistent PR and sender.
                if (prQ.getLocalMaxMemory() != 0) {
                    Iterator<Integer> itr = prQ.getRegionAdvisor().getBucketSet().iterator();
                    while (itr.hasNext()) {
                        itr.next();
                    }
                }
            // In case of Replicated Region it may not be necessary.
            } catch (IOException veryUnLikely) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), veryUnLikely);
            } catch (ClassNotFoundException alsoUnlikely) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.SingleWriteSingleReadRegionQueue_UNEXPECTED_EXCEPTION_DURING_INIT_OF_0, this.getClass()), alsoUnlikely);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Created queue region: {}", this, prQ);
            }
        } else {
            // started from stop operation)
            if (// HItesh: for first processor only
            this.index == 0)
                handleShadowPRExistsScenario(cache, prQ);
        }
        /*
       * Here, enqueueTempEvents need to be invoked when a sender is already running and userPR is
       * created later. When the flow comes here through start() method of sender i.e. userPR
       * already exists and sender is started later, the enqueueTempEvents is done in the start()
       * method of ParallelGatewaySender
       */
        if ((this.index == this.nDispatcher - 1) && this.sender.isRunning()) {
            ((AbstractGatewaySender) sender).enqueueTempEvents();
        }
    } finally {
        if (prQ != null) {
            this.userRegionNameToshadowPRMap.put(userRegion.getFullPath(), prQ);
        }
        this.sender.getLifeCycleLock().writeLock().unlock();
    }
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionAttributes(org.apache.geode.cache.RegionAttributes) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 14 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.

the class RegionNameValidationJUnitTest method testInternalRegionNames.

@Test
public void testInternalRegionNames() {
    InternalRegionArguments ira = new InternalRegionArguments();
    ira.setInternalRegion(true);
    LocalRegion.validateRegionName("__ValidInternalRegionName", ira);
}
Also used : InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 15 with InternalRegionArguments

use of org.apache.geode.internal.cache.InternalRegionArguments in project geode by apache.

the class ExportLogsFunction method createOrGetExistingExportLogsRegion.

public static Region createOrGetExistingExportLogsRegion(boolean isInitiatingMember, InternalCache cache) throws IOException, ClassNotFoundException {
    Region exportLogsRegion = cache.getRegion(EXPORT_LOGS_REGION);
    if (exportLogsRegion == null) {
        AttributesFactory<String, Configuration> regionAttrsFactory = new AttributesFactory<>();
        regionAttrsFactory.setDataPolicy(DataPolicy.EMPTY);
        regionAttrsFactory.setScope(Scope.DISTRIBUTED_ACK);
        if (isInitiatingMember) {
            regionAttrsFactory.setCacheWriter(new ExportLogsCacheWriter());
        }
        InternalRegionArguments internalArgs = new InternalRegionArguments();
        internalArgs.setIsUsedForMetaRegion(true);
        exportLogsRegion = cache.createVMRegion(EXPORT_LOGS_REGION, regionAttrsFactory.create(), internalArgs);
    }
    return exportLogsRegion;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) Configuration(org.apache.geode.management.internal.configuration.domain.Configuration) ExportLogsCacheWriter(org.apache.geode.management.internal.cli.util.ExportLogsCacheWriter) Region(org.apache.geode.cache.Region) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments)

Aggregations

InternalRegionArguments (org.apache.geode.internal.cache.InternalRegionArguments)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)16 IOException (java.io.IOException)13 RegionAttributes (org.apache.geode.cache.RegionAttributes)7 InternalCache (org.apache.geode.internal.cache.InternalCache)6 TimeoutException (org.apache.geode.cache.TimeoutException)4 Test (org.junit.Test)4 InternalGemFireError (org.apache.geode.InternalGemFireError)3 CacheException (org.apache.geode.cache.CacheException)3 EvictionAttributes (org.apache.geode.cache.EvictionAttributes)3 Region (org.apache.geode.cache.Region)3 RegionExistsException (org.apache.geode.cache.RegionExistsException)3 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)3 File (java.io.File)2 CancelException (org.apache.geode.CancelException)2 Cache (org.apache.geode.cache.Cache)2 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)2 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)2 CachePerfStats (org.apache.geode.internal.cache.CachePerfStats)2 HasCachePerfStats (org.apache.geode.internal.cache.HasCachePerfStats)2