Search in sources :

Example 1 with IndexCreationData

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

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

the class CacheXmlParser method endIndex.

/**
   * When index element is ending we need to verify all attributes because of new index tag
   * definition since 6.6.1 and support previous definition also.
   * 
   * if <code>functional</code> element was not there then we need to validate expression and
   * fromClause as not null.
   */
private void endIndex() {
    boolean throwExcep = false;
    IndexCreationData icd = (IndexCreationData) this.stack.pop();
    if (icd.getIndexType() == null) {
        throwExcep = true;
    } else {
        if (icd.getIndexType().equals(IndexType.PRIMARY_KEY)) {
            if (icd.getIndexExpression() == null) {
                throwExcep = true;
            }
        } else {
            if (icd.getIndexExpression() == null && icd.getIndexFromClause() == null) {
                throwExcep = true;
            }
        }
    }
    if (!throwExcep) {
        RegionCreation rc = (RegionCreation) this.stack.peek();
        rc.addIndexData(icd);
    } else {
        throw new InternalGemFireException(LocalizedStrings.CacheXmlParser_CACHEXMLPARSERENDINDEXINDEX_CREATION_ATTRIBUTE_NOT_CORRECTLY_SPECIFIED.toLocalizedString());
    }
}
Also used : IndexCreationData(org.apache.geode.cache.query.internal.index.IndexCreationData) InternalGemFireException(org.apache.geode.InternalGemFireException)

Example 3 with IndexCreationData

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

the class CacheXmlParser method startIndex.

/**
   * When a <code>index</code> element is encounter, we create the IndexCreationData object from the
   * Stack. Set the required parameters in the IndexCreationData object & push it on stack.
   *
   */
private void startIndex(Attributes atts) {
    boolean isPrimary = false;
    String type = "";
    IndexCreationData icd = new IndexCreationData(atts.getValue(NAME));
    int len = atts.getLength();
    if (len > 1) {
        if (Boolean.valueOf(atts.getValue(KEY_INDEX))) {
            icd.setIndexType(IndexType.PRIMARY_KEY);
            isPrimary = true;
        }
        type = atts.getValue(INDEX_TYPE);
    }
    if (len > 2) {
        String fromClause = atts.getValue(FROM_CLAUSE);
        String expression = atts.getValue(EXPRESSION);
        String importStr = atts.getValue(IMPORTS);
        if (isPrimary) {
            icd.setIndexData(IndexType.PRIMARY_KEY, null, expression, null);
        } else {
            if (type == null) {
                type = RANGE_INDEX_TYPE;
            }
            if (type.equals(HASH_INDEX_TYPE)) {
                icd.setIndexData(IndexType.HASH, fromClause, expression, importStr);
            } else if (type.equals(RANGE_INDEX_TYPE)) {
                icd.setIndexData(IndexType.FUNCTIONAL, fromClause, expression, importStr);
            } else {
                logger.trace(LogMarker.CACHE_XML_PARSER, LocalizedMessage.create(LocalizedStrings.CacheXmlParser_UNKNOWN_INDEX_TYPE, type));
                icd.setIndexData(IndexType.FUNCTIONAL, fromClause, expression, importStr);
            }
        }
    }
    this.stack.push(icd);
}
Also used : IndexCreationData(org.apache.geode.cache.query.internal.index.IndexCreationData)

Example 4 with IndexCreationData

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

the class PartitionedRegion method sendIndexCreationMsg.

/**
   * Explicitly sends an index creation message to a newly added node to the system on prs.
   * 
   * @param idM id on the newly added node.
   */
