Search in sources :

Example 6 with BucketMovedException

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

Example 7 with BucketMovedException

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;
    }
}
Also used : RegionFunctionContextImpl(org.apache.geode.internal.cache.execute.RegionFunctionContextImpl) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) FunctionException(org.apache.geode.cache.execute.FunctionException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) DM(org.apache.geode.distributed.internal.DM) FunctionStats(org.apache.geode.internal.cache.execute.FunctionStats) PartitionedRegionFunctionResultSender(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultSender) ResultSender(org.apache.geode.cache.execute.ResultSender) PartitionedRegionFunctionResultSender(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionResultSender)

Example 8 with BucketMovedException

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
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) CacheException(org.apache.geode.cache.CacheException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) InternalFunctionException(org.apache.geode.internal.cache.execute.InternalFunctionException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) FunctionStreamingResultCollector(org.apache.geode.internal.cache.execute.FunctionStreamingResultCollector) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Aggregations

BucketMovedException (org.apache.geode.internal.cache.execute.BucketMovedException)8 FunctionException (org.apache.geode.cache.execute.FunctionException)4 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)3 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)3 CacheException (org.apache.geode.cache.CacheException)2 ResultCollector (org.apache.geode.cache.execute.ResultCollector)2 QueryException (org.apache.geode.cache.query.QueryException)2 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)2 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)2 FunctionStreamingResultCollector (org.apache.geode.internal.cache.execute.FunctionStreamingResultCollector)2 InternalFunctionException (org.apache.geode.internal.cache.execute.InternalFunctionException)2 Iterator (java.util.Iterator)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 CancelException (org.apache.geode.CancelException)1 GemFireException (org.apache.geode.GemFireException)1