Search in sources :

Example 1 with QueryMonitor

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

the class GemFireCacheImpl method getQueryMonitor.

/**
   * Returns the QueryMonitor instance based on system property MAX_QUERY_EXECUTION_TIME.
   * 
   * @since GemFire 6.0
   */
@Override
public QueryMonitor getQueryMonitor() {
    // Check to see if monitor is required if ResourceManager critical heap percentage is set
    // or whether we override it with the system variable;
    boolean monitorRequired = !this.queryMonitorDisabledForLowMem && queryMonitorRequiredForResourceManager;
    // Added for DUnit test purpose, which turns-on and off the this.testMaxQueryExecutionTime.
    if (!(MAX_QUERY_EXECUTION_TIME > 0 || this.testMaxQueryExecutionTime > 0 || monitorRequired)) {
        // Else send null, so that the QueryMonitor is turned-off.
        return null;
    }
    // Return the QueryMonitor service if MAX_QUERY_EXECUTION_TIME is set or it is required by the
    // ResourceManager and not overridden by system property.
    boolean needQueryMonitor = MAX_QUERY_EXECUTION_TIME > 0 || this.testMaxQueryExecutionTime > 0 || monitorRequired;
    if (needQueryMonitor && this.queryMonitor == null) {
        synchronized (this.queryMonitorLock) {
            if (this.queryMonitor == null) {
                int maxTime = MAX_QUERY_EXECUTION_TIME > this.testMaxQueryExecutionTime ? MAX_QUERY_EXECUTION_TIME : this.testMaxQueryExecutionTime;
                if (monitorRequired && maxTime < 0) {
                    // this means that the resource manager is being used and we need to monitor query
                    // memory usage
                    // If no max execution time has been set, then we will default to five hours
                    maxTime = FIVE_HOURS;
                }
                this.queryMonitor = new QueryMonitor(maxTime);
                final LoggingThreadGroup group = LoggingThreadGroup.createThreadGroup("QueryMonitor Thread Group", logger);
                Thread qmThread = new Thread(group, this.queryMonitor, "QueryMonitor Thread");
                qmThread.setDaemon(true);
                qmThread.start();
                if (logger.isDebugEnabled()) {
                    logger.debug("QueryMonitor thread started.");
                }
            }
        }
    }
    return this.queryMonitor;
}
Also used : QueryMonitor(org.apache.geode.cache.query.internal.QueryMonitor) LoggingThreadGroup(org.apache.geode.internal.logging.LoggingThreadGroup) SimpleExtensionPoint(org.apache.geode.internal.cache.extension.SimpleExtensionPoint) ExtensionPoint(org.apache.geode.internal.cache.extension.ExtensionPoint)

Example 2 with QueryMonitor

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

the class QueryMonitorDUnitTest method validateQueryMonitorThreadCnt.

private void validateQueryMonitorThreadCnt(VM vm, final int threadCount, final int waitTime) {
    SerializableRunnable validateThreadCnt = new CacheSerializableRunnable("validateQueryMonitorThreadCnt") {

        public void run2() throws CacheException {
            Cache cache = getCache();
            QueryMonitor qm = ((GemFireCacheImpl) cache).getQueryMonitor();
            if (qm == null) {
                fail("Didn't found query monitor.");
            }
            int waited = 0;
            while (true) {
                if (qm.getQueryMonitorThreadCount() != threadCount) {
                    if (waited <= waitTime) {
                        Wait.pause(10);
                        waited += 10;
                        continue;
                    } else {
                        fail("Didn't found expected monitoring thread. Expected: " + threadCount + " found :" + qm.getQueryMonitorThreadCount());
                    }
                }
                break;
            }
        // ((GemFireCache)cache).testMaxQueryExecutionTime = queryMonitorTime;
        }
    };
    vm.invoke(validateThreadCnt);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryMonitor(org.apache.geode.cache.query.internal.QueryMonitor) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache)

Example 3 with QueryMonitor

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

Aggregations

QueryMonitor (org.apache.geode.cache.query.internal.QueryMonitor)3 Cache (org.apache.geode.cache.Cache)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 ClientCache (org.apache.geode.cache.client.ClientCache)1 QueryException (org.apache.geode.cache.query.QueryException)1 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)1 SelectResults (org.apache.geode.cache.query.SelectResults)1 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)1 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)1 BucketMovedException (org.apache.geode.internal.cache.execute.BucketMovedException)1 ExtensionPoint (org.apache.geode.internal.cache.extension.ExtensionPoint)1 SimpleExtensionPoint (org.apache.geode.internal.cache.extension.SimpleExtensionPoint)1 LoggingThreadGroup (org.apache.geode.internal.logging.LoggingThreadGroup)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1