public void sendIndexCreationMsg(InternalDistributedMember idM) {
    if (!this.isIndexed()) {
        return;
    }
    RegionAdvisor advisor = (RegionAdvisor) getCacheDistributionAdvisor();
    final Set<InternalDistributedMember> recipients = advisor.adviseDataStore();
    if (!recipients.contains(idM)) {
        logger.info(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_NEWLY_ADDED_MEMBER_TO_THE_PR_IS_AN_ACCESSOR_AND_WILL_NOT_RECEIVE_INDEX_INFORMATION_0, idM));
        return;
    }
    // this should add the member to a synchronized set and then sent this member
    // and index creation msg latter after its completed creating the partitioned region.
    IndexCreationMsg.IndexCreationResponse response;
    IndexCreationMsg.IndexCreationResult result;
    if (this.indexes.isEmpty()) {
        return;
    }
    Iterator it = this.indexes.values().iterator();
    HashSet<IndexCreationData> indexDefinitions = new HashSet<>();
    Set<PartitionedIndex> indexes = new HashSet<>();
    while (it.hasNext()) {
        Object ind = it.next();
        // the index is not in create phase, its created successfully).
        if (!(ind instanceof Index)) {
            continue;
        }
        PartitionedIndex prIndex = (PartitionedIndex) ind;
        indexes.add(prIndex);
        IndexCreationData icd = new IndexCreationData(prIndex.getName());
        icd.setIndexData(prIndex.getType(), prIndex.getFromClause(), prIndex.getIndexedExpression(), prIndex.getImports(), true);
        indexDefinitions.add(icd);
    }
    response = (IndexCreationMsg.IndexCreationResponse) IndexCreationMsg.send(idM, this, indexDefinitions);
    if (logger.isDebugEnabled()) {
        logger.debug("Sending explicitly index creation message to : {}", idM);
    }
    if (response != null) {
        try {
            result = response.waitForResult();
            Map<String, Integer> remoteIndexBucketsMap = result.getIndexBucketsMap();
            // set the number of remote buckets indexed for each pr index
            for (Index ind : indexes) {
                ((PartitionedIndex) ind).setRemoteBucketesIndexed(remoteIndexBucketsMap.get(ind.getName()));
            }
        } catch (ForceReattemptException e) {
            logger.info(LocalizedStrings.PartitionedRegion_FORCEREATTEMPT_EXCEPTION___0, e);
        }
    }
}
Also used : RegionAdvisor(org.apache.geode.internal.cache.partitioned.RegionAdvisor) 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) IndexCreationData(org.apache.geode.cache.query.internal.index.IndexCreationData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PREntriesIterator(org.apache.geode.internal.cache.partitioned.PREntriesIterator) Iterator(java.util.Iterator) IndexCreationMsg(org.apache.geode.internal.cache.partitioned.IndexCreationMsg) HashSet(java.util.HashSet)

Example 5 with IndexCreationData

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

the class CacheXmlParser method startFunctionalIndex.

/**
   * When a <code>functional</code> element is encounter, we pop the IndexCreationData object from
   * the Stack. Set the required parameters in the IndexCreationData object & set it in
   * RegionCreation object.
   *
   */
private void startFunctionalIndex(Attributes atts) {
    boolean throwExcep = false;
    IndexCreationData icd = (IndexCreationData) this.stack.peek();
    // icd.setIndexType(FUNCTIONAL);
    int len = -1;
    if ((len = atts.getLength()) > 1) {
        String fromClause = atts.getValue(FROM_CLAUSE);
        String expression = atts.getValue(EXPRESSION);
        String importStr = null;
        if (len == 3)
            importStr = atts.getValue(IMPORTS);
        if (fromClause == null || expression == null) {
            throwExcep = true;
        } else {
            icd.setIndexData(IndexType.FUNCTIONAL, fromClause, expression, importStr);
        }
    } else {
        throwExcep = true;
    }
    if (throwExcep) {
        throw new InternalGemFireException(LocalizedStrings.CacheXmlParser_CACHEXMLPARSERSTARTFUNCTIONALINDEXINDEX_CREATION_ATTRIBUTE_NOT_CORRECTLY_SPECIFIED.toLocalizedString());
    }
}
Also used : IndexCreationData(org.apache.geode.cache.query.internal.index.IndexCreationData) InternalGemFireException(org.apache.geode.InternalGemFireException)

Aggregations

IndexCreationData (org.apache.geode.cache.query.internal.index.IndexCreationData)9 InternalGemFireException (org.apache.geode.InternalGemFireException)5 Index (org.apache.geode.cache.query.Index)4 PartitionedIndex (org.apache.geode.cache.query.internal.index.PartitionedIndex)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 MultiIndexCreationException (org.apache.geode.cache.query.MultiIndexCreationException)3 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CancelException (org.apache.geode.CancelException)2 CacheException (org.apache.geode.cache.CacheException)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)2 AbstractIndex (org.apache.geode.cache.query.internal.index.AbstractIndex)2 IndexCreationMsg (org.apache.geode.internal.cache.partitioned.IndexCreationMsg)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1