Search in sources :

Example 21 with ReplyException

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

the class GrantorRequestProcessor method basicOp.

private static GrantorInfo basicOp(long grantorVersion, String serviceName, DLockService service, int dlsSerialNumber, InternalDistributedSystem system, InternalDistributedMember oldTurk, byte opCode) {
    GrantorInfo result = null;
    DM dm = system.getDistributionManager();
    GrantorRequestContext grc = system.getGrantorRequestContext();
    boolean tryNewElder;
    boolean interrupted = false;
    try {
        do {
            tryNewElder = false;
            final boolean usesElderCollaborationLock = opCode == GET_OP || opCode == BECOME_OP;
            if (usesElderCollaborationLock) {
                Assert.assertTrue(service != null, "Attempting GrantorRequest without instance of DistributedLockService");
            }
            final ElderState es = startElderCall(system, service, usesElderCollaborationLock);
            dm.throwIfDistributionStopped();
            try {
                if (es != null) {
                    // local elder so do it without messaging
                    switch(opCode) {
                        case GET_OP:
                            result = es.getGrantor(serviceName, dm.getId(), dlsSerialNumber);
                            break;
                        case PEEK_OP:
                            result = es.peekGrantor(serviceName);
                            break;
                        case BECOME_OP:
                            result = es.becomeGrantor(serviceName, dm.getId(), dlsSerialNumber, oldTurk);
                            break;
                        case CLEAR_OP:
                            es.clearGrantor(grantorVersion, serviceName, dlsSerialNumber, dm.getId(), false);
                            result = CLEAR_COMPLETE;
                            break;
                        case CLEAR_WITH_LOCKS_OP:
                            es.clearGrantor(grantorVersion, serviceName, dlsSerialNumber, dm.getId(), true);
                            result = CLEAR_COMPLETE;
                            break;
                        default:
                            throw new IllegalStateException("Unknown opCode " + opCode);
                    }
                } else {
                    // remote elder so send message
                    GrantorRequestProcessor processor = new GrantorRequestProcessor(system, grc.currentElder);
                    boolean sent = GrantorRequestMessage.send(grantorVersion, dlsSerialNumber, serviceName, grc.currentElder, dm, processor, oldTurk, opCode);
                    if (!sent) {
                        if (logger.isTraceEnabled(LogMarker.DLS)) {
                            logger.trace(LogMarker.DLS, "Unable to communicate with elder {}", grc.currentElder);
                        }
                    }
                    try {
                        processor.waitForRepliesUninterruptibly();
                    } catch (ReplyException e) {
                        e.handleAsUnexpected();
                    }
                    if (processor.result != null) {
                        result = processor.result;
                    } else {
                        // sleep if targeted elder still in view but not activeMembers
                        if (!dm.getDistributionManagerIds().contains(grc.currentElder) && dm.getViewMembers().contains(grc.currentElder)) {
                            // elder probably sent shutdown msg but may not yet left View
                            try {
                                Thread.sleep(ELDER_CHANGE_SLEEP);
                            } catch (InterruptedException e) {
                                interrupted = true;
                                dm.getCancelCriterion().checkCancelInProgress(e);
                            }
                        }
                        // targetted elder either died or already sent us a shutdown msg
                        if (opCode != CLEAR_OP && opCode != CLEAR_WITH_LOCKS_OP) {
                            // Note we do not try a new elder if doing a clear because
                            // the new elder will not have anything for us to clear.
                            // He will have done an ElderInit.
                            tryNewElder = true;
                        }
                    }
                }
            } finally {
                finishElderCall(grc, es);
            }
        } while (tryNewElder);
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }
    return result;
}
Also used : DM(org.apache.geode.distributed.internal.DM) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 22 with ReplyException

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

the class CreateRegionProcessor method initializeRegion.

