Search in sources :

Example 6 with QueryExecutionLowMemoryException

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

the class QueryMessage method getNextReplyObject.

/**
   * Provide results to send back to requestor. terminate by returning END_OF_STREAM token object
   */
@Override
protected Object getNextReplyObject(PartitionedRegion pr) throws CacheException, ForceReattemptException, InterruptedException {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (QueryMonitor.isLowMemory()) {
        String reason = LocalizedStrings.QueryMonitor_LOW_MEMORY_CANCELED_QUERY.toLocalizedString(QueryMonitor.getMemoryUsedDuringLowMemory());
        throw new QueryExecutionLowMemoryException(reason);
    }
    if (Thread.interrupted()) {
        throw new InterruptedException();
    }
    while (this.currentResultIterator == null || !this.currentResultIterator.hasNext()) {
        if (this.currentSelectResultIterator.hasNext()) {
            if (this.isTraceInfoIteration && this.currentResultIterator != null) {
                this.isTraceInfoIteration = false;
            }
            Collection results = this.currentSelectResultIterator.next();
            if (isDebugEnabled) {
                logger.debug("Query result size: {}", results.size());
            }
            this.currentResultIterator = results.iterator();
        } else {
            return Token.END_OF_STREAM;
        }
    }
    Object data = this.currentResultIterator.next();
    boolean isPostGFE_8_1 = this.getSender().getVersionObject().compareTo(Version.GFE_81) > 0;
    // inaccurate struct type for backward compatibility.
    if (this.isStructType && !this.isTraceInfoIteration && isPostGFE_8_1) {
        return ((Struct) data).getFieldValues();
    } else if (this.isStructType && !this.isTraceInfoIteration) {
        Struct struct = (Struct) data;
        ObjectType[] fieldTypes = struct.getStructType().getFieldTypes();
        for (int i = 0; i < fieldTypes.length; ++i) {
            fieldTypes[i] = new ObjectTypeImpl(Object.class);
        }
        return data;
    } else {
        return data;
    }
}
Also used : QueryExecutionLowMemoryException(org.apache.geode.cache.query.QueryExecutionLowMemoryException) ObjectTypeImpl(org.apache.geode.cache.query.internal.types.ObjectTypeImpl) Collection(java.util.Collection) Struct(org.apache.geode.cache.query.Struct)

Example 7 with QueryExecutionLowMemoryException

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

the class QueryAccessController method runAdhocQuery.

/**
   * Run an adhoc Query specified in a query string
   * 
   * @param oql OQL query string to be executed
   * @return query result as a JSON document
   */
@RequestMapping(method = RequestMethod.GET, value = "/adhoc", produces = { MediaType.APPLICATION_JSON_UTF8_VALUE })
@ApiOperation(value = "run an adhoc query", notes = "Run an unnamed (unidentified), ad-hoc query passed as a URL parameter", response = void.class)
@ApiResponses({ @ApiResponse(code = 200, message = "OK."), @ApiResponse(code = 401, message = "Invalid Username or Password."), @ApiResponse(code = 403, message = "Insufficient privileges for operation."), @ApiResponse(code = 500, message = "GemFire throws an error or exception") })
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@PreAuthorize("@securityService.authorize('DATA', 'READ')")
public ResponseEntity<String> runAdhocQuery(@RequestParam("q") String oql) {
    logger.debug("Running an adhoc Query ({})...", oql);
    oql = decode(oql);
    final Query query = getQueryService().newQuery(oql);
    // and handle the Exceptions appropriately (500 Server Error)!
    try {
        Object queryResult = query.execute();
        return processQueryResponse(query, null, queryResult);
    } catch (FunctionDomainException fde) {
        throw new GemfireRestException("A function was applied to a parameter that is improper for that function!", fde);
    } catch (TypeMismatchException tme) {
        throw new GemfireRestException("Bind parameter is not of the expected type!", tme);
    } catch (NameResolutionException nre) {
        throw new GemfireRestException("Name in the query cannot be resolved!", nre);
    } catch (IllegalArgumentException iae) {
        throw new GemfireRestException(" The number of bound parameters does not match the number of placeholders!", iae);
    } catch (IllegalStateException ise) {
        throw new GemfireRestException("Query is not permitted on this type of region!", ise);
    } catch (QueryExecutionTimeoutException qete) {
        throw new GemfireRestException("Query execution time is exceeded max query execution time (gemfire.Cache.MAX_QUERY_EXECUTION_TIME) configured! ", qete);
    } catch (QueryInvocationTargetException qite) {
        throw new GemfireRestException("Data referenced in from clause is not available for querying!", qite);
    } catch (QueryExecutionLowMemoryException qelme) {
        throw new GemfireRestException("Query execution gets canceled due to low memory conditions and the resource manager critical heap percentage has been set!", qelme);
    } catch (Exception e) {
        throw new GemfireRestException("Server has encountered while executing Adhoc query!", e);
    }
}
Also used : GemfireRestException(org.apache.geode.rest.internal.web.exception.GemfireRestException) Query(org.apache.geode.cache.query.Query) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) QueryExecutionLowMemoryException(org.apache.geode.cache.query.QueryExecutionLowMemoryException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) ResourceNotFoundException(org.apache.geode.rest.internal.web.exception.ResourceNotFoundException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) QueryExecutionLowMemoryException(org.apache.geode.cache.query.QueryExecutionLowMemoryException) GemfireRestException(org.apache.geode.rest.internal.web.exception.GemfireRestException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

QueryExecutionLowMemoryException (org.apache.geode.cache.query.QueryExecutionLowMemoryException)7 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)4 QueryInvalidException (org.apache.geode.cache.query.QueryInvalidException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 FunctionDomainException (org.apache.geode.cache.query.FunctionDomainException)2 NameResolutionException (org.apache.geode.cache.query.NameResolutionException)2 Query (org.apache.geode.cache.query.Query)2 QueryExecutionTimeoutException (org.apache.geode.cache.query.QueryExecutionTimeoutException)2 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)2 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)2 GemfireRestException (org.apache.geode.rest.internal.web.exception.GemfireRestException)2 ResourceNotFoundException (org.apache.geode.rest.internal.web.exception.ResourceNotFoundException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1