use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class AbstractIndex method query.
@Override
public void query(Object key, int operator, Collection results, @Retained CompiledValue iterOp, RuntimeIterator indpndntItr, ExecutionContext context, List projAttrib, SelectResults intermediateResults, boolean isIntersection) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
// get a read lock when doing a lookup
if (context.getBucketList() != null && this.region instanceof BucketRegion) {
PartitionedRegion pr = ((Bucket) region).getPartitionedRegion();
long start = updateIndexUseStats();
try {
for (Object bucketId : context.getBucketList()) {
AbstractIndex bucketIndex = PartitionedIndex.getBucketIndex(pr, this.indexName, (Integer) bucketId);
if (bucketIndex == null) {
continue;
}
bucketIndex.lockedQuery(key, operator, results, iterOp, indpndntItr, context, projAttrib, intermediateResults, isIntersection);
}
} finally {
updateIndexUseEndStats(start);
}
} else {
long start = updateIndexUseStats();
try {
lockedQuery(key, operator, results, iterOp, indpndntItr, context, projAttrib, intermediateResults, isIntersection);
} finally {
updateIndexUseEndStats(start);
}
}
}
use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class PartitionedIndex method verifyAndCreateMissingIndex.
/**
* Verify if the index is available of the buckets. If not create index on the bucket.
*/
public void verifyAndCreateMissingIndex(List buckets) throws QueryInvocationTargetException {
PartitionedRegion pr = (PartitionedRegion) this.getRegion();
PartitionedRegionDataStore prds = pr.getDataStore();
for (Object bId : buckets) {
// create index
BucketRegion bukRegion = (BucketRegion) prds.getLocalBucketById((Integer) bId);
if (bukRegion == null) {
throw new QueryInvocationTargetException("Bucket not found for the id :" + bId);
}
IndexManager im = IndexUtils.getIndexManager(bukRegion, true);
if (im != null && im.getIndex(indexName) == null) {
try {
if (pr.getCache().getLogger().fineEnabled()) {
pr.getCache().getLogger().fine("Verifying index presence on bucket region. " + " Found index " + this.indexName + " not present on the bucket region " + bukRegion.getFullPath() + ", index will be created on this region.");
}
ExecutionContext externalContext = new ExecutionContext(null, bukRegion.getCache());
externalContext.setBucketRegion(pr, bukRegion);
im.createIndex(this.indexName, this.type, this.originalIndexedExpression, this.fromClause, this.imports, externalContext, this, true);
} catch (IndexExistsException iee) {
// Index exists.
} catch (IndexNameConflictException ince) {
// ignore.
}
}
}
}
use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class IndexUtils method getIndexManager.
public static IndexManager getIndexManager(Region region, boolean createIfNotAvailable) {
if (region == null || region.isDestroyed()) {
return null;
}
LocalRegion lRegion = (LocalRegion) region;
IndexManager idxMgr = lRegion.getIndexManager();
if (idxMgr == null && createIfNotAvailable) {
// JUst before creating new IndexManager.
if (testHook != null && region instanceof PartitionedRegion) {
testHook.hook(0);
}
Object imSync = lRegion.getIMSync();
synchronized (imSync) {
// Double checked locking
if (lRegion.getIndexManager() == null) {
idxMgr = new IndexManager(region);
lRegion.setIndexManager(idxMgr);
} else {
idxMgr = lRegion.getIndexManager();
}
}
}
return idxMgr;
}
use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class AbstractIndex method query.
@Override
public void query(Collection results, Set keysToRemove, ExecutionContext context) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
Iterator iterator = keysToRemove.iterator();
Object temp = iterator.next();
iterator.remove();
if (context.getBucketList() != null && this.region instanceof BucketRegion) {
long start = updateIndexUseStats();
try {
PartitionedRegion partitionedRegion = ((Bucket) this.region).getPartitionedRegion();
for (Object bucketId : context.getBucketList()) {
AbstractIndex bucketIndex = PartitionedIndex.getBucketIndex(partitionedRegion, this.indexName, (Integer) bucketId);
if (bucketIndex == null) {
continue;
}
bucketIndex.lockedQuery(temp, OQLLexerTokenTypes.TOK_NE, results, iterator.hasNext() ? keysToRemove : null, context);
}
} finally {
updateIndexUseEndStats(start);
}
} else {
long start = updateIndexUseStats();
try {
lockedQuery(temp, OQLLexerTokenTypes.TOK_NE, results, iterator.hasNext() ? keysToRemove : null, context);
} finally {
updateIndexUseEndStats(start);
}
}
}
use of org.apache.geode.internal.cache.PartitionedRegion in project geode by apache.
the class QueryUtils method queryEquijoinConditionBucketIndexes.
static List queryEquijoinConditionBucketIndexes(IndexInfo[] indxInfo, ExecutionContext context) throws QueryInvocationTargetException, TypeMismatchException, FunctionDomainException, NameResolutionException {
List resultData = new ArrayList();
AbstractIndex index0 = (AbstractIndex) indxInfo[0]._index;
AbstractIndex index1 = (AbstractIndex) indxInfo[1]._index;
PartitionedRegion pr0 = null;
if (index0.getRegion() instanceof BucketRegion) {
pr0 = ((Bucket) index0.getRegion()).getPartitionedRegion();
}
PartitionedRegion pr1 = null;
if (index1.getRegion() instanceof BucketRegion) {
pr1 = ((Bucket) index1.getRegion()).getPartitionedRegion();
}
List data = null;
IndexProtocol i0 = null;
IndexProtocol i1 = null;
for (Object b : context.getBucketList()) {
i0 = pr0 != null ? PartitionedIndex.getBucketIndex(pr0, index0.getName(), (Integer) b) : indxInfo[0]._index;
i1 = pr1 != null ? PartitionedIndex.getBucketIndex(pr1, index1.getName(), (Integer) b) : indxInfo[1]._index;
if (i0 == null || i1 == null) {
continue;
}
data = i0.queryEquijoinCondition(i1, context);
resultData.addAll(data);
}
data = resultData;
return data;
}
Aggregations