use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.
the class DumpB2NRegion method process.
@Override
public void process(final DistributionManager dm) {
PartitionedRegion pr = null;
// Get the region, or die trying...
final long finish = System.currentTimeMillis() + 10 * 1000;
try {
for (; ; ) {
dm.getCancelCriterion().checkCancelInProgress(null);
// pr = null; (redundant assignment)
pr = PartitionedRegion.getPRFromId(this.regionId);
if (pr != null) {
break;
}
if (System.currentTimeMillis() > finish) {
ReplyException rex = new ReplyException(new TimeoutException("Waited too long for region to initialize"));
sendReply(getSender(), this.processorId, dm, rex, null, 0);
return;
}
// wait a little
boolean interrupted = Thread.interrupted();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
interrupted = true;
pr.checkReadiness();
} finally {
if (interrupted)
Thread.currentThread().interrupt();
}
}
// Now, wait for the PR to finish initializing
pr.waitForData();
// OK, now it's safe to process this.
super.process(dm);
} catch (CancelException e) {
sendReply(this.sender, this.processorId, dm, new ReplyException(e), pr, 0);
} catch (PRLocallyDestroyedException e) {
sendReply(this.sender, this.processorId, dm, new ReplyException(e), pr, 0);
return;
} catch (RegionDestroyedException rde) {
sendReply(this.sender, this.processorId, dm, new ReplyException(rde), pr, 0);
return;
}
}
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 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;
}
Aggregations