use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class DistTXState method postRemoveAll.
@Override
public void postRemoveAll(final DistributedRemoveAllOperation op, final VersionedObjectList successfulOps, LocalRegion reg) {
final LocalRegion theRegion;
if (reg instanceof BucketRegion) {
theRegion = ((BucketRegion) reg).getPartitionedRegion();
} else {
theRegion = reg;
}
/*
* Don't fire events here. We are on the data store, we don't need to do anything here. Commit
* will push them out. We need to put this into the tx state.
*/
theRegion.syncBulkOp(new Runnable() {
public void run() {
InternalDistributedMember myId = theRegion.getDistributionManager().getDistributionManagerId();
for (int i = 0; i < op.removeAllDataSize; ++i) {
@Released EntryEventImpl ev = RemoveAllPRMessage.getEventFromEntry(theRegion, myId, myId, i, op.removeAllData, false, op.getBaseEvent().getContext(), false, !op.getBaseEvent().isGenerateCallbacks());
try {
ev.setRemoveAllOperation(op);
// distKeyInfo.setCheckPrimary(false);
if (isUpdatingTxStateDuringPreCommit()) {
KeyInfo keyInfo = ev.getKeyInfo();
DistTxKeyInfo distKeyInfo = new DistTxKeyInfo(keyInfo);
distKeyInfo.setCheckPrimary(false);
ev.setKeyInfo(distKeyInfo);
}
/*
* Whenever commit is called, especially when its a DistTxStateOnCoordinator the txState
* is set to null in @see TXManagerImpl.commit() and thus when basicDestroy will be
* called will be called as in i.e. @see LocalRegion.basicDestroy, they will not found a
* TxState with call for getDataView()
*
* [DISTTX] TODO verify if this is correct to call destroyExistingEntry directly?
*/
try {
if (!(theRegion.getDataView() instanceof TXStateInterface)) {
destroyExistingEntry(ev, true, /* should we invoke cacheWriter? */
null);
} else {
theRegion.basicDestroy(ev, true, /* should we invoke cacheWriter? */
null);
}
} catch (EntryNotFoundException ignore) {
}
successfulOps.addKeyAndVersion(op.removeAllData[i].key, null);
} finally {
ev.release();
}
}
}
}, op.getBaseEvent().getEventId());
}
use of org.apache.geode.cache.EntryNotFoundException 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.EntryNotFoundException in project geode by apache.
the class PRUpdateEntryVersionMessage method operateOnPartitionedRegion.
/*
* (non-Javadoc)
*
* @see org.apache.geode.internal.cache.partitioned.PartitionMessage# operateOnPartitionedRegion
* (org.apache.geode.distributed.internal.DistributionManager,
* org.apache.geode.internal.cache.PartitionedRegion, long)
*/
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion pr, long startTime) throws CacheException, QueryException, DataLocationException, InterruptedException, IOException {
// release not needed because disallowOffHeapValues called
final EntryEventImpl event = EntryEventImpl.create(pr, getOperation(), getKey(), null, /* newValue */
null, /* callbackargs */
false, /* originRemote - false to force distribution in buckets */
getSender(), /* eventSender */
false, /* generateCallbacks */
false);
event.disallowOffHeapValues();
Assert.assertTrue(eventId != null);
if (this.versionTag != null) {
event.setVersionTag(this.versionTag);
}
event.setEventId(eventId);
event.setPossibleDuplicate(this.posDup);
event.setInvokePRCallbacks(false);
event.setCausedByMessage(this);
boolean sendReply = true;
if (!notificationOnly) {
PartitionedRegionDataStore ds = pr.getDataStore();
Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
try {
Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(event));
pr.getDataView().updateEntryVersion(event);
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.debug("{}: updateEntryVersionLocally in bucket: {}, key: {}", getClass().getName(), bucket, key);
}
} catch (EntryNotFoundException eee) {
// failed = true;
if (logger.isDebugEnabled()) {
logger.debug("{}: operateOnRegion caught EntryNotFoundException", getClass().getName());
}
sendReply(getSender(), getProcessorId(), dm, null, /*
* No need to send exception back
*/
pr, startTime);
// this prevents us from acknowledging later
sendReply = false;
} catch (PrimaryBucketException pbe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), pr, startTime);
return false;
}
}
return sendReply;
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class DestroyMessage 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
*/
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException {
InternalDistributedMember eventSender = originalSender;
if (eventSender == null) {
eventSender = getSender();
}
@Released EntryEventImpl event = null;
try {
if (this.bridgeContext != null) {
event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
getCallbackArg(), false, /* originRemote */
eventSender, true);
event.setContext(this.bridgeContext);
} else // bridgeContext != null
{
event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
eventSender, true, /* generateCallbacks */
false);
}
if (this.versionTag != null) {
this.versionTag.replaceNullIDs(getSender());
event.setVersionTag(this.versionTag);
}
event.setInvokePRCallbacks(!notificationOnly);
Assert.assertTrue(eventId != null);
event.setEventId(eventId);
event.setPossibleDuplicate(this.posDup);
PartitionedRegionDataStore ds = r.getDataStore();
boolean sendReply = true;
if (!notificationOnly) {
Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
try {
Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(r, null, this.key, null, this.cbArg));
// try {
// // the event must show its true origin for cachewriter invocation
// event.setOriginRemote(true);
// event.setPartitionMessage(this);
// r.doCacheWriteBeforeDestroy(event);
// }
// finally {
// event.setOriginRemote(false);
// }
event.setCausedByMessage(this);
r.getDataView().destroyOnRemote(event, true, /* cacheWrite */
this.expectedOldValue);
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "{} updated bucket: {} with key: {}", getClass().getName(), bucket, this.key);
}
} catch (CacheWriterException cwe) {
sendReply(getSender(), this.processorId, dm, new ReplyException(cwe), r, startTime);
return false;
} catch (EntryNotFoundException eee) {
logger.trace(LogMarker.DM, "{}: operateOnRegion caught EntryNotFoundException", getClass().getName());
ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(eee), getReplySender(dm), r.isInternalRegion());
// this prevents us from acking later
sendReply = false;
} catch (PrimaryBucketException pbe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
sendReply = false;
} finally {
this.versionTag = event.getVersionTag();
}
} else {
@Released EntryEventImpl e2 = createListenerEvent(event, r, dm.getDistributionManagerId());
try {
r.invokeDestroyCallbacks(EnumListenerEvent.AFTER_DESTROY, e2, r.isInitialized(), true);
} finally {
// if e2 == ev then no need to free it here. The outer finally block will get it.
if (e2 != event) {
e2.release();
}
}
}
return sendReply;
} finally {
if (event != null) {
event.release();
}
}
}
use of org.apache.geode.cache.EntryNotFoundException 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;
}
Aggregations