use of org.apache.geode.internal.cache.execute.BucketMovedException 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);
}
}
}
use of org.apache.geode.internal.cache.execute.BucketMovedException in project geode by apache.
the class PartitionedRegionDataStore method executeOnDataStore.
public void executeOnDataStore(final Set localKeys, final Function function, final Object object, final int prid, final Set<Integer> bucketSet, final boolean isReExecute, final PartitionedRegionFunctionStreamingMessage msg, long time, ServerConnection servConn, int transactionID) {
if (!areAllBucketsHosted(bucketSet)) {
throw new BucketMovedException(LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE.toLocalizedString());
}
final DM dm = this.partitionedRegion.getDistributionManager();
ResultSender resultSender = new PartitionedRegionFunctionResultSender(dm, this.partitionedRegion, time, msg, function, bucketSet);
final RegionFunctionContextImpl prContext = new RegionFunctionContextImpl(function.getId(), this.partitionedRegion, object, localKeys, ColocationHelper.constructAndGetAllColocatedLocalDataSet(this.partitionedRegion, bucketSet), bucketSet, resultSender, isReExecute);
FunctionStats stats = FunctionStats.getFunctionStats(function.getId(), dm.getSystem());
try {
long start = stats.startTime();
stats.startFunctionExecution(function.hasResult());
if (logger.isDebugEnabled()) {
logger.debug("Executing Function: {} on Remote Node with context: ", function.getId(), prContext);
}
function.execute(prContext);
stats.endFunctionExecution(start, function.hasResult());
} catch (FunctionException functionException) {
if (logger.isDebugEnabled()) {
logger.debug("FunctionException occurred on remote node while executing Function: {}", function.getId(), functionException);
}
stats.endFunctionExecutionWithException(function.hasResult());
if (functionException.getCause() instanceof QueryInvalidException) {
// create a new FunctionException on the original one's message (not cause).
throw new FunctionException(functionException.getLocalizedMessage());
}
throw functionException;
}
}
use of org.apache.geode.internal.cache.execute.BucketMovedException in project geode by apache.
the class PRFunctionStreamingResultCollector method getResult.
@Override
public Object getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
long timeoutInMillis = unit.toMillis(timeout);
if (this.resultCollected) {
throw new FunctionException("Result already collected");
}
this.resultCollected = true;
if (this.hasResult) {
try {
long timeBefore = System.currentTimeMillis();
if (!this.waitForCacheOrFunctionException(timeoutInMillis)) {
throw new FunctionException("All results not recieved in time provided.");
}
long timeAfter = System.currentTimeMillis();
timeoutInMillis = timeoutInMillis - (timeAfter - timeBefore);
if (timeoutInMillis < 0) {
timeoutInMillis = 0;
}
if (!this.execution.getFailedNodes().isEmpty() && !this.execution.isClientServerMode()) {
// end the rc and clear it
endResults();
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
throw new FunctionException(this.fites.get(0));
}
} catch (FunctionInvocationTargetException fite) {
if (!this.fn.isHA()) {
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException fe = new InternalFunctionInvocationTargetException(fite.getMessage(), this.execution.getFailedNodes());
throw new FunctionException(fe);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
} catch (BucketMovedException e) {
if (!this.fn.isHA()) {
// endResults();
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
// endResults();
clearResults();
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else {
// endResults();
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
} catch (CacheClosedException e) {
if (!this.fn.isHA()) {
// endResults();
FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
throw new FunctionException(fite);
} else if (execution.isClientServerMode()) {
// endResults();
clearResults();
FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
throw new FunctionException(fite);
} else {
// endResults();
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult(timeoutInMillis, unit);
}
} catch (CacheException e) {
// endResults();
throw new FunctionException(e);
} catch (ForceReattemptException e) {
// the function.
if (!this.fn.isHA()) {
throw new FunctionException(e);
} else if (execution.isClientServerMode()) {
clearResults();
FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(e.getMessage(), this.execution.getFailedNodes());
throw new FunctionException(iFITE);
} else {
clearResults();
this.execution = this.execution.setIsReExecute();
ResultCollector newRc = null;
if (execution.isFnSerializationReqd()) {
newRc = this.execution.execute(this.fn);
} else {
newRc = this.execution.execute(this.fn.getId());
}
return newRc.getResult();
}
}
}
// As we have already waited for timeout
return this.userRC.getResult(timeoutInMillis, unit);
// earlier we expect results to be ready
}
Aggregations