Search in sources :

Example 6 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