Search in sources :

Example 11 with PartitionedRegion

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);
        }
    }
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 12 with PartitionedRegion

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.
            }
        }
    }
}
Also used : ExecutionContext(org.apache.geode.cache.query.internal.ExecutionContext) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore)

Example 13 with PartitionedRegion

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;
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 14 with PartitionedRegion

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);
        }
    }
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) Bucket(org.apache.geode.internal.cache.partitioned.Bucket) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RuntimeIterator(org.apache.geode.cache.query.internal.RuntimeIterator) CloseableIterator(org.apache.geode.internal.cache.persistence.query.CloseableIterator) Iterator(java.util.Iterator)

Example 15 with PartitionedRegion

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;
}
Also used : IndexProtocol(org.apache.geode.cache.query.internal.index.IndexProtocol) BucketRegion(org.apache.geode.internal.cache.BucketRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ArrayList(java.util.ArrayList) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) ArrayList(java.util.ArrayList) List(java.util.List)

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