Search in sources :

Example 11 with NameResolutionException

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

Example 12 with NameResolutionException

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

the class CompiledOperation method eval0.

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED", justification = "Does not matter if the methodDispatch that isn't stored in the map is used")
private Object eval0(Object receiver, Class resolutionType, ExecutionContext context) throws TypeMismatchException, FunctionDomainException, NameResolutionException, QueryInvocationTargetException {
    if (receiver == null || receiver == QueryService.UNDEFINED)
        return QueryService.UNDEFINED;
    List args = new ArrayList();
    List argTypes = new ArrayList();
    Iterator i = this.args.iterator();
    while (i.hasNext()) {
        CompiledValue arg = (CompiledValue) i.next();
        Object o = arg.evaluate(context);
        // undefined arg produces undefines method result
        if (o == QueryService.UNDEFINED)
            return QueryService.UNDEFINED;
        args.add(o);
        // pass in null for the type if the runtime value is null
        if (o == null)
            argTypes.add(null);
        else
            // commented out because we currently always use the runtime type for args
            // else if (arg.getType() == Identifier)
            // {
            // CompiledValue resolved = context.resolve(((CompiledID)arg).getId());
            // if (resolved != null && resolved.getType() == ITERATOR)
            // argTypes.add(((RuntimeIterator)resolved).getBaseCollection().getConstraint());
            // else
            // argTypes.add(o.getClass());
            // }
            // otherwise use the runtime type
            argTypes.add(o.getClass());
    }
    // see if in cache
    MethodDispatch methodDispatch;
    List key = Arrays.asList(new Object[] { resolutionType, this.methodName, argTypes });
    methodDispatch = (MethodDispatch) CompiledOperation.cache.get(key);
    if (methodDispatch == null) {
        try {
            methodDispatch = new MethodDispatch(resolutionType, this.methodName, argTypes);
        } catch (NameResolutionException nre) {
            if (!org.apache.geode.cache.query.Struct.class.isAssignableFrom(resolutionType) && (DefaultQueryService.QUERY_HETEROGENEOUS_OBJECTS || DefaultQueryService.TEST_QUERY_HETEROGENEOUS_OBJECTS)) {
                return QueryService.UNDEFINED;
            } else {
                throw nre;
            }
        }
        // cache
        CompiledOperation.cache.putIfAbsent(key, methodDispatch);
    }
    if (receiver instanceof PdxInstance) {
        try {
            if (receiver instanceof PdxInstanceImpl) {
                receiver = ((PdxInstanceImpl) receiver).getCachedObject();
            } else {
                receiver = ((PdxInstance) receiver).getObject();
            }
        } catch (PdxSerializationException ex) {
            throw new QueryInvocationTargetException(ex);
        }
    } else if (receiver instanceof PdxString) {
        receiver = ((PdxString) receiver).toString();
    }
    return methodDispatch.invoke(receiver, args);
}
Also used : ArrayList(java.util.ArrayList) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) PdxString(org.apache.geode.pdx.internal.PdxString) PdxSerializationException(org.apache.geode.pdx.PdxSerializationException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) PdxInstance(org.apache.geode.pdx.PdxInstance) PdxInstanceImpl(org.apache.geode.pdx.internal.PdxInstanceImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with NameResolutionException

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

the class ResourceManagerWithQueryMonitorDUnitTest method doCriticalMemoryHitDuringGatherTestWithMultipleServers.

// tests low memory hit while gathering partition region results
private void doCriticalMemoryHitDuringGatherTestWithMultipleServers(final String regionName, boolean createPR, final int criticalThreshold, final boolean disabledQueryMonitorForLowMem, final int queryTimeout, final boolean hitCriticalThreshold) throws Exception {
    // create region on the server
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM server2 = host.getVM(1);
    final VM client = host.getVM(2);
    final int numObjects = 200;
    try {
        final int[] port = AvailablePortHelper.getRandomAvailableTCPPorts(2);
        startCacheServer(server1, port[0], criticalThreshold, disabledQueryMonitorForLowMem, queryTimeout, regionName, createPR, 0);
        startCacheServer(server2, port[1], criticalThreshold, true, -1, regionName, createPR, 0);
        startClient(client, server1, port[0], regionName);
        populateData(server2, regionName, numObjects);
        createCancelDuringGatherTestHook(server1);
        client.invoke(new SerializableCallable("executing query to be canceled by gather") {

            public Object call() {
                QueryService qs = null;
                try {
                    qs = getCache().getQueryService();
                    Query query = qs.newQuery("Select * From /" + regionName);
                    query.execute();
                } catch (ServerOperationException soe) {
                    if (soe.getRootCause() instanceof QueryException) {
                        QueryException e = (QueryException) soe.getRootCause();
                        if (!isExceptionDueToLowMemory(e, CRITICAL_HEAP_USED)) {
                            throw new CacheException(soe) {
                            };
                        } else {
                            return 0;
                        }
                    }
                } catch (Exception e) {
                    throw new CacheException(e) {
                    };
                }
                // assertTrue(((CancelDuringGatherHook)DefaultQuery.testHook).triggeredOOME);
                throw new CacheException("should have hit low memory") {
                };
            }
        });
        verifyRejectedObjects(server1, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
        // Pause for a second and then let's recover
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        // Recover from critical heap
        if (hitCriticalThreshold) {
            vmRecoversFromCriticalHeap(server1);
        }
        // Check to see if query execution is ok under "normal" or "healthy" conditions
        client.invoke(new CacheSerializableRunnable("Executing query when system is 'Normal'") {

            public void run2() {
                try {
                    QueryService qs = getCache().getQueryService();
                    Query query = qs.newQuery("Select * From /" + regionName);
                    SelectResults results = (SelectResults) query.execute();
                    assertEquals(numObjects, results.size());
                } catch (QueryInvocationTargetException e) {
                    assertFalse(true);
                } catch (NameResolutionException e) {
                    assertFalse(true);
                } catch (TypeMismatchException e) {
                    assertFalse(true);
                } catch (FunctionDomainException e) {
                    assertFalse(true);
                }
            }
        });
        // Recover from critical heap
        if (hitCriticalThreshold) {
            vmRecoversFromCriticalHeap(server1);
        }
    } finally {
        stopServer(server1);
        stopServer(server2);
    }
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Host(org.apache.geode.test.dunit.Host) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) CacheException(org.apache.geode.cache.CacheException) QueryExecutionLowMemoryException(org.apache.geode.cache.query.QueryExecutionLowMemoryException) QueryException(org.apache.geode.cache.query.QueryException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryException(org.apache.geode.cache.query.QueryException) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ServerOperationException(org.apache.geode.cache.client.ServerOperationException)

Example 14 with NameResolutionException

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

the class ResourceManagerWithQueryMonitorDUnitTest method doCriticalMemoryHitTestWithMultipleServers.

// Executes on client cache with multiple configured servers
private void doCriticalMemoryHitTestWithMultipleServers(final String regionName, boolean createPR, final int criticalThreshold, final boolean disabledQueryMonitorForLowMem, final int queryTimeout, final boolean hitCriticalThreshold) throws Exception {
    // create region on the server
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM server2 = host.getVM(1);
    final VM client = host.getVM(2);
    final int numObjects = 200;
    try {
        final int[] port = AvailablePortHelper.getRandomAvailableTCPPorts(2);
        startCacheServer(server1, port[0], criticalThreshold, disabledQueryMonitorForLowMem, queryTimeout, regionName, createPR, 0);
        startCacheServer(server2, port[1], criticalThreshold, true, -1, regionName, createPR, 0);
        startClient(client, server1, port[0], regionName);
        populateData(server2, regionName, numObjects);
        doTestCriticalHeapAndQueryTimeout(server1, client, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
        verifyRejectedObjects(server1, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
        // Pause for a second and then let's recover
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        // Recover from critical heap
        if (hitCriticalThreshold) {
            vmRecoversFromCriticalHeap(server1);
        }
        // Check to see if query execution is ok under "normal" or "healthy" conditions
        client.invoke(new CacheSerializableRunnable("Executing query when system is 'Normal'") {

            public void run2() {
                try {
                    QueryService qs = getCache().getQueryService();
                    Query query = qs.newQuery("Select * From /" + regionName);
                    SelectResults results = (SelectResults) query.execute();
                    assertEquals(numObjects, results.size());
                } catch (QueryInvocationTargetException e) {
                    assertFalse(true);
                } catch (NameResolutionException e) {
                    assertFalse(true);
                } catch (TypeMismatchException e) {
                    assertFalse(true);
                } catch (FunctionDomainException e) {
                    assertFalse(true);
                }
            }
        });
        // Execute a critical heap event/ query timeout test again
        doTestCriticalHeapAndQueryTimeout(server1, client, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
        verifyRejectedObjects(server1, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
        // Recover from critical heap
        if (hitCriticalThreshold) {
            vmRecoversFromCriticalHeap(server1);
        }
    } finally {
        stopServer(server1);
        stopServer(server2);
    }
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Host(org.apache.geode.test.dunit.Host) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) VM(org.apache.geode.test.dunit.VM)

Example 15 with NameResolutionException

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

the class IndexManager method getBestMatchIndex.

/**
   * Asif : Returns the best available Index based on the available iterators in the Group
   * 
   * TODO: Asif :Check if synchronization is needed while obtaining Array of Indexes as similar to
   * what we have used during index updates
   * 
   * @param indexType Primary or Range Index
   * @param definitions String array containing the canonicalized definitions of the Iterators of
   *        the Group
   * @param indexedExpression Index Expression path(CompiledValue) on which index needs to be
   *        created
   * @param context ExecutionContext object
   * @return IndexData object
   */
public IndexData getBestMatchIndex(IndexType indexType, String[] definitions, CompiledValue indexedExpression, ExecutionContext context) throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
    Index bestIndex = null;
    Index bestPRIndex = null;
    int[] bestMapping = null;
    int qItrSize = definitions.length;
    int bestIndexMatchLevel = qItrSize;
    Iterator iter = this.indexes.values().iterator();
    StringBuilder sb = new StringBuilder();
    indexedExpression.generateCanonicalizedExpression(sb, context);
    String indexExprStr = sb.toString();
    PartitionedIndex prIndex = null;
    Index prevBestPRIndex = null;
    Index prevBestIndex = null;
    Index index;
    while (iter.hasNext()) {
        Object ind = iter.next();
        // the index is in create phase.
        if (ind instanceof FutureTask) {
            continue;
        }
        // If the index is still empty
        if (!((AbstractIndex) ind).isPopulated()) {
            continue;
        }
        index = (Index) ind;
        if (index instanceof PartitionedIndex) {
            prIndex = (PartitionedIndex) index;
            // Get one of the bucket index. This index will be
            // available on all the buckets.
            index = prIndex.getBucketIndex();
            if (index == null) {
                continue;
            }
        }
        // Use simple strategy just pick first compatible index
        if (((IndexProtocol) index).isMatchingWithIndexExpression(indexedExpression, indexExprStr, context) && index.getType() == indexType) {
            // For PR the matched index needs to be available on all the query buckets.
            if (prIndex != null) {
                try {
                    // Protect the PartitionedIndex from being removed when it is being used.
                    if (!prIndex.acquireIndexReadLockForRemove()) {
                        continue;
                    }
                    prIndex.verifyAndCreateMissingIndex(context.getBucketList());
                } catch (Exception ignored) {
                    // Index is not there on all buckets.
                    // ignore this index.
                    prIndex.releaseIndexReadLockForRemove();
                    prIndex = null;
                    continue;
                }
            } else {
                // For index on replicated regions
                if (!((AbstractIndex) index).acquireIndexReadLockForRemove()) {
                    continue;
                }
            }
            /*
         * Asif : A match level of zero means exact match. A match level greater than 0 means the
         * query from clauses have extra iterators as compared to Index resultset ( This does not
         * neccessarily mean that Index resultset is not having extra fields. It is just that the
         * criteria for match level is the absence or presence of extra iterators. The order of
         * preference will be 0 , <0 , > 0 for first cut.
         */
            String[] indexDefinitions = ((IndexProtocol) index).getCanonicalizedIteratorDefinitions();
            int[] mapping = new int[qItrSize];
            int matchLevel = getMatchLevel(definitions, indexDefinitions, mapping);
            if (matchLevel == 0) {
                prevBestPRIndex = bestPRIndex;
                bestPRIndex = prIndex;
                prevBestIndex = bestIndex;
                bestIndex = index;
                bestIndexMatchLevel = matchLevel;
                bestMapping = mapping;
                // chosen as bestIndex.
                if (prIndex != null && prevBestPRIndex != null && prevBestPRIndex instanceof PartitionedIndex) {
                    ((PartitionedIndex) prevBestPRIndex).releaseIndexReadLockForRemove();
                    prevBestPRIndex = null;
                } else if (prevBestIndex != null) {
                    ((AbstractIndex) prevBestIndex).releaseIndexReadLockForRemove();
                    prevBestIndex = null;
                }
                break;
            } else if ((bestIndexMatchLevel > 0 && matchLevel < bestIndexMatchLevel) || (bestIndexMatchLevel < 0 && matchLevel < 0 && matchLevel > bestIndexMatchLevel)) {
                prevBestPRIndex = bestPRIndex;
                bestPRIndex = prIndex;
                prevBestIndex = bestIndex;
                bestIndex = index;
                bestIndexMatchLevel = matchLevel;
                bestMapping = mapping;
            }
            // release the lock if this index is not chosen as bestIndex.
            if (prIndex != null && bestPRIndex != prIndex) {
                prIndex.releaseIndexReadLockForRemove();
                prIndex = null;
            } else if (bestIndex != index) {
                ((AbstractIndex) index).releaseIndexReadLockForRemove();
                index = null;
            }
            // chosen as bestIndex.
            if (prevBestPRIndex != null && prevBestPRIndex instanceof PartitionedIndex) {
                ((PartitionedIndex) prevBestPRIndex).releaseIndexReadLockForRemove();
                prevBestPRIndex = null;
            } else if (prevBestIndex != null) {
                ((AbstractIndex) prevBestIndex).releaseIndexReadLockForRemove();
                prevBestIndex = null;
            }
        }
    }
    if (bestIndex != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("The best index found for index expression: {} is: {} with Match-level: {} and mapping: {}", indexExprStr, bestIndex, bestIndexMatchLevel, Arrays.toString(bestMapping));
        }
    }
    return bestIndex != null ? new IndexData((IndexProtocol) bestIndex, bestIndexMatchLevel, bestMapping) : null;
}
Also used : Index(org.apache.geode.cache.query.Index) 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) FutureTask(java.util.concurrent.FutureTask) Iterator(java.util.Iterator)

Aggregations

NameResolutionException (org.apache.geode.cache.query.NameResolutionException)17 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)16 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)16 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)15 Query (org.apache.geode.cache.query.Query)11 SelectResults (org.apache.geode.cache.query.SelectResults)11 QueryService (org.apache.geode.cache.query.QueryService)9 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)9 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)6 Host (org.apache.geode.test.dunit.Host)6 VM (org.apache.geode.test.dunit.VM)6 QueryException (org.apache.geode.cache.query.QueryException)5 QueryExecutionTimeoutException (org.apache.geode.cache.query.QueryExecutionTimeoutException)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 QueryExecutionLowMemoryException (org.apache.geode.cache.query.QueryExecutionLowMemoryException)4 Cache (org.apache.geode.cache.Cache)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 CacheException (org.apache.geode.cache.CacheException)3 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)3