Search in sources :

Example 1 with PartitionedRegion

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

the class GemFireMemberStatus method initializeRegionSizes.

protected void initializeRegionSizes() {
    Iterator rootRegions = cache.rootRegions().iterator();
    while (rootRegions.hasNext()) {
        LocalRegion rootRegion = (LocalRegion) rootRegions.next();
        if (!(rootRegion instanceof HARegion)) {
            RegionStatus rootRegionStatus = rootRegion instanceof PartitionedRegion ? new PartitionedRegionStatus((PartitionedRegion) rootRegion) : new RegionStatus(rootRegion);
            putRegionStatus(rootRegion.getFullPath(), rootRegionStatus);
            Iterator subRegions = rootRegion.subregions(true).iterator();
            while (subRegions.hasNext()) {
                LocalRegion subRegion = (LocalRegion) subRegions.next();
                RegionStatus subRegionStatus = subRegion instanceof PartitionedRegion ? new PartitionedRegionStatus((PartitionedRegion) subRegion) : new RegionStatus(subRegion);
                putRegionStatus(subRegion.getFullPath(), subRegionStatus);
            }
        }
    }
}
Also used : PartitionedRegionStatus(org.apache.geode.internal.cache.PartitionedRegionStatus) RegionStatus(org.apache.geode.internal.cache.RegionStatus) PartitionedRegionStatus(org.apache.geode.internal.cache.PartitionedRegionStatus) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) HARegion(org.apache.geode.internal.cache.HARegion)

Example 2 with PartitionedRegion

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

the class CompiledRegion method evaluate.

public Object evaluate(ExecutionContext context) throws RegionNotFoundException {
    Region rgn;
    Cache cache = context.getCache();
    // do PR bucketRegion substitution here for expressions that evaluate to a Region.
    PartitionedRegion pr = context.getPartitionedRegion();
    if (pr != null && pr.getFullPath().equals(this.regionPath)) {
        rgn = context.getBucketRegion();
    } else if (pr != null) {
        // Asif : This is a very tricky solution to allow equijoin queries on PartitionedRegion
        // locally
        // We have possibly got a situation of equijoin. it may be across PRs. so use the context's
        // bucket region
        // to get ID and then retrieve the this region's bucket region
        BucketRegion br = context.getBucketRegion();
        int bucketID = br.getId();
        // Is current region a partitioned region
        rgn = cache.getRegion(this.regionPath);
        if (rgn.getAttributes().getDataPolicy().withPartitioning()) {
            // convert it into bucket region.
            PartitionedRegion prLocal = (PartitionedRegion) rgn;
            rgn = prLocal.getDataStore().getLocalBucketById(bucketID);
        }
    } else {
        rgn = cache.getRegion(this.regionPath);
    }
    if (rgn == null) {
        // a CacheClosedException
        if (cache.isClosed()) {
            throw new CacheClosedException();
        }
        throw new RegionNotFoundException(LocalizedStrings.CompiledRegion_REGION_NOT_FOUND_0.toLocalizedString(this.regionPath));
    }
    if (context.isCqQueryContext()) {
        return new QRegion(rgn, true, context);
    } else {
        return new QRegion(rgn, false, context);
    }
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion)

Example 3 with PartitionedRegion

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

the class CompiledPath method evaluate.

public Object evaluate(ExecutionContext context) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    CompiledValue rcvr = getReceiver();
    Object evalRcvr = rcvr.evaluate(context);
    if (context.isCqQueryContext() && (evalRcvr instanceof Region.Entry || evalRcvr instanceof CqEntry)) {
        try {
            if (evalRcvr instanceof Region.Entry) {
                Region.Entry re = (Region.Entry) evalRcvr;
                if (re.isDestroyed()) {
                    return QueryService.UNDEFINED;
                }
                evalRcvr = re.getValue();
            } else if (evalRcvr instanceof CqEntry) {
                CqEntry re = (CqEntry) evalRcvr;
                evalRcvr = re.getValue();
            }
        } catch (EntryDestroyedException ede) {
            // throw EntryDestroyedException if the value becomes null.
            return QueryService.UNDEFINED;
        }
    }
    // if the receiver is an iterator, then use the contrained type
    // for attribute evaluation instead of the runtime type
    // RuntimeIterator cmpItr = null;
    // if (rcvr.getType() == ID)
    // {
    // CompiledValue resolvedRcvr = context.resolve(((CompiledID)rcvr).getId());
    // if (resolvedRcvr != null && resolvedRcvr.getType() == ITERATOR)
    // cmpItr = ((RuntimeIterator)resolvedRcvr);
    // }
    // if (rcvr.getType() == ITERATOR)
    // cmpItr = (RuntimeIterator)rcvr;
    // if (cmpItr != null)
    // {
    // Class constraint = cmpItr.getBaseCollection().getConstraint();
    // return PathUtils.evaluateAttribute(evalRcvr,
    // constraint,
    // getTailID());
    // }
    Object obj = PathUtils.evaluateAttribute(evalRcvr, getTailID());
    // check for BucketRegion substitution
    PartitionedRegion pr = context.getPartitionedRegion();
    if (pr != null && (obj instanceof Region)) {
        if (pr.getFullPath().equals(((Region) obj).getFullPath())) {
            obj = context.getBucketRegion();
        }
    }
    return obj;
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 4 with PartitionedRegion

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

