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);
}
}
}
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();
}
}
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);
}
}
}
use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.
the class RemoteDestroyMessage 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
*/
@Override
protected boolean operateOnRegion(DistributionManager dm, LocalRegion r, long startTime) throws EntryExistsException, RemoteOperationException {
InternalDistributedMember eventSender = originalSender;
if (eventSender == null) {
eventSender = getSender();
}
@Released EntryEventImpl event = null;
try {
if (this.bridgeContext != null) {
event = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
getCallbackArg(), false, /* originRemote */
eventSender, true);
event.setContext(this.bridgeContext);
// for cq processing and client notification by BS.
if (this.hasOldValue) {
if (this.oldValueIsSerialized) {
event.setSerializedOldValue(getOldValueBytes());
} else {
event.setOldValue(getOldValueBytes());
}
}
} else // bridgeContext != null
{
event = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
getCallbackArg(), this.useOriginRemote, eventSender, true, /* generateCallbacks */
false);
}
event.setCausedByMessage(this);
if (this.versionTag != null) {
this.versionTag.replaceNullIDs(getSender());
event.setVersionTag(this.versionTag);
}
// for cq processing and client notification by BS.
if (this.hasOldValue) {
if (this.oldValueIsSerialized) {
event.setSerializedOldValue(getOldValueBytes());
} else {
event.setOldValue(getOldValueBytes());
}
}
Assert.assertTrue(eventId != null);
event.setEventId(eventId);
event.setPossibleDuplicate(this.possibleDuplicate);
try {
r.getDataView().destroyOnRemote(event, true, this.expectedOldValue);
sendReply(dm, event.getVersionTag());
} catch (CacheWriterException cwe) {
sendReply(getSender(), this.processorId, dm, new ReplyException(cwe), r, startTime);
return false;
} catch (EntryNotFoundException eee) {
if (logger.isDebugEnabled()) {
logger.debug("operateOnRegion caught EntryNotFoundException", eee);
}
ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(eee), getReplySender(dm), r.isInternalRegion());
} catch (DataLocationException e) {
if (logger.isDebugEnabled()) {
logger.debug("operateOnRegion caught DataLocationException");
}
ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(e), getReplySender(dm), r.isInternalRegion());
}
return false;
} finally {
if (event != null) {
event.release();
}
}
}
use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.
the class RemotePutMessage method operateOnRegion.
/**
* This method is called upon receipt and make the desired changes to the Replicate Region. Note:
* It is very important that this message does NOT cause any deadlocks as the sender will wait
* indefinitely for the acknowledgement
*/
@Override
protected boolean operateOnRegion(DistributionManager dm, LocalRegion r, long startTime) throws EntryExistsException, RemoteOperationException {
// set the internal DS. Required to
this.setInternalDs(r.getSystem());
// checked DS level delta-enabled property
// while sending delta
boolean sendReply = true;
InternalDistributedMember eventSender = originalSender;
if (eventSender == null) {
eventSender = getSender();
}
@Released EntryEventImpl eei = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
getCallbackArg(), useOriginRemote, /* originRemote - false to force distribution in buckets */
eventSender, true, /* generateCallbacks */
false);
this.event = eei;
try {
if (this.versionTag != null) {
this.versionTag.replaceNullIDs(getSender());
event.setVersionTag(this.versionTag);
}
this.event.setCausedByMessage(this);
event.setPossibleDuplicate(this.possibleDuplicate);
if (this.bridgeContext != null) {
event.setContext(this.bridgeContext);
}
Assert.assertTrue(eventId != null);
event.setEventId(eventId);
// added for cq procesing
if (this.hasOldValue) {
if (this.oldValueIsSerialized) {
event.setSerializedOldValue(getOldValueBytes());
} else {
event.setOldValue(getOldValueBytes());
}
}
if (this.applyDeltaBytes) {
event.setNewValue(this.valObj);
event.setDeltaBytes(this.deltaBytes);
} else {
switch(this.deserializationPolicy) {
case DistributedCacheOperation.DESERIALIZATION_POLICY_LAZY:
event.setSerializedNewValue(getValBytes());
break;
case DistributedCacheOperation.DESERIALIZATION_POLICY_NONE:
event.setNewValue(getValBytes());
break;
default:
throw new AssertionError("unknown deserialization policy: " + deserializationPolicy);
}
}
try {
// the event must show it's true origin for cachewriter invocation
// event.setOriginRemote(true);
// this.op = r.doCacheWriteBeforePut(event, ifNew); // TODO fix this for bug 37072
result = r.getDataView().putEntry(event, this.ifNew, this.ifOld, this.expectedOldValue, this.requireOldValue, this.lastModified, true);
if (!this.result) {
// make sure the region hasn't gone away
r.checkReadiness();
if (!this.ifNew && !this.ifOld) {
// no reason to be throwing an exception, so let's retry
RemoteOperationException fre = new RemoteOperationException(LocalizedStrings.RemotePutMessage_UNABLE_TO_PERFORM_PUT_BUT_OPERATION_SHOULD_NOT_FAIL_0.toLocalizedString());
fre.setHash(key.hashCode());
sendReply(getSender(), getProcessorId(), dm, new ReplyException(fre), r, startTime);
}
}
} catch (CacheWriterException cwe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(cwe), r, startTime);
return false;
} catch (PrimaryBucketException pbe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
return false;
}
// set operation for reply message
setOperation(event.getOperation());
if (sendReply) {
sendReply(getSender(), getProcessorId(), dm, null, r, startTime, event);
}
return false;
} finally {
// OFFHEAP this may be too soon to make this call
this.event.release();
}
}
Aggregations