/** this method tells other members that the region is being created */
public void initializeRegion() {
    InternalDistributedSystem system = this.newRegion.getSystem();
    // try 5 times, see CreateRegionMessage#skipDuringInitialization
    for (int retry = 0; retry < 5; retry++) {
        Set recps = getRecipients();
        if (logger.isDebugEnabled()) {
            logger.debug("Creating region {}", this.newRegion);
        }
        if (recps.isEmpty()) {
            if (logger.isDebugEnabled()) {
                logger.debug("CreateRegionProcessor.initializeRegion, no recipients, msg not sent");
            }
            this.newRegion.getDistributionAdvisor().setInitialized();
            EventTracker tracker = ((LocalRegion) this.newRegion).getEventTracker();
            if (tracker != null) {
                tracker.setInitialized();
            }
            return;
        }
        CreateRegionReplyProcessor replyProc = new CreateRegionReplyProcessor(recps);
        newRegion.registerCreateRegionReplyProcessor(replyProc);
        // multicast is disabled for this message for now
        boolean useMcast = false;
        CreateRegionMessage msg = getCreateRegionMessage(recps, replyProc, useMcast);
        // severe alert processing if we're creating one of them
        if (((LocalRegion) newRegion).isUsedForPartitionedRegionBucket()) {
            replyProc.enableSevereAlertProcessing();
            msg.severeAlertCompatible = true;
        }
        this.newRegion.getDistributionManager().putOutgoing(msg);
        // Reply procs are deregistered when they return from waitForReplies
        try {
            // Don't allow a region to be created if the distributed system is
            // disconnecting
            this.newRegion.getCache().getCancelCriterion().checkCancelInProgress(null);
            // // Similarly, don't allow new regions to be created if the cache is closing
            try {
                replyProc.waitForRepliesUninterruptibly();
                if (!replyProc.needRetry()) {
                    break;
                }
            } catch (ReplyException e) {
                Throwable t = e.getCause();
                if (t instanceof IllegalStateException) {
                    // region is incompatible with region in another cache
                    throw (IllegalStateException) t;
                }
                e.handleAsUnexpected();
                break;
            }
        } finally {
            replyProc.cleanup();
            EventTracker tracker = ((LocalRegion) this.newRegion).getEventTracker();
            if (tracker != null) {
                tracker.setInitialized();
            }
            if (((LocalRegion) this.newRegion).isUsedForPartitionedRegionBucket()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("initialized bucket event tracker: {}", tracker);
                }
            }
        }
    }
    // while
    // tell advisor that it has been initialized since a profile exchange occurred
    this.newRegion.getDistributionAdvisor().setInitialized();
}
Also used : Set(java.util.Set) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 23 with ReplyException

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

the class MemberFunctionStreamingMessage method process.

