Search in sources :

Example 26 with QueryInvocationTargetException

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

the class PartitionedIndex method getBucketIndex.

/**
   * Returns the index for the bucket.
   */
public static AbstractIndex getBucketIndex(PartitionedRegion pr, String indexName, Integer bId) throws QueryInvocationTargetException {
    try {
        pr.checkReadiness();
    } catch (Exception ex) {
        throw new QueryInvocationTargetException(ex.getMessage());
    }
    PartitionedRegionDataStore prds = pr.getDataStore();
    BucketRegion bukRegion;
    bukRegion = (BucketRegion) prds.getLocalBucketById(bId);
    if (bukRegion == null) {
        throw new BucketMovedException("Bucket not found for the id :" + bId);
    }
    AbstractIndex index = null;
    if (bukRegion.getIndexManager() != null) {
        index = (AbstractIndex) (bukRegion.getIndexManager().getIndex(indexName));
    } else {
        if (pr.getCache().getLogger().fineEnabled()) {
            pr.getCache().getLogger().fine("Index Manager not found for the bucket region " + bukRegion.getFullPath() + " unable to fetch the index " + indexName);
        }
        throw new QueryInvocationTargetException("Index Manager not found, " + " unable to fetch the index " + indexName);
    }
    return index;
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) 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) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException)

Example 27 with QueryInvocationTargetException

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

the class PRQueryProcessor method executeQueryOnBuckets.

private void executeQueryOnBuckets(Collection<Collection> resultCollector, ExecutionContext context) throws ForceReattemptException, QueryInvocationTargetException, QueryException {
    // Check if QueryMonitor is enabled, if so add query to be monitored.
    QueryMonitor queryMonitor = null;
    context.setCqQueryContext(query.isCqQuery());
    if (GemFireCacheImpl.getInstance() != null) {
        queryMonitor = GemFireCacheImpl.getInstance().getQueryMonitor();
    }
    try {
        if (queryMonitor != null) {
            // Add current thread to be monitored by QueryMonitor.
            queryMonitor.monitorQueryThread(Thread.currentThread(), query);
        }
        Object results = query.executeUsingContext(context);
        synchronized (resultCollector) {
            // TODO: In what situation would the results object itself be undefined?
            // The elements of the results can be undefined , but not the resultset itself
            this.resultType = ((SelectResults) results).getCollectionType().getElementType();
            resultCollector.add((Collection) results);
        }
        isIndexUsedForLocalQuery = ((QueryExecutionContext) context).isIndexUsed();
    } catch (BucketMovedException bme) {
        if (logger.isDebugEnabled()) {
            logger.debug("Query targeted local bucket not found. {}", bme.getMessage(), bme);
        }
        throw new ForceReattemptException("Query targeted local bucket not found." + bme.getMessage(), bme);
    } catch (RegionDestroyedException rde) {
        throw new QueryInvocationTargetException("The Region on which query is executed may have been destroyed." + rde.getMessage(), rde);
    } catch (QueryException qe) {
        // Check if PR is locally destroyed.
        if (pr.isLocallyDestroyed || pr.isClosed) {
            throw new ForceReattemptException("Local Partition Region or the targeted bucket has been moved");
        }
        throw qe;
    } finally {
        if (queryMonitor != null) {
            queryMonitor.stopMonitoringQueryThread(Thread.currentThread(), query);
        }
    }
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) SelectResults(org.apache.geode.cache.query.SelectResults) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) QueryMonitor(org.apache.geode.cache.query.internal.QueryMonitor) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException)

Example 28 with QueryInvocationTargetException

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

the class QueryUsingFunctionContextDUnitTest method testQueriesWithFilterKeysOnPRWithRebalancing.

