Search in sources :

Example 31 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class MemberFunctionResultSender method lastResult.

public void lastResult(Object oneResult) {
    if (!this.function.hasResult()) {
        throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
    }
    if (this.serverSender != null) {
        // client-server
        if (this.localLastResultRecieved) {
            return;
        }
        if (onlyLocal) {
            this.serverSender.lastResult(oneResult);
            this.rc.endResults();
            this.localLastResultRecieved = true;
        } else {
            lastResult(oneResult, rc, false, true, this.dm.getId());
        }
    } else {
        // P2P
        if (this.msg != null) {
            try {
                this.msg.sendReplyForOneResult(dm, oneResult, true, enableOrderedResultStreming);
            } catch (QueryException e) {
                throw new FunctionException(e);
            } catch (ForceReattemptException e) {
                throw new FunctionException(e);
            } catch (InterruptedException e) {
                throw new FunctionException(e);
            }
        } else {
            if (this.localLastResultRecieved) {
                return;
            }
            if (onlyLocal) {
                this.rc.addResult(this.dm.getDistributionManagerId(), oneResult);
                this.rc.endResults();
                this.localLastResultRecieved = true;
            } else {
                // call a synchronized method as local node is also waiting to send lastResult
                lastResult(oneResult, rc, false, true, this.dm.getDistributionManagerId());
            }
            FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReceived();
        }
    }
    FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReturned();
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException)

Example 32 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class FunctionStreamingResultCollector method waitForCacheOrFunctionException.

/**
   * Waits for the response from the recipient
   * 
   * @throws CacheException if the recipient threw a cache exception during message processing
   * @throws ForceReattemptException if the recipient left the distributed system before the
   *         response was received.
   * @throws RegionDestroyedException if the peer has closed its copy of the region
   */
public boolean waitForCacheOrFunctionException(long timeout) throws CacheException, ForceReattemptException {
    boolean timedOut = false;
    try {
        if (timeout == 0) {
            waitForRepliesUninterruptibly();
            timedOut = true;
        } else {
            timedOut = waitForRepliesUninterruptibly(timeout);
        }
    } catch (ReplyException e) {
        removeMember(e.getSender(), true);
        Throwable t = e.getCause();
        if (t instanceof CacheException) {
            throw (CacheException) t;
        } else if (t instanceof RegionDestroyedException) {
            throw (RegionDestroyedException) t;
        } else if (t instanceof ForceReattemptException) {
            throw new ForceReattemptException("Peer requests reattempt", t);
        } else if (t instanceof PrimaryBucketException) {
            throw new PrimaryBucketException("Peer failed primary test", t);
        }
        if (t instanceof CancelException) {
            this.execution.failedNodes.add(e.getSender().getId());
            String msg = "PartitionResponse got remote CacheClosedException, throwing PartitionedRegionCommunicationException";
            logger.debug("{}, throwing ForceReattemptException", msg, t);
            throw (CancelException) t;
        }
        if (e.getCause() instanceof FunctionException) {
            throw (FunctionException) e.getCause();
        }
        e.handleAsUnexpected();
    }
    return timedOut;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) CacheException(org.apache.geode.cache.CacheException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) FunctionException(org.apache.geode.cache.execute.FunctionException) CancelException(org.apache.geode.CancelException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 33 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class FunctionStreamingResultCollector method getResult.

public Object getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
    long timeoutInMillis = unit.toMillis(timeout);
    if (this.resultCollected) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
    }
    this.resultCollected = true;
    // Should convert it from unit to milliseconds
    if (this.userRC != null) {
        try {
            long timeBefore = System.currentTimeMillis();
            boolean isNotTimedOut;
            if (execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) {
                isNotTimedOut = this.waitForCacheOrFunctionException(timeoutInMillis);
            } else {
                isNotTimedOut = this.waitForRepliesUninterruptibly(timeoutInMillis);
            }
            if (!isNotTimedOut) {
                throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_NOT_COLLECTED_IN_TIME_PROVIDED.toLocalizedString());
            }
            long timeAfter = System.currentTimeMillis();
            timeoutInMillis = timeoutInMillis - (timeAfter - timeBefore);
            if (timeoutInMillis < 0)
                timeoutInMillis = 0;
            if (this.removedNodes != null) {
                if (this.removedNodes.size() != 0) {
                    // end the rc and clear it
                    clearResults();
                    this.execution = this.execution.setIsReExecute();
                    ResultCollector newRc = null;
                    if (execution.isFnSerializationReqd()) {
                        newRc = this.execution.execute(fn);
                    } else {
                        newRc = this.execution.execute(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) {
            // function.
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage());
                throw new FunctionException(iFITE);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
        } catch (CacheClosedException e) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
        }// }
         catch (ForceReattemptException e) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
        } catch (ReplyException e) {
            if (!(execution.waitOnException || execution.forwardExceptions)) {
                throw new FunctionException(e.getCause());
            }
        }
        return this.userRC.getResult(timeoutInMillis, unit);
    }
    return null;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 34 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class FunctionStreamingResultCollector method getResult.