@Override
protected void process(final DistributionManager dm) {
    Throwable thr = null;
    ReplyException rex = null;
    if (this.functionObject == null) {
        rex = new ReplyException(new FunctionException(LocalizedStrings.ExecuteFunction_FUNCTION_NAMED_0_IS_NOT_REGISTERED.toLocalizedString(this.functionName)));
        replyWithException(dm, rex);
        return;
    }
    FunctionStats stats = FunctionStats.getFunctionStats(this.functionObject.getId(), dm.getSystem());
    TXStateProxy tx = null;
    try {
        tx = prepForTransaction();
        ResultSender resultSender = new MemberFunctionResultSender(dm, this, this.functionObject);
        Set<Region> regions = new HashSet<Region>();
        if (this.regionPathSet != null) {
            InternalCache cache = GemFireCacheImpl.getInstance();
            for (String regionPath : this.regionPathSet) {
                if (checkCacheClosing(dm) || checkDSClosing(dm)) {
                    thr = new CacheClosedException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString(dm.getId()));
                    return;
                }
                regions.add(cache.getRegion(regionPath));
            }
        }
        FunctionContextImpl context = new MultiRegionFunctionContextImpl(this.functionObject.getId(), this.args, resultSender, regions, isReExecute);
        long start = stats.startTime();
        stats.startFunctionExecution(this.functionObject.hasResult());
        if (logger.isDebugEnabled()) {
            logger.debug("Executing Function: {} on remote member with context: {}", this.functionObject.getId(), context.toString());
        }
        this.functionObject.execute(context);
        if (!this.replyLastMsg && this.functionObject.hasResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(functionObject.getId()));
        }
        stats.endFunctionExecution(start, this.functionObject.hasResult());
    } catch (FunctionException functionException) {
        if (logger.isDebugEnabled()) {
            logger.debug("FunctionException occurred on remote member while executing Function: {}", this.functionObject.getId(), functionException);
        }
        stats.endFunctionExecutionWithException(this.functionObject.hasResult());
        rex = new ReplyException(functionException);
        replyWithException(dm, rex);
    // thr = functionException.getCause();
    } catch (CancelException exception) {
        // bug 37026: this is too noisy...
        // throw new CacheClosedException("remote system shutting down");
        // thr = se; cache is closed, no point trying to send a reply
        thr = new FunctionInvocationTargetException(exception);
        stats.endFunctionExecutionWithException(this.functionObject.hasResult());
        rex = new ReplyException(thr);
        replyWithException(dm, rex);
    } catch (Exception exception) {
        if (logger.isDebugEnabled()) {
            logger.debug("Exception occurred on remote member while executing Function: {}", this.functionObject.getId(), exception);
        }
        stats.endFunctionExecutionWithException(this.functionObject.hasResult());
        rex = new ReplyException(exception);
        replyWithException(dm, rex);
    // thr = e.getCause();
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // 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();
        thr = t;
    } finally {
        cleanupTransaction(tx);
        if (thr != null) {
            rex = new ReplyException(thr);
            replyWithException(dm, rex);
        }
    }
}
Also used : FunctionContextImpl(org.apache.geode.internal.cache.execute.FunctionContextImpl) MultiRegionFunctionContextImpl(org.apache.geode.internal.cache.execute.MultiRegionFunctionContextImpl) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) MemberFunctionResultSender(org.apache.geode.internal.cache.execute.MemberFunctionResultSender) ResultSender(org.apache.geode.cache.execute.ResultSender) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) QueryException(org.apache.geode.cache.query.QueryException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionStats(org.apache.geode.internal.cache.execute.FunctionStats) MemberFunctionResultSender(org.apache.geode.internal.cache.execute.MemberFunctionResultSender) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) MultiRegionFunctionContextImpl(org.apache.geode.internal.cache.execute.MultiRegionFunctionContextImpl) HashSet(java.util.HashSet)

Example 24 with ReplyException

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

the class RemoteInvalidateMessage method operateOnRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   * 
   * @throws EntryExistsException
   */
