Search in sources :

Example 1 with MultiIndexCreationException

use of org.apache.geode.cache.query.MultiIndexCreationException in project geode by apache.

the class IndexCreationMsg method operateOnPartitionedRegion.

/**
   * This method actually operates on the partitioned region and creates given list of indexes from
   * a index creation message.
   * 
   * @param dm distribution manager.
   * @param pr partitioned region on which to create an index.
   * @throws CacheException indicating a cache level error
   * @throws ForceReattemptException if the peer is no longer available
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion pr, long startTime) throws CacheException, ForceReattemptException {
    // region exists
    ReplyException replyEx = null;
    boolean result = false;
    List<Index> indexes = null;
    List<String> failedIndexNames = new ArrayList<String>();
    if (logger.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        for (IndexCreationData icd : indexDefinitions) {
            sb.append(icd.getIndexName()).append(" ");
        }
        logger.debug("Processing index creation message on this remote partitioned region vm for indexes: {}", sb);
    }
    try {
        indexes = pr.createIndexes(true, indexDefinitions);
    } catch (IndexCreationException e1) {
        replyEx = new ReplyException(LocalizedStrings.IndexCreationMsg_REMOTE_INDEX_CREAION_FAILED.toLocalizedString(), e1);
    } catch (MultiIndexCreationException exx) {
        failedIndexNames.addAll(exx.getExceptionsMap().keySet());
        if (logger.isDebugEnabled()) {
            StringBuffer exceptionMsgs = new StringBuffer();
            for (Exception ex : exx.getExceptionsMap().values()) {
                exceptionMsgs.append(ex.getMessage()).append("\n");
            }
            logger.debug("Got an MultiIndexCreationException with \n: {}", exceptionMsgs);
            logger.debug("{} indexes were created succesfully", failedIndexNames.size());
        }
        replyEx = new ReplyException(LocalizedStrings.IndexCreationMsg_REMOTE_INDEX_CREAION_FAILED.toLocalizedString(), exx);
    }
    if (null == replyEx) {
        result = true;
    }
    if (result) {
        Map<String, Integer> indexBucketsMap = new HashMap<String, Integer>();
        for (Index index : indexes) {
            PartitionedIndex prIndex = (PartitionedIndex) index;
            indexBucketsMap.put(prIndex.getName(), prIndex.getNumberOfIndexedBuckets());
        }
        sendReply(getSender(), getProcessorId(), dm, replyEx, result, indexBucketsMap, pr.getDataStore().getAllLocalBuckets().size());
    } else {
        // add the indexes that were successfully created to the map
        Map<String, Integer> indexBucketsMap = new HashMap<String, Integer>();
        for (IndexCreationData icd : indexDefinitions) {
            // if the index was successfully created
            if (!failedIndexNames.contains(icd.getIndexName())) {
                PartitionedIndex prIndex = (PartitionedIndex) pr.getIndex(icd.getIndexName());
                indexBucketsMap.put(icd.getIndexName(), prIndex.getNumberOfIndexedBuckets());
            }
        }
        sendReply(getSender(), getProcessorId(), dm, replyEx, result, indexBucketsMap, pr.getDataStore().getAllLocalBuckets().size());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Multi Index creation completed on remote host and has sent the reply to the originating vm.");
    }
    return false;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) ReplyException(org.apache.geode.distributed.internal.ReplyException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) PartitionedRegionException(org.apache.geode.internal.cache.PartitionedRegionException) IndexCreationData(org.apache.geode.cache.query.internal.index.IndexCreationData) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) IndexCreationException(org.apache.geode.cache.query.IndexCreationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException)

Example 2 with MultiIndexCreationException

use of org.apache.geode.cache.query.MultiIndexCreationException in project geode by apache.

the class PRQueryDUnitHelper method getCacheSerializableRunnableForDefineIndex.

public CacheSerializableRunnable getCacheSerializableRunnableForDefineIndex(final String prRegionName, final ArrayList<String> indexName, final ArrayList<String> indexedExpression, final ArrayList<String> fromClause) {
    SerializableRunnable prIndexCreator = new CacheSerializableRunnable("PartitionedIndexCreator") {

        @Override
        public void run2() {
            List<Index> indexes = null;
            try {
                Cache cache = getCache();
                QueryService qs = cache.getQueryService();
                Region region = cache.getRegion(prRegionName);
                for (int i = 0; i < indexName.size(); i++) {
                    qs.defineIndex(indexName.get(i), indexedExpression.get(i), fromClause == null ? region.getFullPath() : fromClause.get(i));
                }
                indexes = qs.createDefinedIndexes();
            } catch (Exception ex) {
                if (ex instanceof MultiIndexCreationException) {
                    StringBuffer sb = new StringBuffer();
                    for (Exception e : ((MultiIndexCreationException) ex).getExceptionsMap().values()) {
                        sb.append(e.getMessage()).append("\n");
                    }
                    fail("Multi index creation failed, " + sb);
                } else {
                    Assert.fail("Creating Index in this vm failed : ", ex);
                }
            }
            assertNotNull("Indexes should have been created.", indexes);
        }
    };
    return (CacheSerializableRunnable) prIndexCreator;
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryExistsException(org.apache.geode.cache.EntryExistsException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CancelException(org.apache.geode.CancelException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) TestException(util.TestException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) QueryException(org.apache.geode.cache.query.QueryException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) Cache(org.apache.geode.cache.Cache)

Example 3 with MultiIndexCreationException

use of org.apache.geode.cache.query.MultiIndexCreationException in project geode by apache.

the class IndexManager method populateIndexes.

/**
   * populates all the indexes in the region
   */