// GEODE-575: ignores lots of exceptions, non-thread-safe test hooks
@Category(FlakyTest.class)
@Test
public void testQueriesWithFilterKeysOnPRWithRebalancing() {
    IgnoredException.addIgnoredException("QueryInvocationTargetException");
    IgnoredException.addIgnoredException("java.net.SocketException");
    IgnoredException.addIgnoredException("ServerConnectivityException");
    IgnoredException.addIgnoredException("FunctionException");
    IgnoredException.addIgnoredException("IOException");
    // Close cache on server1
    server1.invoke(new CacheSerializableRunnable("Set QueryObserver in cache on server1") {

        @Override
        public void run2() throws CacheException {
            class MyQueryObserver extends IndexTrackingQueryObserver {

                @Override
                public void startQuery(Query query) {
                    Region pr = CacheFactory.getAnyInstance().getRegion(PartitionedRegionName1);
                    Region KeyRegion = null;
                    for (int i = 6; i < 9; i++) {
                        KeyRegion = ((PartitionedRegion) pr).getBucketRegion(i);
                        if (KeyRegion != null)
                            KeyRegion.destroyRegion();
                    }
                }
            }
            ;
            QueryObserverHolder.setInstance(new MyQueryObserver());
        }
    });
    client.invoke(new CacheSerializableRunnable("Run function on PR") {

        @Override
        public void run2() throws CacheException {
            Set filter = new HashSet();
            ResultCollector rcollector = null;
            filter.addAll(getFilter(6, 9));
            for (int i = 0; i < queries.length; i++) {
                try {
                    function = new TestQueryFunction("queryFunction");
                    rcollector = FunctionService.onRegion(CacheFactory.getAnyInstance().getRegion(PartitionedRegionName1)).setArguments(queries[i]).withFilter(filter).execute(function);
                    // Should not come here, an exception is expected from above function call.
                    fail("Function call did not fail for query with function context");
                } catch (FunctionException ex) {
                    if (!((ex.getCause() instanceof QueryInvocationTargetException) || (ex.getCause() instanceof ServerConnectivityException))) {
                        if (ex.getCause() instanceof FunctionException) {
                            FunctionException fe = (FunctionException) ex.getCause();
                            if (!fe.getMessage().startsWith("IOException")) {
                                fail("Should have received an QueryInvocationTargetException but recieved" + ex.getMessage());
                            }
                        } else {
                            fail("Should have received an QueryInvocationTargetException but recieved" + ex.getMessage());
                        }
                    }
                }
            }
        // For loop ends here.
        }
    });
    // Close cache on server1
    server1.invoke(new CacheSerializableRunnable("Reset Query Observer on server1") {

        @Override
        public void run2() throws CacheException {
            QueryObserverHolder.reset();
        }
    });
}
Also used : LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) Set(java.util.Set) StructSetOrResultsSet(org.apache.geode.cache.query.functional.StructSetOrResultsSet) HashSet(java.util.HashSet) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) FunctionException(org.apache.geode.cache.execute.FunctionException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 29 with QueryInvocationTargetException

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

the class GroupByQueryDUnitTest method runQuery.

private void runQuery(VM queryVM) throws Exception {
    // createIndex(vm0, "compactRangeIndex", "entry.value",
    // "/region.entrySet entry");
    // Do Puts
    queryVM.invoke(new SerializableRunnable("putting data") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("portfolio");
            for (int i = 1; i < 200; ++i) {
                Portfolio pf = new Portfolio(i);
                pf.shortID = (short) ((short) i / 5);
                region.put("" + i, pf);
            }
        }
    });
    queryVM.invoke(new SerializableRunnable("query") {

        public void run() {
            try {
                QueryService qs = getCache().getQueryService();
                String queryStr = "select  p.shortID as short_id  from /portfolio p where p.ID >= 0 group by short_id ";
                Query query = qs.newQuery(queryStr);
                SelectResults<Struct> results = (SelectResults<Struct>) query.execute();
                Iterator<Struct> iter = results.iterator();
                int counter = 0;
                while (iter.hasNext()) {
                    Struct str = iter.next();
                    assertEquals(counter++, ((Short) str.get("short_id")).intValue());
                }
                assertEquals(39, counter - 1);
            } catch (QueryInvocationTargetException e) {
                fail(e.toString());
            } catch (NameResolutionException e) {
                fail(e.toString());
            } catch (TypeMismatchException e) {
                fail(e.toString());
            } catch (FunctionDomainException e) {
                fail(e.toString());
            }
        }
    });
}
Also used : Query(org.apache.geode.cache.query.Query) Portfolio(org.apache.geode.cache.query.data.Portfolio) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) Struct(org.apache.geode.cache.query.Struct) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

Example 30 with QueryInvocationTargetException

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

the class GetDeliveredOrders method execute.

public void execute(FunctionContext context) {
    Cache c = null;
    ArrayList<Object> vals = new ArrayList<Object>();
    try {
        c = CacheFactory.getAnyInstance();
    } catch (CacheClosedException ex) {
        vals.add("NoCacheFoundResult");
        context.getResultSender().lastResult(vals);
    }
    String oql = "SELECT o.purchaseOrderNo, o.deliveryDate  FROM /orders o WHERE o.deliveryDate != NULL";
    final Query query = c.getQueryService().newQuery(oql);
    SelectResults result = null;
    try {
        result = (SelectResults) query.execute();
        int resultSize = result.size();
        if (result instanceof Collection<?>)
            for (Object item : result) {
                vals.add(item);
            }
    } catch (FunctionDomainException e) {
        if (c != null)
            c.getLogger().info("Caught FunctionDomainException while executing function GetDeliveredOrders: " + e.getMessage());
    } catch (TypeMismatchException e) {
        if (c != null)
            c.getLogger().info("Caught TypeMismatchException while executing function GetDeliveredOrders: " + e.getMessage());
    } catch (NameResolutionException e) {
        if (c != null)
            c.getLogger().info("Caught NameResolutionException while executing function GetDeliveredOrders: " + e.getMessage());
    } catch (QueryInvocationTargetException e) {
        if (c != null)
            c.getLogger().info("Caught QueryInvocationTargetException while executing function GetDeliveredOrders: " + e.getMessage());
    }
    context.getResultSender().lastResult(vals);
}
Also used : Query(org.apache.geode.cache.query.Query) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) ArrayList(java.util.ArrayList) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) SelectResults(org.apache.geode.cache.query.SelectResults) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) Collection(java.util.Collection) Cache(org.apache.geode.cache.Cache)

Aggregations

QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)42 Region (org.apache.geode.cache.Region)23 SelectResults (org.apache.geode.cache.query.SelectResults)22 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)21 QueryService (org.apache.geode.cache.query.QueryService)20 QueryException (org.apache.geode.cache.query.QueryException)16 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)16 Cache (org.apache.geode.cache.Cache)15 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)15 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)15 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)15 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)14 Query (org.apache.geode.cache.query.Query)13 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)13 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)12 CancelException (org.apache.geode.CancelException)10 StructSetOrResultsSet (org.apache.geode.cache.query.functional.StructSetOrResultsSet)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)10 Host (org.apache.geode.test.dunit.Host)10 VM (org.apache.geode.test.dunit.VM)10