the class PartitionRegionHelper method getColocatedRegions.

/**
   * Given a partitioned Region, return a map of
   * {@linkplain PartitionAttributesFactory#setColocatedWith(String) colocated Regions}. Given a
   * local data reference to a partitioned region, return a map of local
   * {@linkplain PartitionAttributesFactory#setColocatedWith(String) colocated Regions}. If there
   * are no colocated regions, return an empty map.
   * 
   * @param r a partitioned Region
   * @throws IllegalStateException if the Region is not a {@linkplain DataPolicy#PARTITION
   *         partitioned Region}
   * @return an unmodifiable map of {@linkplain Region#getFullPath() region name} to {@link Region}
   * @since GemFire 6.0
   */
public static Map<String, Region<?, ?>> getColocatedRegions(final Region<?, ?> r) {
    Map ret;
    if (isPartitionedRegion(r)) {
        final PartitionedRegion pr = (PartitionedRegion) r;
        ret = ColocationHelper.getAllColocationRegions(pr);
        if (ret.isEmpty()) {
            ret = Collections.emptyMap();
        }
    } else if (r instanceof LocalDataSet) {
        LocalDataSet lds = (LocalDataSet) r;
        InternalRegionFunctionContext fc = lds.getFunctionContext();
        if (fc != null) {
            ret = ColocationHelper.getAllColocatedLocalDataSets(lds.getProxy(), fc);
            if (ret.isEmpty()) {
                ret = Collections.emptyMap();
            }
        } else {
            ret = ColocationHelper.getColocatedLocalDataSetsForBuckets(lds.getProxy(), lds.getBucketSet());
        }
    } else {
        throw new IllegalArgumentException(LocalizedStrings.PartitionManager_REGION_0_IS_NOT_A_PARTITIONED_REGION.toLocalizedString(r.getFullPath()));
    }
    return Collections.unmodifiableMap(ret);
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalRegionFunctionContext(org.apache.geode.internal.cache.execute.InternalRegionFunctionContext) Map(java.util.Map)

Example 5 with PartitionedRegion

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

the class PartitionRegionHelper method assignBucketsToPartitions.

/**
   * Decide which partitions will host which buckets. Gemfire normally assigns buckets to partitions
   * as needed when data is added to a partitioned region. This method provides way to assign all of
   * the buckets without putting any data in partition region. This method should not be called
   * until all of the partitions are running because it will divide the buckets between the running
   * partitions. If the buckets are already assigned this method will have no effect.
   * 
   * This method will block until all buckets are assigned.
   * 
   * @param region The region which should have it's buckets assigned.
   * @throws IllegalStateException if the provided region is something other than a
   *         {@linkplain DataPolicy#PARTITION partitioned Region}
   * @since GemFire 6.0
   */
public static void assignBucketsToPartitions(Region<?, ?> region) {
    PartitionedRegion pr = isPartitionedCheck(region);
    RecoveryLock lock = null;
    try {
        lock = pr.getRecoveryLock();
        lock.lock();
        for (int i = 0; i < getNumberOfBuckets(pr); i++) {
            // This method will return quickly if the bucket already exists
            pr.createBucket(i, 0, null);
        }
    } finally {
        if (lock != null) {
            lock.unlock();
        }
    }
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RecoveryLock(org.apache.geode.internal.cache.PartitionedRegion.RecoveryLock)

Aggregations

PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)367 Test (org.junit.Test)135 Region (org.apache.geode.cache.Region)115 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)112 HashSet (java.util.HashSet)105 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)104 AttributesFactory (org.apache.geode.cache.AttributesFactory)86 VM (org.apache.geode.test.dunit.VM)86 Host (org.apache.geode.test.dunit.Host)85 ArrayList (java.util.ArrayList)77 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)75 Set (java.util.Set)69 IOException (java.io.IOException)66 Function (org.apache.geode.cache.execute.Function)66 FunctionException (org.apache.geode.cache.execute.FunctionException)63 List (java.util.List)62 RegionAttributes (org.apache.geode.cache.RegionAttributes)61 Iterator (java.util.Iterator)60 IgnoredException (org.apache.geode.test.dunit.IgnoredException)59 Cache (org.apache.geode.cache.Cache)56