Search in sources :

Example 1 with AbstractIndex

use of org.apache.geode.cache.query.internal.index.AbstractIndex in project geode by apache.

the class CompiledSelect method releaseReadLockOnUsedIndex.

/**
   * The index is locked during query to prevent it from being removed by another thread. So we have
   * to release the lock only after whole query is finished as one query can use an index multiple
   * times.
   */
private void releaseReadLockOnUsedIndex(PlanInfo planInfo) {
    List inds = planInfo.indexes;
    for (Object obj : inds) {
        Index index = (Index) obj;
        Index prIndex = ((AbstractIndex) index).getPRIndex();
        if (prIndex != null) {
            ((PartitionedIndex) prIndex).releaseIndexReadLockForRemove();
        } else {
            ((AbstractIndex) index).releaseIndexReadLockForRemove();
        }
    }
}
Also used : PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) ArrayList(java.util.ArrayList) List(java.util.List) Index(org.apache.geode.cache.query.Index) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex)

Example 2 with AbstractIndex

use of org.apache.geode.cache.query.internal.index.AbstractIndex in project geode by apache.

the class QueryUtils method getRelationshipIndexIfAny.

/**
   * Returns the pair of RangeIndexes available for a composite condition ( equi join across the
   * region). It will either return two indexes or will return null. *
   * 
   * @param lhs One of the operands of the equi-join condition
   * @param rhs The other operand of the equi-join condition
   * @param context ExecutionContext object
   * @param operator The operator which necesarily has to be an equality ( ' = ' )
   * @return An array of IndexData object with 0th IndexData for the lhs operand & 1th object for
   *         rhs operad
   */
static IndexData[] getRelationshipIndexIfAny(CompiledValue lhs, CompiledValue rhs, ExecutionContext context, int operator) throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
    if (operator != OQLLexerTokenTypes.TOK_EQ) {
        // Operator must be '='
        return null;
    }
    // Do not use PrimaryKey Index
    IndexData lhsIndxData = QueryUtils.getAvailableIndexIfAny(lhs, context, false);
    if (lhsIndxData == null) {
        return null;
    }
    // Do not use PrimaryKey Index
    IndexData rhsIndxData = QueryUtils.getAvailableIndexIfAny(rhs, context, false);
    if (rhsIndxData == null) {
        // release the lock held on lhsIndex as it will not be used
        Index index = lhsIndxData.getIndex();
        Index prIndex = ((AbstractIndex) index).getPRIndex();
        if (prIndex != null) {
            ((PartitionedIndex) prIndex).releaseIndexReadLockForRemove();
        } else {
            ((AbstractIndex) index).releaseIndexReadLockForRemove();
        }
        return null;
    }
    IndexProtocol lhsIndx = lhsIndxData.getIndex();
    IndexProtocol rhsIndx = rhsIndxData.getIndex();
    if (lhsIndx.isValid() && rhsIndx.isValid()) {
        return new IndexData[] { lhsIndxData, rhsIndxData };
    }
    return null;
}
Also used : IndexProtocol(org.apache.geode.cache.query.internal.index.IndexProtocol) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) IndexData(org.apache.geode.cache.query.internal.index.IndexData) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) Index(org.apache.geode.cache.query.Index) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex)

Example 3 with AbstractIndex

use of org.apache.geode.cache.query.internal.index.AbstractIndex 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)

Example 4 with AbstractIndex

use of org.apache.geode.cache.query.internal.index.AbstractIndex in project geode by apache.

the class DerivedInfo method evaluateDerivedJoin.

/*
   * Called by createDerivedJoinResultsFromCCa Creates the new cc, executes the cc and releases any
   * newly obtain index locks
   */
private void evaluateDerivedJoin(ExecutionContext context, CompiledValue newLeftSide, CompiledValue newRightSide, int operator) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
    CompiledComparison dcc = createDerivedJoin(context, newLeftSide, newRightSide, operator);
    IndexInfo[] indexInfos = (IndexInfo[]) dcc.getIndexInfo(context);
    try {
        if (indexInfos != null && isValidIndexTypeToDerive(indexInfos[0]._getIndex())) {
            populateDerivedResultsFromDerivedJoin(context, dcc, indexInfos[0]);
        }
    } finally {
        if (indexInfos != null) {
            Index index = (Index) indexInfos[0]._index;
            Index prIndex = ((AbstractIndex) index).getPRIndex();
            if (prIndex != null) {
                ((PartitionedIndex) prIndex).releaseIndexReadLockForRemove();
            } else {
                ((AbstractIndex) index).releaseIndexReadLockForRemove();
            }
        }
    }
}
Also used : PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) Index(org.apache.geode.cache.query.Index) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex)