@Override
protected boolean operateOnRegion(DistributionManager dm, LocalRegion r, long startTime) throws EntryExistsException, RemoteOperationException {
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    final Object key = getKey();
    @Released final EntryEventImpl event = EntryEventImpl.create(r, getOperation(), key, null, /* newValue */
    getCallbackArg(), this.useOriginRemote, /* originRemote - false to force distribution in buckets */
    eventSender, true, /* generateCallbacks */
    false);
    try {
        if (this.bridgeContext != null) {
            event.setContext(this.bridgeContext);
        }
        event.setCausedByMessage(this);
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            event.setVersionTag(this.versionTag);
        }
        Assert.assertTrue(eventId != null);
        event.setEventId(eventId);
        event.setPossibleDuplicate(this.possibleDuplicate);
        // for cqs, which needs old value based on old value being sent on wire.
        boolean eventShouldHaveOldValue = getHasOldValue();
        if (eventShouldHaveOldValue) {
            if (getOldValueIsSerialized()) {
                event.setSerializedOldValue(getOldValueBytes());
            } else {
                event.setOldValue(getOldValueBytes());
            }
        }
        boolean sendReply = true;
        try {
            r.checkReadiness();
            r.checkForLimitedOrNoAccess();
            r.basicInvalidate(event);
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "remoteInvalidated key: {}", key);
            }
            sendReply(getSender(), this.processorId, dm, /* ex */
            null, event.getRegion(), event.getVersionTag(), startTime);
            sendReply = false;
        } catch (EntryNotFoundException eee) {
            // failed = true;
            if (logger.isDebugEnabled()) {
                logger.debug("operateOnRegion caught EntryNotFoundException");
            }
            sendReply(getSender(), getProcessorId(), dm, new ReplyException(eee), r, null, startTime);
            // this prevents us from acking later
            sendReply = false;
        } catch (PrimaryBucketException pbe) {
            sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
            return false;
        }
        return sendReply;
    } finally {
        event.release();
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 25 with ReplyException

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

the class RemoteOperationMessage method process.

/**
   * Upon receipt of the message, both process the message and send an acknowledgement, not
   * necessarily in that order. Note: Any hang in this message may cause a distributed deadlock for
   * those threads waiting for an acknowledgement.
   * 
   * @throws PartitionedRegionException if the region does not exist (typically, if it has been
   *         destroyed)
   */
@Override
public void process(final DistributionManager dm) {
    Throwable thr = null;
    boolean sendReply = true;
    LocalRegion r = null;
    long startTime = 0;
    try {
        if (checkCacheClosing(dm) || checkDSClosing(dm)) {
            thr = new CacheClosedException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString(dm.getId()));
            return;
        }
        InternalCache cache = getCache(dm);
        r = getRegionByPath(cache);
        if (r == null && failIfRegionMissing()) {
            // if the distributed system is disconnecting, don't send a reply saying
            // the partitioned region can't be found (bug 36585)
            thr = new RegionDestroyedException(LocalizedStrings.RemoteOperationMessage_0_COULD_NOT_FIND_REGION_1.toLocalizedString(dm.getDistributionManagerId(), regionPath), regionPath);
            // reply sent in finally block below
            return;
        }
        thr = UNHANDLED_EXCEPTION;
        // [bruce] r might be null here, so we have to go to the cache instance to get the txmgr
        TXManagerImpl txMgr = getTXManager(cache);
        TXStateProxy tx = txMgr.masqueradeAs(this);
        if (tx == null) {
            sendReply = operateOnRegion(dm, r, startTime);
        } else {
            try {
                if (txMgr.isClosed()) {
                    // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
                    sendReply = false;
                } else if (tx.isInProgress()) {
                    sendReply = operateOnRegion(dm, r, startTime);
                    tx.updateProxyServer(this.getSender());
                }
            } finally {
                txMgr.unmasquerade(tx);
            }
        }
        thr = null;
    } catch (RemoteOperationException fre) {
        thr = fre;
    } catch (DistributedSystemDisconnectedException se) {
        // bug 37026: this is too noisy...
        // throw new CacheClosedException("remote system shutting down");
        // thr = se; cache is closed, no point trying to send a reply
        thr = null;
        sendReply = false;
        if (logger.isDebugEnabled()) {
            logger.debug("shutdown caught, abandoning message: {}", se.getMessage(), se);
        }
    } catch (RegionDestroyedException rde) {
        // [bruce] RDE does not always mean that the sender's region is also
        // destroyed, so we must send back an exception. If the sender's
        // region is also destroyed, who cares if we send it an exception
        // if (pr != null && pr.isClosed) {
        thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_REGION_IS_DESTROYED_IN_0.toLocalizedString(dm.getDistributionManagerId()), rde);
    // }
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // 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();
        // log the exception at fine level if there is no reply to the message
        thr = null;
        if (sendReply) {
            if (!checkDSClosing(dm)) {
                thr = t;
            } else {
                // don't pass arbitrary runtime exceptions and errors back if this
                // cache/vm is closing
                thr = new ForceReattemptException(LocalizedStrings.PartitionMessage_DISTRIBUTED_SYSTEM_IS_DISCONNECTING.toLocalizedString());
            }
        }
        if (logger.isTraceEnabled(LogMarker.DM) && (t instanceof RuntimeException)) {
            logger.trace(LogMarker.DM, "Exception caught while processing message", t);
        }
    } finally {
        if (sendReply) {
            ReplyException rex = null;
            if (thr != null) {
                // don't transmit the exception if this message was to a listener
                // and this listener is shutting down
                rex = new ReplyException(thr);
            }
            // Send the reply if the operateOnPartitionedRegion returned true
            sendReply(getSender(), this.processorId, dm, rex, r, startTime);
        }
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) 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