public Object getResult() throws FunctionException {
    if (this.resultCollected) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
    }
    this.resultCollected = true;
    if (this.userRC != null) {
        try {
            if (execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) {
                this.waitForCacheOrFunctionException(0);
            } else {
                waitForRepliesUninterruptibly(0);
            }
            if (this.removedNodes != null) {
                if (this.removedNodes.size() != 0) {
                    // end the rc and clear it
                    clearResults();
                    this.execution = this.execution.setIsReExecute();
                    ResultCollector newRc = null;
                    if (execution.isFnSerializationReqd()) {
                        newRc = this.execution.execute(fn);
                    } else {
                        newRc = this.execution.execute(fn.getId());
                    }
                    return newRc.getResult();
                }
            }
            if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
                throw new FunctionException(this.fites.get(0));
            }
        } catch (FunctionInvocationTargetException fite) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage());
                throw new FunctionException(iFITE);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult();
            }
        } catch (CacheClosedException e) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult();
            }
        }// }
         catch (ForceReattemptException e) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult();
            }
        } catch (ReplyException e) {
            if (!(execution.waitOnException || execution.forwardExceptions)) {
                throw new FunctionException(e.getCause());
            }
        }
        return this.userRC.getResult();
    }
    return null;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 35 with ForceReattemptException

use of org.apache.geode.internal.cache.ForceReattemptException in project geode by apache.

the class DistributedRegionFunctionResultSender method lastResult.

public void lastResult(Object oneResult) {
    if (!this.functionObject.hasResult()) {
        throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
    }
    if (this.localLastResultRecieved) {
        return;
    }
    this.localLastResultRecieved = true;
    if (this.sender != null) {
        // Client-Server
        sender.lastResult(oneResult);
        if (this.rc != null) {
            this.rc.endResults();
        }
    } else {
        if (isLocal) {
            this.rc.addResult(dm.getDistributionManagerId(), oneResult);
            this.rc.endResults();
            FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReceived();
        } else {
            try {
                this.msg.sendReplyForOneResult(dm, oneResult, true, enableOrderedResultStreming);
            } catch (ForceReattemptException e) {
                throw new FunctionException(e);
            } catch (InterruptedException e) {
                throw new FunctionException(e);
            }
        }
        // incrementing result sent stats.
        FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReturned();
    }
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException)

Aggregations

ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)62 Set (java.util.Set)21 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)13 FunctionException (org.apache.geode.cache.execute.FunctionException)12 ReplyException (org.apache.geode.distributed.internal.ReplyException)11 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)11 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)9 TransactionException (org.apache.geode.cache.TransactionException)8 HashSet (java.util.HashSet)7 CacheException (org.apache.geode.cache.CacheException)7 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)7 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)5 TransactionDataNodeHasDepartedException (org.apache.geode.cache.TransactionDataNodeHasDepartedException)5 Host (org.apache.geode.test.dunit.Host)5 VM (org.apache.geode.test.dunit.VM)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Test (org.junit.Test)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4