Search in sources :

Example 41 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class TXRecoverGrantorMessageProcessor method processDLockRecoverGrantorMessage.

protected void processDLockRecoverGrantorMessage(final DM dm, final DLockRecoverGrantorProcessor.DLockRecoverGrantorMessage msg) {
    ReplyException replyException = null;
    int replyCode = DLockRecoverGrantorProcessor.DLockRecoverGrantorReplyMessage.OK;
    DLockRemoteToken[] heldLocks = new DLockRemoteToken[0];
    if (logger.isDebugEnabled()) {
        logger.debug("[TXRecoverGrantorMessageProcessor.process]");
    }
    boolean gotRecoveryLock = false;
    TXLockServiceImpl dtls = null;
    try {
        Assert.assertTrue(msg.getServiceName().startsWith(DLockService.DTLS), "TXRecoverGrantorMessageProcessor cannot handle service " + msg.getServiceName());
        // get the service from the name
        DLockService svc = DLockService.getInternalServiceNamed(msg.getServiceName());
        if (svc != null) {
            dtls = (TXLockServiceImpl) TXLockService.getDTLS();
            if (dtls != null) {
                // use TXLockServiceImpl recoveryLock to delay reply...
                dtls.acquireRecoveryWriteLock();
                gotRecoveryLock = true;
                // Wait for all the received transactions to finish processing
                TXCommitMessage.getTracker().waitForAllToProcess();
            }
        }
    } catch (InterruptedException t) {
        Thread.currentThread().interrupt();
        logger.warn(LocalizedMessage.create(LocalizedStrings.TXRecoverGrantorMessageProcessor_TXRECOVERGRANTORMESSAGEPROCESSORPROCESS_THROWABLE), t);
        replyException = new ReplyException(t);
    } catch (RuntimeException t) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.TXRecoverGrantorMessageProcessor_TXRECOVERGRANTORMESSAGEPROCESSORPROCESS_THROWABLE), t);
        if (replyException == null) {
            replyException = new ReplyException(t);
        } else {
            logger.warn(LocalizedMessage.create(LocalizedStrings.TXRecoverGrantorMessageProcessor_MORE_THAN_ONE_EXCEPTION_THROWN_IN__0, this), t);
        }
    } finally // catch (VirtualMachineError err) {
    // SystemFailure.initiateFailure(err);
    // // If this ever returns, rethrow the error. We're poisoned
    // // now, so don't let this thread continue.
    // throw err;
    // }
    // catch (Throwable t) {
    // // Whenever you catch Error or Throwable, you must also
    // // catch VirtualMachineError (see above). However, there is
    // // _still_ a possibility that you are dealing with a cascading
    // // error condition, so you also need to check to see if the JVM
    // // is still usable:
    // SystemFailure.checkFailure();
    // if (replyException == null) {
    // replyException = new ReplyException(t);
    // }
    // }
    {
        if (gotRecoveryLock && dtls != null) {
            dtls.releaseRecoveryWriteLock();
        }
        DLockRecoverGrantorProcessor.DLockRecoverGrantorReplyMessage replyMsg = new DLockRecoverGrantorProcessor.DLockRecoverGrantorReplyMessage();
        replyMsg.setReplyCode(replyCode);
        replyMsg.setHeldLocks(heldLocks);
        replyMsg.setProcessorId(msg.getProcessorId());
        replyMsg.setRecipient(msg.getSender());
        replyMsg.setException(replyException);
        if (msg.getSender().equals(dm.getId())) {
            // process in-line in this VM
            if (logger.isDebugEnabled()) {
                logger.debug("[TXRecoverGrantorMessageProcessor.process] locally process reply");
            }
            replyMsg.setSender(dm.getId());
            replyMsg.dmProcess((DistributionManager) dm);
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("[TXRecoverGrantorMessageProcessor.process] send reply");
            }
            dm.putOutgoing(replyMsg);
        }
    }
}
Also used : DLockRecoverGrantorProcessor(org.apache.geode.distributed.internal.locks.DLockRecoverGrantorProcessor) DLockService(org.apache.geode.distributed.internal.locks.DLockService) ReplyException(org.apache.geode.distributed.internal.ReplyException) DLockRemoteToken(org.apache.geode.distributed.internal.locks.DLockRemoteToken)

Example 42 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException 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 43 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException 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 44 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class FunctionStreamingResultCollector method stillWaitingFromNodes.

protected boolean stillWaitingFromNodes() {
    if (shutdown) {
        // Create the exception here, so that the call stack reflects the
        // failed computation. If you set the exception in onShutdown,
        // the resulting stack is not of interest.
        ReplyException re = new ReplyException(new DistributedSystemDisconnectedException(LocalizedStrings.ReplyProcessor21_ABORTED_DUE_TO_SHUTDOWN.toLocalizedString()));
        this.exception = re;
        return false;
    }
    // return (numMembers()-this.numMemberDeparted) > 0;
    return numMembers() > 0;
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 45 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException 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)

Aggregations

ReplyException (org.apache.geode.distributed.internal.ReplyException)75 CancelException (org.apache.geode.CancelException)24 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)20 Set (java.util.Set)16 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)16 HashSet (java.util.HashSet)12 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)10 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 IOException (java.io.IOException)7 CacheClosedException (org.apache.geode.cache.CacheClosedException)7 ReplyMessage (org.apache.geode.distributed.internal.ReplyMessage)7 Cache (org.apache.geode.cache.Cache)6 CacheException (org.apache.geode.cache.CacheException)6 Region (org.apache.geode.cache.Region)6 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)6 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)6 Released (org.apache.geode.internal.offheap.annotations.Released)6 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)5 ReplyProcessor21 (org.apache.geode.distributed.internal.ReplyProcessor21)5