use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.
the class PartitionedRegion method sendDumpB2NRegionForBucket.
/**
* Sends a message to all the {@code PartitionedRegion} participants, telling each member of the
* PartitionedRegion to dump the nodelist in bucket2node metadata for specified bucketId.
*/
public void sendDumpB2NRegionForBucket(int bucketId) {
getRegionAdvisor().dumpProfiles("dumpB2NForBucket");
try {
PartitionResponse response = DumpB2NRegion.send(this.getRegionAdvisor().adviseAllPRNodes(), this, bucketId, false);
response.waitForRepliesUninterruptibly();
this.dumpB2NForBucket(bucketId);
} catch (ReplyException re) {
if (logger.isDebugEnabled()) {
logger.debug("sendDumpB2NRegionForBucket got ReplyException", re);
}
} catch (CancelException e) {
if (logger.isDebugEnabled()) {
logger.debug("sendDumpB2NRegionForBucket got CacheClosedException", e);
}
} catch (RegionDestroyedException e) {
if (logger.isDebugEnabled()) {
logger.debug("sendDumpB2RegionForBucket got RegionDestroyedException", e);
}
}
}
use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.
the class PartitionedRegion method containsKeyInBucket.
boolean containsKeyInBucket(final InternalDistributedMember targetNode, final Integer bucketIdInt, final Object key, boolean valueCheck) {
final int retryAttempts = calcRetry();
if (logger.isDebugEnabled()) {
logger.debug("containsKeyInBucket: {}{} ({}) from: {} bucketId={}", (valueCheck ? "ValueForKey key=" : "Key key="), key, key.hashCode(), targetNode, bucketStringForLogs(bucketIdInt));
}
boolean ret;
int count = 0;
RetryTimeKeeper retryTime = null;
InternalDistributedMember retryNode = targetNode;
while (count <= retryAttempts) {
// Every continuation should check for DM cancellation
if (retryNode == null) {
checkReadiness();
if (retryTime == null) {
retryTime = new RetryTimeKeeper(this.retryTimeout);
}
if (retryTime.overMaximum()) {
break;
}
retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
// No storage found for bucket, early out preventing hot loop, bug 36819
if (retryNode == null) {
// Prefer closed style exceptions over empty result
checkShutdown();
return false;
}
continue;
}
// retryNode != null
try {
final boolean loc = retryNode.equals(getMyId());
if (loc) {
if (valueCheck) {
ret = this.dataStore.containsValueForKeyLocally(bucketIdInt, key);
} else {
ret = this.dataStore.containsKeyLocally(bucketIdInt, key);
}
} else {
if (valueCheck) {
ret = containsValueForKeyRemotely(retryNode, bucketIdInt, key);
} else {
ret = containsKeyRemotely(retryNode, bucketIdInt, key);
}
}
return ret;
} catch (PRLocallyDestroyedException pde) {
if (logger.isDebugEnabled()) {
logger.debug("containsKeyInBucket: Encountered PRLocallyDestroyedException", pde);
}
checkReadiness();
} catch (ForceReattemptException prce) {
prce.checkKey(key);
if (logger.isDebugEnabled()) {
logger.debug("containsKeyInBucket: retry attempt:{} of {}", count, retryAttempts, prce);
}
checkReadiness();
InternalDistributedMember lastNode = retryNode;
retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
if (lastNode.equals(retryNode)) {
if (retryTime == null) {
retryTime = new RetryTimeKeeper(this.retryTimeout);
}
if (retryTime.overMaximum()) {
break;
}
retryTime.waitToRetryNode();
}
} catch (PrimaryBucketException notPrimary) {
if (logger.isDebugEnabled()) {
logger.debug("containsKeyInBucket {} on Node {} not primary", notPrimary.getLocalizedMessage(), retryNode);
}
getRegionAdvisor().notPrimary(bucketIdInt, retryNode);
retryNode = getOrCreateNodeForBucketRead(bucketIdInt);
} catch (RegionDestroyedException rde) {
if (!rde.getRegionFullPath().equals(getFullPath())) {
throw new RegionDestroyedException(toString(), getFullPath(), rde);
}
}
// It's possible this is a GemFire thread e.g. ServerConnection
// which got to this point because of a distributed system shutdown or
// region closure which uses interrupt to break any sleep() or wait()
// calls
// e.g. waitForPrimary
checkShutdown();
count++;
if (count == 1) {
this.prStats.incContainsKeyValueOpsRetried();
}
this.prStats.incContainsKeyValueRetries();
}
StringId msg = null;
if (valueCheck) {
msg = LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_CONTAINS_VALUE_FOR_KEY_IN_1_ATTEMPTS;
} else {
msg = LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_CONTAINS_KEY_IN_1_ATTEMPTS;
}
Integer countInteger = count;
// Fix for bug 36014
PartitionedRegionDistributionException e = null;
if (logger.isDebugEnabled()) {
e = new PartitionedRegionDistributionException(msg.toLocalizedString(countInteger));
}
logger.warn(LocalizedMessage.create(msg, countInteger), e);
return false;
}
use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.
the class PartitionedRegion method getDataRegionForWrite.
@Override
public LocalRegion getDataRegionForWrite(KeyInfo keyInfo) {
BucketRegion br = null;
final Object entryKey = keyInfo.getKey();
try {
final int retryAttempts = calcRetry();
// TODO provide appropriate Operation and arg
int bucketId = keyInfo.getBucketId();
if (bucketId == KeyInfo.UNKNOWN_BUCKET) {
bucketId = PartitionedRegionHelper.getHashKey(this, null, entryKey, keyInfo.getValue(), keyInfo.getCallbackArg());
keyInfo.setBucketId(bucketId);
}
int count = 0;
while (count <= retryAttempts) {
try {
PartitionedRegionDataStore ds = getDataStore();
if (ds == null) {
throw new TransactionException(LocalizedStrings.PartitionedRegion_TX_ON_DATASTORE.toLocalizedString());
}
br = ds.getInitializedBucketWithKnownPrimaryForId(entryKey, bucketId);
break;
} catch (ForceReattemptException ignore) {
// create a new bucket
InternalDistributedMember member = createBucket(bucketId, 0, null);
if (!getMyId().equals(member) && keyInfo.isCheckPrimary()) {
throw new PrimaryBucketException("Bucket " + bucketId + " is not primary. Current primary holder is " + member);
}
count++;
}
}
Assert.assertTrue(br != null, "Could not create storage for Entry");
if (keyInfo.isCheckPrimary()) {
br.checkForPrimary();
}
} catch (PrimaryBucketException pbe) {
throw new TransactionDataRebalancedException(LocalizedStrings.PartitionedRegion_TRANSACTIONAL_DATA_MOVED_DUE_TO_REBALANCING.toLocalizedString(), pbe);
} catch (RegionDestroyedException ignore) {
// TODO: why is this purposely not wrapping the original cause?
throw new TransactionDataNotColocatedException(LocalizedStrings.PartitionedRegion_KEY_0_NOT_COLOCATED_WITH_TRANSACTION.toLocalizedString(entryKey));
}
return br;
}
use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.
the class PartitionMessage 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;
PartitionedRegion pr = null;
long startTime = 0;
EntryLogger.setSource(getSender(), "PR");
try {
if (checkCacheClosing(dm) || checkDSClosing(dm)) {
thr = new CacheClosedException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString(dm.getId()));
return;
}
pr = getPartitionedRegion();
if (pr == 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 ForceReattemptException(LocalizedStrings.PartitionMessage_0_COULD_NOT_FIND_PARTITIONED_REGION_WITH_ID_1.toLocalizedString(dm.getDistributionManagerId(), regionId));
// reply sent in finally block below
return;
}
if (pr != null) {
startTime = getStartPartitionMessageProcessingTime(pr);
}
thr = UNHANDLED_EXCEPTION;
InternalCache cache = getInternalCache();
if (cache == null) {
throw new ForceReattemptException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString());
}
TXManagerImpl txMgr = getTXManagerImpl(cache);
TXStateProxy tx = txMgr.masqueradeAs(this);
if (tx == null) {
sendReply = operateOnPartitionedRegion(dm, pr, startTime);
} else {
try {
if (txMgr.isClosed()) {
// NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
sendReply = false;
} else if (tx.isInProgress()) {
sendReply = operateOnPartitionedRegion(dm, pr, startTime);
tx.updateProxyServer(this.getSender());
}
} finally {
txMgr.unmasquerade(tx);
}
}
thr = null;
} catch (ForceReattemptException fre) {
thr = fre;
} catch (DataLocationException fre) {
thr = new ForceReattemptException(fre.getMessage(), 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 | RegionNotFoundException 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.getMessage(), 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
boolean excludeException = this.notificationOnly && ((thr instanceof CancelException) || (thr instanceof ForceReattemptException));
if (!excludeException) {
rex = new ReplyException(thr);
}
}
// Send the reply if the operateOnPartitionedRegion returned true
sendReply(getSender(), this.processorId, dm, rex, pr, startTime);
EntryLogger.clearSource();
}
}
}
use of org.apache.geode.cache.RegionDestroyedException in project geode by apache.
the class IndexCreationMsg method process.
/**
* Process this index creation message on the receiver.
*/
@Override
public void process(final DistributionManager dm) {
final boolean isDebugEnabled = logger.isDebugEnabled();
Throwable thr = null;
boolean sendReply = true;
PartitionedRegion pr = null;
try {
if (isDebugEnabled) {
logger.debug("Trying to get pr with id: {}", this.regionId);
}
try {
if (isDebugEnabled) {
logger.debug("Again trying to get pr with id : {}", this.regionId);
}
pr = PartitionedRegion.getPRFromId(this.regionId);
if (isDebugEnabled) {
logger.debug("Index creation message got the pr {}", pr);
}
if (null == pr) {
boolean wait = true;
int attempts = 0;
while (wait && attempts < 30) {
// max 30 seconds of wait.
dm.getCancelCriterion().checkCancelInProgress(null);
if (isDebugEnabled) {
logger.debug("Waiting for Partitioned Region to be intialized with id {}for processing index creation messages", this.regionId);
}
try {
boolean interrupted = Thread.interrupted();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
interrupted = true;
dm.getCancelCriterion().checkCancelInProgress(e);
} finally {
if (interrupted)
Thread.currentThread().interrupt();
}
pr = PartitionedRegion.getPRFromId(this.regionId);
if (null != pr) {
wait = false;
if (isDebugEnabled) {
logger.debug("Indexcreation message got the pr {}", pr);
}
}
attempts++;
} catch (CancelException ignorAndLoopWait) {
if (isDebugEnabled) {
logger.debug("IndexCreationMsg waiting for pr to be properly created with prId : {}", this.regionId);
}
}
}
}
} catch (CancelException letPRInitialized) {
// to the PR being initialized.
if (logger.isDebugEnabled()) {
logger.debug("Waiting for notification from pr being properly created on {}", this.regionId);
}
boolean wait = true;
while (wait) {
dm.getCancelCriterion().checkCancelInProgress(null);
try {
boolean interrupted = Thread.interrupted();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
interrupted = true;
dm.getCancelCriterion().checkCancelInProgress(e);
} finally {
if (interrupted)
Thread.currentThread().interrupt();
}
pr = PartitionedRegion.getPRFromId(this.regionId);
wait = false;
if (logger.isDebugEnabled()) {
logger.debug("Indexcreation message got the pr {}", pr);
}
} catch (CancelException ignorAndLoopWait) {
if (logger.isDebugEnabled()) {
logger.debug("IndexCreationMsg waiting for pr to be properly created with prId : {}", this.regionId);
}
}
}
}
if (pr == null) /* && failIfRegionMissing() */
{
String msg = LocalizedStrings.IndexCreationMsg_COULD_NOT_GET_PARTITIONED_REGION_FROM_ID_0_FOR_MESSAGE_1_RECEIVED_ON_MEMBER_2_MAP_3.toLocalizedString(new Object[] { Integer.valueOf(this.regionId), this, dm.getId(), PartitionedRegion.dumpPRId() });
throw new PartitionedRegionException(msg, new RegionNotFoundException(msg));
}
sendReply = operateOnPartitionedRegion(dm, pr, 0);
} catch (PRLocallyDestroyedException pre) {
if (isDebugEnabled) {
logger.debug("Region is locally Destroyed ");
}
thr = pre;
} 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
if (this.processorId == 0) {
logger.debug("{} exception while processing message:{}", this, t.getMessage(), t);
} else if (logger.isDebugEnabled(LogMarker.DM) && (t instanceof RuntimeException)) {
logger.debug(LogMarker.DM, "Exception caught while processing message: {}", t.getMessage(), t);
}
if (t instanceof RegionDestroyedException && pr != null) {
if (pr.isClosed) {
logger.info(LocalizedMessage.create(LocalizedStrings.IndexCreationMsg_REGION_IS_LOCALLY_DESTROYED_THROWING_REGIONDESTROYEDEXCEPTION_FOR__0, pr));
thr = new RegionDestroyedException(LocalizedStrings.IndexCreationMsg_REGION_IS_LOCALLY_DESTROYED_ON_0.toLocalizedString(dm.getId()), pr.getFullPath());
}
} else {
thr = t;
}
} finally {
if (sendReply && this.processorId != 0) {
ReplyException rex = null;
if (thr != null) {
rex = new ReplyException(thr);
}
sendReply(getSender(), this.processorId, dm, rex, pr, 0);
}
}
}
Aggregations