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