Search in sources :

Example 1 with IndexExistsException

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

the class PartitionedIndex method verifyAndCreateMissingIndex.

/**
   * Verify if the index is available of the buckets. If not create index on the bucket.
   */
public void verifyAndCreateMissingIndex(List buckets) throws QueryInvocationTargetException {
    PartitionedRegion pr = (PartitionedRegion) this.getRegion();
    PartitionedRegionDataStore prds = pr.getDataStore();
    for (Object bId : buckets) {
        // create index
        BucketRegion bukRegion = (BucketRegion) prds.getLocalBucketById((Integer) bId);
        if (bukRegion == null) {
            throw new QueryInvocationTargetException("Bucket not found for the id :" + bId);
        }
        IndexManager im = IndexUtils.getIndexManager(bukRegion, true);
        if (im != null && im.getIndex(indexName) == null) {
            try {
                if (pr.getCache().getLogger().fineEnabled()) {
                    pr.getCache().getLogger().fine("Verifying index presence on bucket region. " + " Found index " + this.indexName + " not present on the bucket region " + bukRegion.getFullPath() + ", index will be created on this region.");
                }
                ExecutionContext externalContext = new ExecutionContext(null, bukRegion.getCache());
                externalContext.setBucketRegion(pr, bukRegion);
                im.createIndex(this.indexName, this.type, this.originalIndexedExpression, this.fromClause, this.imports, externalContext, this, true);
            } catch (IndexExistsException iee) {
            // Index exists.
            } catch (IndexNameConflictException ince) {
            // ignore.
            }
        }
    }
}
Also used : ExecutionContext(org.apache.geode.cache.query.internal.ExecutionContext) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore)

Example 2 with IndexExistsException

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

the class RegionProvider method doInitializeSortedSet.

private void doInitializeSortedSet(ByteArrayWrapper key, Region<?, ?> r) throws RegionNotFoundException, IndexInvalidException {
    String fullpath = r.getFullPath();
    try {
        queryService.createIndex("scoreIndex", "entry.value.score", r.getFullPath() + ".entrySet entry");
        queryService.createIndex("scoreIndex2", "value.score", r.getFullPath() + ".values value");
    } catch (IndexNameConflictException | IndexExistsException | UnsupportedOperationException e) {
    // ignore, these indexes already exist or unsupported but make sure prepared queries are made
    }
    HashMap<Enum<?>, Query> queryList = new HashMap<Enum<?>, Query>();
    for (SortedSetQuery lq : SortedSetQuery.values()) {
        String queryString = lq.getQueryString(fullpath);
        Query query = this.queryService.newQuery(queryString);
        queryList.put(lq, query);
    }
    this.preparedQueries.put(key, queryList);
}
Also used : IndexExistsException(org.apache.geode.cache.query.IndexExistsException) Query(org.apache.geode.cache.query.Query) SortedSetQuery(org.apache.geode.redis.internal.executor.SortedSetQuery) ListQuery(org.apache.geode.redis.internal.executor.ListQuery) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedSetQuery(org.apache.geode.redis.internal.executor.SortedSetQuery)

Example 3 with IndexExistsException

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

the class CreateIndexFunction method execute.

@Override
public void execute(FunctionContext context) {
    final IndexInfo indexInfo = (IndexInfo) context.getArguments();
    String memberId = null;
    try {
        Cache cache = CacheFactory.getAnyInstance();
        memberId = cache.getDistributedSystem().getDistributedMember().getId();
        QueryService queryService = cache.getQueryService();
        String indexName = indexInfo.getIndexName();
        String indexedExpression = indexInfo.getIndexedExpression();
        String fromClause = indexInfo.getRegionPath();
        // Check to see if the region path contains an alias e.g "/region1 r1"
        // Then the first string will be the regionPath
        String[] regionPathTokens = fromClause.trim().split(" ");
        String regionPath = regionPathTokens[0];
        switch(indexInfo.getIndexType()) {
            case IndexInfo.RANGE_INDEX:
                queryService.createIndex(indexName, indexedExpression, fromClause);
                break;
            case IndexInfo.KEY_INDEX:
                queryService.createKeyIndex(indexName, indexedExpression, fromClause);
                break;
            case IndexInfo.HASH_INDEX:
                queryService.createHashIndex(indexName, indexedExpression, fromClause);
                break;
            default:
                queryService.createIndex(indexName, indexedExpression, fromClause);
        }
        regionPath = getValidRegionName(cache, regionPath);
        setResultInSender(context, indexInfo, memberId, cache, regionPath);
    } catch (IndexExistsException e) {
        String message = CliStrings.format(CliStrings.CREATE_INDEX__INDEX__EXISTS, indexInfo.getIndexName());
        context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
    } catch (IndexNameConflictException e) {
        String message = CliStrings.format(CliStrings.CREATE_INDEX__NAME__CONFLICT, indexInfo.getIndexName());
        context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
    } catch (RegionNotFoundException e) {
        String message = CliStrings.format(CliStrings.CREATE_INDEX__INVALID__REGIONPATH, indexInfo.getRegionPath());
        context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
    } catch (IndexInvalidException e) {
        context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
    } catch (Exception e) {
        String exceptionMessage = CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage());
        context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
    }
}
Also used : IndexExistsException(org.apache.geode.cache.query.IndexExistsException) QueryService(org.apache.geode.cache.query.QueryService) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) IndexInfo(org.apache.geode.management.internal.cli.domain.IndexInfo) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) Cache(org.apache.geode.cache.Cache)