public void populateIndexes(Collection<Index> indexSet) throws MultiIndexCreationException {
    waitBeforeUpdate();
    if (region.getCache().getLogger().infoEnabled()) {
        region.getCache().getLogger().info("Populating indexes for region " + region.getName());
    }
    boolean throwException = false;
    HashMap<String, Exception> exceptionsMap = new HashMap<String, Exception>();
    boolean oldReadSerialized = DefaultQuery.getPdxReadSerialized();
    DefaultQuery.setPdxReadSerialized(true);
    try {
        Iterator entryIter = ((LocalRegion) region).getBestIterator(true);
        while (entryIter.hasNext()) {
            RegionEntry entry = (RegionEntry) entryIter.next();
            if (entry == null || entry.isInvalidOrRemoved()) {
                continue;
            }
            // Fault in the value once before index update so that every index
            // update does not have
            // to read the value from disk every time.
            entry.getValue((LocalRegion) this.region);
            Iterator<Index> indexSetIterator = indexSet.iterator();
            while (indexSetIterator.hasNext()) {
                AbstractIndex index = (AbstractIndex) indexSetIterator.next();
                if (!index.isPopulated() && index.getType() != IndexType.PRIMARY_KEY) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding to index :{}{} value :{}", index.getName(), this.region.getFullPath(), entry.getKey());
                    }
                    long start = ((AbstractIndex) index).updateIndexUpdateStats();
                    try {
                        index.addIndexMapping(entry);
                    } catch (IMQException e) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Adding to index failed for: {}, {}", index.getName(), e.getMessage(), e);
                        }
                        exceptionsMap.put(index.indexName, e);
                        indexSetIterator.remove();
                        throwException = true;
                    }
                    ((AbstractIndex) index).updateIndexUpdateStats(start);
                }
            }
        }
        setPopulateFlagForIndexes(indexSet);
        if (throwException) {
            throw new MultiIndexCreationException(exceptionsMap);
        }
    } finally {
        DefaultQuery.setPdxReadSerialized(oldReadSerialized);
        notifyAfterUpdate();
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Index(org.apache.geode.cache.query.Index) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AmbiguousNameException(org.apache.geode.cache.query.AmbiguousNameException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) ExecutionException(java.util.concurrent.ExecutionException) QueryException(org.apache.geode.cache.query.QueryException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) Iterator(java.util.Iterator) RegionEntry(org.apache.geode.internal.cache.RegionEntry) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException)

Example 4 with MultiIndexCreationException

use of org.apache.geode.cache.query.MultiIndexCreationException in project geode by apache.

the class PartitionedRegion method populateEmptyIndexes.

private boolean populateEmptyIndexes(Set<Index> indexes, HashMap<String, Exception> exceptionsMap) {
    boolean throwException = false;
    if (getDataStore() != null && indexes.size() > 0) {
        Set localBuckets = getDataStore().getAllLocalBuckets();
        Iterator it = localBuckets.iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            Region bucket = (Region) entry.getValue();
            if (bucket == null) {
                continue;
            }
            IndexManager bucketIndexManager = IndexUtils.getIndexManager(bucket, true);
            Set<Index> bucketIndexes = getBucketIndexesForPRIndexes(bucket, indexes);
            try {
                bucketIndexManager.populateIndexes(bucketIndexes);
            } catch (MultiIndexCreationException ex) {
                exceptionsMap.putAll(ex.getExceptionsMap());
                throwException = true;
            }
        }
    }
    return throwException;
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager) HashSet(java.util.HashSet) Set(java.util.Set) ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) PREntriesIterator(org.apache.geode.internal.cache.partitioned.PREntriesIterator) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) DumpB2NRegion(org.apache.geode.internal.cache.partitioned.DumpB2NRegion) 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) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashMap(java.util.HashMap) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException)

Example 5 with MultiIndexCreationException

use of org.apache.geode.cache.query.MultiIndexCreationException 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

MultiIndexCreationException (org.apache.geode.cache.query.MultiIndexCreationException)8 Index (org.apache.geode.cache.query.Index)7 HashMap (java.util.HashMap)4 IndexExistsException (org.apache.geode.cache.query.IndexExistsException)4 QueryService (org.apache.geode.cache.query.QueryService)4 PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)4 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CancelException (org.apache.geode.CancelException)3 CacheException (org.apache.geode.cache.CacheException)3 Region (org.apache.geode.cache.Region)3 FunctionException (org.apache.geode.cache.execute.FunctionException)3 IndexCreationException (org.apache.geode.cache.query.IndexCreationException)3 IndexNameConflictException (org.apache.geode.cache.query.IndexNameConflictException)3 QueryException (org.apache.geode.cache.query.QueryException)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 ExecutionException (java.util.concurrent.ExecutionException)2