use of org.apache.geode.cache.PartitionedRegionDistributionException in project geode by apache.
the class PartitionedRegion method tryToSendOnePutAllMessage.
public VersionedObjectList tryToSendOnePutAllMessage(PutAllPRMessage prMsg, InternalDistributedMember currentTarget) throws DataLocationException {
boolean putResult = false;
VersionedObjectList versions = null;
final boolean isLocal = (this.localMaxMemory > 0) && currentTarget.equals(getMyId());
if (isLocal) {
// local
// It might throw retry exception when one key failed
// InternalDS has to be set for each msg
prMsg.initMessage(this, null, false, null);
putResult = prMsg.doLocalPutAll(this, this.getDistributionManager().getDistributionManagerId(), 0L);
versions = prMsg.getVersions();
} else {
PutAllPRMessage.PutAllResponse response = (PutAllPRMessage.PutAllResponse) prMsg.send(currentTarget, this);
PutAllPRMessage.PutAllResult pr = null;
if (response != null) {
this.prStats.incPartitionMessagesSent();
try {
pr = response.waitForResult();
putResult = pr.returnValue;
versions = pr.versions;
} catch (RegionDestroyedException rde) {
if (logger.isDebugEnabled()) {
logger.debug("prMsg.send: caught RegionDestroyedException", rde);
}
throw new RegionDestroyedException(toString(), getFullPath());
} catch (CacheException ce) {
// Fix for bug 36014
throw new PartitionedRegionDistributionException("prMsg.send on " + currentTarget + " failed", ce);
}
} else {
// follow the same behavior of putRemotely()
putResult = true;
}
}
if (!putResult) {
// retry exception when msg failed in waitForResult()
ForceReattemptException fre = new ForceReattemptException("false result in PutAllMessage.send - retrying");
fre.setHash(0);
throw fre;
}
return versions;
}
use of org.apache.geode.cache.PartitionedRegionDistributionException in project geode by apache.
the class PartitionedRegion method putRemotely.
/**
* Puts the key/value pair into the remote target that is managing the key's bucket.
*
* @param recipient the member to receive the message
* @param event the event prompting this action
* @param ifNew the mysterious ifNew parameter
* @param ifOld the mysterious ifOld parameter
* @return whether the operation succeeded
* @throws PrimaryBucketException if the remote bucket was not the primary
* @throws ForceReattemptException if the peer is no longer available
*/
public boolean putRemotely(final DistributedMember recipient, final EntryEventImpl event, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue) throws PrimaryBucketException, ForceReattemptException {
// boolean forceAck = basicGetWriter() != null
// || getDistributionAdvisor().adviseNetWrite().size() > 0;
long eventTime = event.getEventTime(0L);
PutMessage.PutResponse response = (PutMessage.PutResponse) PutMessage.send(recipient, this, event, eventTime, ifNew, ifOld, expectedOldValue, requireOldValue);
PutResult pr = null;
if (response != null) {
this.prStats.incPartitionMessagesSent();
try {
pr = response.waitForResult();
event.setOperation(pr.op);
event.setVersionTag(pr.versionTag);
if (requireOldValue) {
event.setOldValue(pr.oldValue, true);
}
return pr.returnValue;
} catch (RegionDestroyedException rde) {
if (logger.isDebugEnabled()) {
logger.debug("putRemotely: caught RegionDestroyedException", rde);
}
throw new RegionDestroyedException(toString(), getFullPath());
} catch (TransactionException te) {
throw te;
} catch (CacheException ce) {
// Fix for bug 36014
throw new PartitionedRegionDistributionException(LocalizedStrings.PartitionedRegion_PUTTING_ENTRY_ON_0_FAILED.toLocalizedString(recipient), ce);
}
}
// ???:ezoerner:20080728 why return true if response was null?
return true;
}
use of org.apache.geode.cache.PartitionedRegionDistributionException in project geode by apache.
the class PartitionedRegion method invalidateInBucket.
/**
* Invalidate the entry in the bucket identified by the key
*/
void invalidateInBucket(final EntryEventImpl event) throws EntryNotFoundException {
final boolean isDebugEnabled = logger.isDebugEnabled();
final Integer bucketId = event.getKeyInfo().getBucketId();
assert bucketId != KeyInfo.UNKNOWN_BUCKET;
final InternalDistributedMember targetNode = getOrCreateNodeForBucketWrite(bucketId, null);
final int retryAttempts = calcRetry();
int count = 0;
RetryTimeKeeper retryTime = null;
InternalDistributedMember retryNode = targetNode;
while (count <= retryAttempts) {
// 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 or waitForBucketRecovery
checkShutdown();
if (retryNode == null) {
checkReadiness();
if (retryTime == null) {
retryTime = new RetryTimeKeeper(this.retryTimeout);
}
try {
retryNode = getOrCreateNodeForBucketWrite(bucketId, retryTime);
} catch (TimeoutException ignore) {
if (getRegionAdvisor().isStorageAssignedForBucket(bucketId)) {
// bucket no longer exists
throw new EntryNotFoundException(LocalizedStrings.PartitionedRegion_ENTRY_NOT_FOUND_FOR_KEY_0.toLocalizedString(event.getKey()));
}
// fall out to failed exception
break;
}
if (retryNode == null) {
checkEntryNotFound(event.getKey());
}
continue;
}
final boolean isLocal = (this.localMaxMemory > 0) && retryNode.equals(getMyId());
try {
if (isLocal) {
event.setInvokePRCallbacks(true);
this.dataStore.invalidateLocally(bucketId, event);
} else {
invalidateRemotely(retryNode, bucketId, event);
}
return;
} catch (ConcurrentCacheModificationException e) {
if (isDebugEnabled) {
logger.debug("invalidateInBucket: caught concurrent cache modification exception", e);
}
event.isConcurrencyConflict(true);
if (isDebugEnabled) {
logger.debug("ConcurrentCacheModificationException received for invalidateInBucket for bucketId: {}{}{} for event: {} No reattampt is done, returning from here", getPRId(), BUCKET_ID_SEPARATOR, bucketId, event);
}
return;
} catch (ForceReattemptException prce) {
prce.checkKey(event.getKey());
if (isDebugEnabled) {
logger.debug("invalidateInBucket: retry attempt:{} of {}", count, retryAttempts, prce);
}
checkReadiness();
InternalDistributedMember lastNode = retryNode;
retryNode = getOrCreateNodeForBucketWrite(bucketId, retryTime);
if (lastNode.equals(retryNode)) {
if (retryTime == null) {
retryTime = new RetryTimeKeeper(this.retryTimeout);
}
if (retryTime.overMaximum()) {
break;
}
retryTime.waitToRetryNode();
}
event.setPossibleDuplicate(true);
} catch (PrimaryBucketException notPrimary) {
if (isDebugEnabled) {
logger.debug("invalidateInBucket {} on Node {} not primary", notPrimary.getLocalizedMessage(), retryNode);
}
getRegionAdvisor().notPrimary(bucketId, retryNode);
retryNode = getOrCreateNodeForBucketWrite(bucketId, retryTime);
}
count++;
if (count == 1) {
this.prStats.incInvalidateOpsRetried();
}
this.prStats.incInvalidateRetries();
if (isDebugEnabled) {
logger.debug("invalidateInBucket: Attempting to resend invalidate to node {} after {} failed attempts", retryNode, count);
}
}
// while
// No target was found
PartitionedRegionDistributionException e = new PartitionedRegionDistributionException(LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_INVALIDATE_IN_0_ATTEMPTS.toLocalizedString(// Fix for bug 36014
count));
if (!isDebugEnabled) {
logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_INVALIDATE_IN_0_ATTEMPTS, count));
} else {
logger.warn(e.getMessage(), e);
}
throw e;
}
use of org.apache.geode.cache.PartitionedRegionDistributionException 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.PartitionedRegionDistributionException in project geode by apache.
the class PartitionedRegion method sendInvalidateRegionMessage.
private void sendInvalidateRegionMessage(RegionEventImpl event) {
final int retryAttempts = calcRetry();
Throwable thr = null;
int count = 0;
while (count <= retryAttempts) {
try {
count++;
Set recipients = getRegionAdvisor().adviseDataStore();
ReplyProcessor21 response = InvalidatePartitionedRegionMessage.send(recipients, this, event);
response.waitForReplies();
thr = null;
break;
} catch (ReplyException e) {
thr = e;
if (!this.isClosed && !this.isDestroyed) {
if (logger.isDebugEnabled()) {
logger.debug("Invalidating partitioned region caught exception", e);
}
}
} catch (InterruptedException e) {
thr = e;
if (!cache.getCancelCriterion().isCancelInProgress()) {
if (logger.isDebugEnabled()) {
logger.debug("Invalidating partitioned region caught exception", e);
}
}
}
}
if (thr != null) {
PartitionedRegionDistributionException e = new PartitionedRegionDistributionException(LocalizedStrings.PartitionedRegion_INVALIDATING_REGION_CAUGHT_EXCEPTION.toLocalizedString(count));
if (logger.isDebugEnabled()) {
logger.debug(e.getMessage(), e);
}
throw e;
}
}
Aggregations