Example 4 with IndexExistsException

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

the class OrderByPartitionedDUnitTest method createIndex.

private void createIndex(VM vm, final String indexName, IndexType indexType, final String indexedExpression, final String fromClause) {
    int indxTypeCode = -1;
    if (indexType.equals(IndexType.FUNCTIONAL)) {
        indxTypeCode = 0;
    } else if (indexType.equals(IndexType.PRIMARY_KEY)) {
        indxTypeCode = 1;
    } else if (indexType.equals(IndexType.HASH)) {
        indxTypeCode = 2;
    }
    final int finalIndxTypeCode = indxTypeCode;
    vm.invoke(new SerializableRunnable("create index") {

        public void run() {
            try {
                Cache cache = getCache();
                IndexType indxType = null;
                if (finalIndxTypeCode == 0) {
                    indxType = IndexType.FUNCTIONAL;
                } else if (finalIndxTypeCode == 1) {
                    indxType = IndexType.PRIMARY_KEY;
                } else if (finalIndxTypeCode == 2) {
                    indxType = IndexType.HASH;
                }
                cache.getQueryService().createIndex(indexName, indxType, indexedExpression, fromClause);
            } catch (RegionNotFoundException e) {
                fail(e.toString());
            } catch (IndexExistsException e) {
                fail(e.toString());
            } catch (IndexNameConflictException e) {
                fail(e.toString());
            }
        }
    });
}
Also used : IndexExistsException(org.apache.geode.cache.query.IndexExistsException) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IndexType(org.apache.geode.cache.query.IndexType) Cache(org.apache.geode.cache.Cache)

Example 5 with IndexExistsException

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

the class QueryIndexDUnitTest method createIndex.

private static void createIndex() {
    Region region = basicGetCache().getRegion("portfolios");
    if (region == null) {
        logger.info("The region is not created properly");
    } else {
        if (!region.isDestroyed()) {
            logger.info("Obtained the region with name :" + "portfolios");
            QueryService qs = basicGetCache().getQueryService();
            if (qs != null) {
                try {
                    qs.createIndex("statusIndex", "status", "/portfolios");
                    logger.info("Index statusIndex Created successfully");
                } catch (IndexNameConflictException e) {
                    Assert.fail("Caught IndexNameConflictException", e);
                } catch (IndexExistsException e) {
                    Assert.fail("Caught IndexExistsException", e);
                } catch (QueryException e) {
                    Assert.fail("Caught exception while trying to create index", e);
                }
            } else {
                fail("Could not obtain QueryService for the cache ");
            }
        } else {
            fail("Region.isDestroyed() returned true for region : " + "/portfolios");
        }
    }
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) QueryService(org.apache.geode.cache.query.QueryService) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) Region(org.apache.geode.cache.Region)

Aggregations

IndexExistsException (org.apache.geode.cache.query.IndexExistsException)12 IndexNameConflictException (org.apache.geode.cache.query.IndexNameConflictException)11 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)6 Index (org.apache.geode.cache.query.Index)5 Cache (org.apache.geode.cache.Cache)4 QueryService (org.apache.geode.cache.query.QueryService)4 Region (org.apache.geode.cache.Region)3 IndexInvalidException (org.apache.geode.cache.query.IndexInvalidException)3 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3 ExecutionException (java.util.concurrent.ExecutionException)2 FutureTask (java.util.concurrent.FutureTask)2 IndexType (org.apache.geode.cache.query.IndexType)2 MultiIndexCreationException (org.apache.geode.cache.query.MultiIndexCreationException)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1