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);
}
}
}
}
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);
}
}
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;
}
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);
}
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();
}
}
}
Aggregations