Example 5 with AbstractIndex

use of org.apache.geode.cache.query.internal.index.AbstractIndex in project geode by apache.

the class PartitionedRegion method createIndexes.

public List<Index> createIndexes(boolean remotelyOriginated, HashSet<IndexCreationData> indexDefinitions) throws MultiIndexCreationException, CacheException, ForceReattemptException, IndexCreationException {
    if (remotelyOriginated && dataStore == null) {
        // data store where as it should have.
        if (getLocalMaxMemory() != 0) {
            throw new IndexCreationException(LocalizedStrings.PartitionedRegion_DATA_STORE_ON_THIS_VM_IS_NULL_AND_THE_LOCAL_MAX_MEMORY_IS_NOT_ZERO_THE_DATA_POLICY_IS_0_AND_THE_LOCALMAXMEMEORY_IS_1.toLocalizedString(getDataPolicy(), (long) getLocalMaxMemory()));
        }
        // Not have to do anything since the region is just an Accessor and
        // does not store any data.
        logger.info(LocalizedStrings.PartitionedRegion_THIS_IS_AN_ACCESSOR_VM_AND_DOESNT_CONTAIN_DATA);
        return new ArrayList<Index>();
    }
    Set<Index> indexes = new HashSet<Index>();
    boolean throwException = false;
    HashMap<String, Exception> exceptionsMap = new HashMap<String, Exception>();
    // First step is creating all the defined indexes.
    // Do not send the IndexCreationMsg to remote nodes now.
    throwException |= createEmptyIndexes(indexDefinitions, remotelyOriginated, indexes, exceptionsMap);
    // If same indexes are created locally and also being created by a remote index creation msg
    // populate such indexes only once.
    Set<Index> unpopulatedIndexes = null;
    if (indexes.size() > 0) {
        unpopulatedIndexes = getUnpopulatedIndexes(indexes);
    }
    // Second step is iterating over REs and populating all the created indexes
    if (unpopulatedIndexes != null && unpopulatedIndexes.size() > 0) {
        throwException |= populateEmptyIndexes(unpopulatedIndexes, exceptionsMap);
    }
    // Third step is to send the message to remote nodes
    // Locally originated create index request.
    // Send create request to other PR nodes.
    throwException |= sendCreateIndexesMessage(remotelyOriginated, indexDefinitions, indexes, exceptionsMap);
    // If exception is throw in any of the above steps
    if (throwException) {
        throw new MultiIndexCreationException(exceptionsMap);
    }
    // set the populate flag for all the created PR indexes
    for (Index ind : indexes) {
        ((AbstractIndex) ind).setPopulated(true);
    }
    return new ArrayList<Index>(indexes);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) AbstractIndex(org.apache.geode.cache.query.internal.index.AbstractIndex) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) TimeoutException(org.apache.geode.cache.TimeoutException) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) GatewaySenderConfigurationException(org.apache.geode.internal.cache.wan.GatewaySenderConfigurationException) ExecutionException(java.util.concurrent.ExecutionException) ReplyException(org.apache.geode.distributed.internal.ReplyException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) PartitionNotAvailableException(org.apache.geode.cache.partition.PartitionNotAvailableException) LowMemoryException(org.apache.geode.cache.LowMemoryException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) PRLocallyDestroyedException(org.apache.geode.internal.cache.partitioned.PRLocallyDestroyedException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) TransactionException(org.apache.geode.cache.TransactionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) EmptyRegionFunctionException(org.apache.geode.cache.execute.EmptyRegionFunctionException) HashSet(java.util.HashSet)

Aggregations

AbstractIndex (org.apache.geode.cache.query.internal.index.AbstractIndex)6 ArrayList (java.util.ArrayList)3 Index (org.apache.geode.cache.query.Index)3 PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)3 IOException (java.io.IOException)2 List (java.util.List)2 CacheException (org.apache.geode.cache.CacheException)2 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)2 IndexExistsException (org.apache.geode.cache.query.IndexExistsException)2 IndexNameConflictException (org.apache.geode.cache.query.IndexNameConflictException)2 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)2 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)2 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)2 IndexProtocol (org.apache.geode.cache.query.internal.index.IndexProtocol)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 NoSuchElementException (java.util.NoSuchElementException)1 CancellationException (java.util.concurrent.CancellationException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1