use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.
the class FetchEntryMessage method operateOnPartitionedRegion.
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws ForceReattemptException {
// FetchEntryMessage is used in refreshing client caches during interest list recovery,
// so don't be too verbose or hydra tasks may time out
PartitionedRegionDataStore ds = r.getDataStore();
EntrySnapshot val;
if (ds != null) {
try {
KeyInfo keyInfo = r.getKeyInfo(key);
val = (EntrySnapshot) r.getDataView().getEntryOnRemote(keyInfo, r, true);
r.getPrStats().endPartitionMessagesProcessing(startTime);
FetchEntryReplyMessage.send(getSender(), getProcessorId(), val, dm, null);
} catch (TransactionException tex) {
FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(tex));
} catch (PRLocallyDestroyedException pde) {
FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(new ForceReattemptException(LocalizedStrings.FetchEntryMessage_ENCOUNTERED_PRLOCALLYDESTROYED.toLocalizedString(), pde)));
} catch (EntryNotFoundException enfe) {
FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(LocalizedStrings.FetchEntryMessage_ENTRY_NOT_FOUND.toLocalizedString(), enfe));
} catch (PrimaryBucketException pbe) {
FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(pbe));
} catch (ForceReattemptException pbe) {
pbe.checkKey(key);
// Slightly odd -- we're marshalling the retry to the peer on another host...
FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(pbe));
} catch (DataLocationException e) {
FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(e));
}
} else {
throw new InternalGemFireError(LocalizedStrings.FetchEntryMessage_FETCHENTRYMESSAGE_MESSAGE_SENT_TO_WRONG_MEMBER.toLocalizedString());
}
// response
return false;
}
use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.
the class InvalidateMessage method operateOnPartitionedRegion.
/**
* 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
* @throws DataLocationException
*/
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException {
InternalDistributedMember eventSender = originalSender;
if (eventSender == null) {
eventSender = getSender();
}
final Object key = getKey();
@Released final EntryEventImpl event = EntryEventImpl.create(r, getOperation(), key, null, /* newValue */
getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
eventSender, true, /* generateCallbacks */
false);
try {
if (this.versionTag != null) {
this.versionTag.replaceNullIDs(getSender());
event.setVersionTag(this.versionTag);
}
if (this.bridgeContext != null) {
event.setContext(this.bridgeContext);
}
// Assert.assertTrue(eventId != null); bug #47235: region invalidation doesn't send event ids
event.setEventId(eventId);
event.setPossibleDuplicate(this.posDup);
PartitionedRegionDataStore ds = r.getDataStore();
boolean sendReply = true;
// boolean failed = false;
event.setInvokePRCallbacks(!notificationOnly);
if (!notificationOnly) {
Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
try {
Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(event));
event.setCausedByMessage(this);
r.getDataView().invalidateOnRemote(event, true, /* invokeCallbacks */
false);
this.versionTag = event.getVersionTag();
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "{} invalidateLocally in bucket: {}, key: {}", getClass().getName(), bucket, key);
}
} catch (DataLocationException e) {
((ForceReattemptException) e).checkKey(event.getKey());
throw e;
} catch (EntryNotFoundException eee) {
// failed = true;
if (logger.isDebugEnabled()) {
logger.debug("{}: operateOnRegion caught EntryNotFoundException {}", getClass().getName(), eee.getMessage(), eee);
}
sendReply(getSender(), getProcessorId(), dm, new ReplyException(eee), r, startTime);
// this prevents us from acking later
sendReply = false;
} catch (PrimaryBucketException pbe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
return false;
}
} else {
event.setRegion(r);
event.setOriginRemote(true);
if (this.versionTag != null) {
this.versionTag.replaceNullIDs(getSender());
event.setVersionTag(this.versionTag);
}
if (this.filterInfo != null) {
event.setLocalFilterInfo(this.filterInfo.getFilterInfo(dm.getDistributionManagerId()));
}
r.invokeInvalidateCallbacks(EnumListenerEvent.AFTER_INVALIDATE, event, r.isInitialized());
}
return sendReply;
} finally {
event.release();
}
}
use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.
the class TXFailoverCommand method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
serverConnection.setAsTrue(REQUIRES_RESPONSE);
// Build the TXId for the transaction
InternalDistributedMember client = (InternalDistributedMember) serverConnection.getProxyID().getDistributedMember();
int uniqId = clientMessage.getTransactionId();
if (logger.isDebugEnabled()) {
logger.debug("TX: Transaction {} from {} is failing over to this server", uniqId, client);
}
TXId txId = new TXId(client, uniqId);
TXManagerImpl mgr = (TXManagerImpl) serverConnection.getCache().getCacheTransactionManager();
// in case it's already completing here in another
mgr.waitForCompletingTransaction(txId);
// thread
if (mgr.isHostedTxRecentlyCompleted(txId)) {
writeReply(clientMessage, serverConnection);
serverConnection.setAsTrue(RESPONDED);
mgr.removeHostedTXState(txId);
return;
}
// fixes bug 43350
boolean wasInProgress = mgr.setInProgress(true);
TXStateProxy tx = mgr.getTXState();
Assert.assertTrue(tx != null);
if (!tx.isRealDealLocal()) {
// send message to all peers to find out who hosts the transaction
FindRemoteTXMessageReplyProcessor processor = FindRemoteTXMessage.send(serverConnection.getCache(), txId);
try {
processor.waitForRepliesUninterruptibly();
} catch (ReplyException e) {
e.handleAsUnexpected();
}
// if hosting member is not null, bootstrap PeerTXStateStub to that member
// if hosting member is null, rebuild TXCommitMessage from partial TXCommitMessages
InternalDistributedMember hostingMember = processor.getHostingMember();
if (hostingMember != null) {
if (logger.isDebugEnabled()) {
logger.debug("TX: txState is not local, bootstrapping PeerTXState stub for targetNode: {}", hostingMember);
}
// inject the real deal
tx.setLocalTXState(new PeerTXStateStub(tx, hostingMember, client));
} else {
// bug #42228 and bug #43504 - this cannot return until the current view
// has been installed by all members, so that dlocks are released and
// the same keys can be used in a new transaction by the same client thread
InternalCache cache = serverConnection.getCache();
try {
WaitForViewInstallation.send((DistributionManager) cache.getDistributionManager());
} catch (InterruptedException e) {
cache.getDistributionManager().getCancelCriterion().checkCancelInProgress(e);
Thread.currentThread().interrupt();
}
// tx host has departed, rebuild the tx
if (processor.getTxCommitMessage() != null) {
if (logger.isDebugEnabled()) {
logger.debug("TX: for txId: {} rebuilt a recently completed tx", txId);
}
mgr.saveTXCommitMessageForClientFailover(txId, processor.getTxCommitMessage());
} else {
writeException(clientMessage, new TransactionDataNodeHasDepartedException("Could not find transaction host for " + txId), false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
mgr.removeHostedTXState(txId);
return;
}
}
}
if (!wasInProgress) {
mgr.setInProgress(false);
}
writeReply(clientMessage, serverConnection);
serverConnection.setAsTrue(RESPONDED);
}
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;
}
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();
}
Aggregations