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();
}
}
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);
}
}
}
use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.
the class ElderInitProcessor method init.
////////// Public static entry point /////////
/**
* Initializes ElderState map by recovering all existing grantors and crashed grantors in the
* current ds.
*/
static void init(DM dm, HashMap map) {
HashSet crashedGrantors = new HashSet();
if (!dm.isAdam()) {
Set others = dm.getOtherDistributionManagerIds();
if (!others.isEmpty()) {
ElderInitProcessor processor = new ElderInitProcessor(dm, others, map, crashedGrantors);
ElderInitMessage.send(others, dm, processor);
try {
processor.waitForRepliesUninterruptibly();
} catch (ReplyException e) {
e.handleAsUnexpected();
}
}
}
// always recover from ourself
GrantorRequestProcessor.readyForElderRecovery(dm.getSystem(), null, null);
DLockService.recoverLocalElder(dm, map, crashedGrantors);
{
Iterator it = crashedGrantors.iterator();
while (it.hasNext()) {
map.put(it.next(), new GrantorInfo(null, 0, 0, true));
}
}
}
use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.
the class ShutdownAllRequest method send.
/**
* Sends a shutdownAll request to all other members and performs local shutdownAll processing in
* the waitingThreadPool.
*/
public static Set send(final DM dm, long timeout) {
boolean hadCache = hasCache();
DistributionManager dism = dm instanceof DistributionManager ? (DistributionManager) dm : null;
InternalDistributedMember myId = dm.getDistributionManagerId();
Set recipients = dm.getOtherNormalDistributionManagerIds();
recipients.remove(myId);
// now do shutdownall
ShutdownAllRequest request = new ShutdownAllRequest();
request.setRecipients(recipients);
ShutDownAllReplyProcessor replyProcessor = new ShutDownAllReplyProcessor(dm, recipients);
request.msgId = replyProcessor.getProcessorId();
dm.putOutgoing(request);
if (!InternalLocator.isDedicatedLocator()) {
if (hadCache && dism != null) {
AdminResponse response;
try {
request.setSender(myId);
response = request.createResponse(dism);
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("caught exception while processing shutdownAll locally", ex);
}
response = AdminFailureResponse.create(dism, myId, ex);
}
response.setSender(myId);
replyProcessor.process(response);
}
}
boolean interrupted = false;
try {
if (!replyProcessor.waitForReplies(timeout)) {
return null;
}
} catch (ReplyException e) {
if (!(e.getCause() instanceof CancelException)) {
e.handleAsUnexpected();
}
} catch (CancelException ignore) {
// expected
} catch (InterruptedException ignore) {
interrupted = true;
}
// wait until all the recipients send response, shut down itself (if not a locator)
if (hadCache) {
// because the cache is closed at GemFireCacheImpl.getInstance().shutDownAll()
if (!InternalLocator.isDedicatedLocator()) {
InternalDistributedSystem ids = dm.getSystem();
if (ids.isConnected()) {
ids.disconnect();
}
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
try {
Thread.sleep(3 * SLEEP_TIME_BEFORE_DISCONNECT_DS);
} catch (InterruptedException ignore) {
}
return replyProcessor.getResults();
}
Aggregations