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;
}
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);
}
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);
}
}
}
Aggregations