use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class PartitionedRegionHelper method removeGlobalMetadataForFailedNode.
/**
* This function is used for cleaning the config meta data for the failed or closed
* PartitionedRegion node.
*
* @param failedNode The failed PartitionedRegion Node
* @param regionIdentifier The PartitionedRegion for which the cleanup is required
* @param cache GemFire cache.
* @param lock True if this removal should acquire and release the RegionLock
*/
static void removeGlobalMetadataForFailedNode(Node failedNode, String regionIdentifier, InternalCache cache, final boolean lock) {
Region root = PartitionedRegionHelper.getPRRoot(cache, false);
if (root == null) {
// no partitioned region info to clean up
return;
}
PartitionRegionConfig prConfig = (PartitionRegionConfig) root.get(regionIdentifier);
if (null == prConfig || !prConfig.containsNode(failedNode)) {
return;
}
final PartitionedRegion.RegionLock rl = PartitionedRegion.getRegionLock(regionIdentifier, cache);
try {
if (lock) {
rl.lock();
}
prConfig = (PartitionRegionConfig) root.get(regionIdentifier);
if (prConfig != null && prConfig.containsNode(failedNode)) {
if (logger.isDebugEnabled()) {
logger.debug("Cleaning up config for pr {} node {}", regionIdentifier, failedNode);
}
if ((prConfig.getNumberOfNodes() - 1) <= 0) {
if (logger.isDebugEnabled()) {
logger.debug("No nodes left but failed node {} destroying entry {} nodes {}", failedNode, regionIdentifier, prConfig.getNodes());
}
try {
root.destroy(regionIdentifier);
} catch (EntryNotFoundException e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionedRegionHelper_GOT_ENTRYNOTFOUNDEXCEPTION_IN_DESTROY_OP_FOR_ALLPRREGION_KEY_0, regionIdentifier), e);
}
} else {
prConfig.removeNode(failedNode);
if (prConfig.getNumberOfNodes() == 0) {
root.destroy(regionIdentifier);
} else {
// We can't go backwards, or we potentially lose data
root.put(regionIdentifier, prConfig);
}
}
}
} finally {
if (lock) {
rl.unlock();
}
}
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class RemoteFetchVersionMessage method operateOnRegion.
@Override
protected boolean operateOnRegion(DistributionManager dm, LocalRegion r, long startTime) throws RemoteOperationException {
if (!(r instanceof PartitionedRegion)) {
r.waitOnInitialization();
}
VersionTag tag;
try {
RegionEntry re = r.getRegionEntry(key);
if (re == null) {
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "RemoteFetchVersionMessage did not find entry for key:{}", key);
}
r.checkEntryNotFound(key);
}
tag = re.getVersionStamp().asVersionTag();
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.debug("RemoteFetchVersionMessage for key:{} returning tag:{}", key, tag);
}
FetchVersionReplyMessage.send(getSender(), processorId, tag, dm);
} catch (EntryNotFoundException e) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(e), r, startTime);
}
return false;
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class TXJUnitTest method testRepeatableRead.
@Test
public void testRepeatableRead() throws CacheException {
final TXManagerImpl txMgrImpl = (TXManagerImpl) this.txMgr;
TXStateProxy tx;
// try repeating a get and make sure it doesn't cause a conflict
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
assertEquals("value1", this.region.get("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals("value1", this.region.get("key1"));
txMgrImpl.commit();
// try repeating a get and modify the entry and make sure it causes a conflict
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
assertEquals("value1", this.region.get("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals("value1", this.region.get("key1"));
this.region.put("key1", "value3");
assertEquals("value3", this.region.get("key1"));
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
// try repeating a getEntry and make sure it doesn't cause a conflict
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
this.region.getEntry("key1");
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals("value1", this.region.get("key1"));
txMgrImpl.commit();
// try repeating a getEntry and modify the entry and make sure it causes a conflict
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
this.region.getEntry("key1");
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
this.region.put("key1", "value3");
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
// try RR when entry fetched using entrySet
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
// bootstrap the tx, entrySet does not
this.region.get("key1");
this.region.entrySet(false).iterator().next();
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals("value1", this.region.get("key1"));
txMgrImpl.commit();
// try RRW->CONFLICT when entry fetched using entrySet
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
// bootstrap the tx, entrySet does not
this.region.get("key1");
this.region.entrySet(false).iterator().next();
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals("value1", this.region.get("key1"));
this.region.put("key1", "value3");
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
// try containsKey
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
assertEquals(true, this.region.containsKey("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.remove("key1");
txMgrImpl.internalResume(tx);
assertEquals(true, this.region.containsKey("key1"));
txMgrImpl.commit();
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
assertEquals(true, this.region.containsKey("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.remove("key1");
txMgrImpl.internalResume(tx);
assertEquals(true, this.region.containsKey("key1"));
this.region.put("key1", "value3");
assertEquals(true, this.region.containsKey("key1"));
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
// try containsValueForKey
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
assertEquals(true, this.region.containsValueForKey("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.remove("key1");
txMgrImpl.internalResume(tx);
assertEquals(true, this.region.containsValueForKey("key1"));
txMgrImpl.commit();
// non-tx
this.region.put("key1", "value1");
txMgrImpl.begin();
assertEquals(true, this.region.containsValueForKey("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.remove("key1");
txMgrImpl.internalResume(tx);
assertEquals(true, this.region.containsValueForKey("key1"));
this.region.put("key1", "value3");
assertEquals(true, this.region.containsValueForKey("key1"));
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
// now try the same things but with no entry in committed state at
// the time of the first read
// try repeating a get and make sure it doesn't cause a conflict
// non-tx
this.region.remove("key1");
txMgrImpl.begin();
assertEquals(null, this.region.get("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals(null, this.region.get("key1"));
txMgrImpl.commit();
// try repeating a get and modify the entry and make sure it causes a conflict
// non-tx
this.region.remove("key1");
txMgrImpl.begin();
assertEquals(null, this.region.get("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals(null, this.region.get("key1"));
this.region.put("key1", "value3");
assertEquals("value3", this.region.get("key1"));
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
// try repeating a getEntry and make sure it doesn't cause a conflict
// non-tx
this.region.remove("key1");
txMgrImpl.begin();
assertEquals(null, this.region.getEntry("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals(null, this.region.getEntry("key1"));
txMgrImpl.commit();
// try repeating a getEntry and modify the entry and make sure it causes a conflict
// non-tx
this.region.remove("key1");
txMgrImpl.begin();
assertEquals(null, this.region.getEntry("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals(null, this.region.getEntry("key1"));
this.region.put("key1", "value3");
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
// try containsKey
// non-tx
this.region.remove("key1");
txMgrImpl.begin();
assertEquals(false, this.region.containsKey("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals(false, this.region.containsKey("key1"));
txMgrImpl.commit();
// non-tx
this.region.remove("key1");
txMgrImpl.begin();
assertEquals(false, this.region.containsKey("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals(false, this.region.containsKey("key1"));
this.region.put("key1", "value3");
assertEquals(true, this.region.containsKey("key1"));
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
// try containsValueForKey
// non-tx
this.region.remove("key1");
txMgrImpl.begin();
assertEquals(false, this.region.containsValueForKey("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals(false, this.region.containsValueForKey("key1"));
txMgrImpl.commit();
// non-tx
this.region.remove("key1");
txMgrImpl.begin();
assertEquals(false, this.region.containsValueForKey("key1"));
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.put("key1", "value2");
txMgrImpl.internalResume(tx);
assertEquals(false, this.region.containsValueForKey("key1"));
this.region.put("key1", "value3");
assertEquals(true, this.region.containsValueForKey("key1"));
try {
txMgrImpl.commit();
fail("expected CommitConflictException");
} catch (CommitConflictException ex) {
}
// try an invalidate of an already invalid entry
// non-tx
this.region.remove("key1");
// non-tx
this.region.create("key1", null);
txMgrImpl.begin();
this.region.get("key1");
// should be a noop since it is already invalid
this.region.localInvalidate("key1");
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.remove("key1");
txMgrImpl.internalResume(tx);
txMgrImpl.commit();
assertEquals(false, this.region.containsKey("key1"));
// make sure a noop invalidate is repeatable read
// non-tx
this.region.remove("key1");
// non-tx
this.region.create("key1", null);
txMgrImpl.begin();
// should be a noop since it is already invalid
this.region.localInvalidate("key1");
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.remove("key1");
txMgrImpl.internalResume(tx);
assertEquals(true, this.region.containsKey("key1"));
assertEquals(false, this.region.containsValueForKey("key1"));
txMgrImpl.commit();
assertEquals(false, this.region.containsKey("key1"));
// make sure a destroy that throws entryNotFound is repeatable read
// non-tx
this.region.remove("key1");
txMgrImpl.begin();
try {
this.region.localDestroy("key1");
fail("expected EntryNotFoundException");
} catch (EntryNotFoundException expected) {
}
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.create("key1", "value1");
txMgrImpl.internalResume(tx);
assertEquals(false, this.region.containsKey("key1"));
txMgrImpl.commit();
assertEquals(true, this.region.containsKey("key1"));
// non-tx
this.region.remove("key1");
// make sure a create that throws entryExists is repeatable read
// non-tx
this.region.create("key1", "non-tx-value1");
txMgrImpl.begin();
try {
this.region.create("key1", "value1");
fail("expected EntryExistsException");
} catch (EntryExistsException expected) {
}
tx = txMgrImpl.internalSuspend();
// non-tx
this.region.remove("key1");
txMgrImpl.internalResume(tx);
assertEquals(true, this.region.containsKey("key1"));
txMgrImpl.commit();
assertEquals(false, this.region.containsKey("key1"));
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class LocalRegion method invalidateAllEntries.
/**
* @param rgnEvent the RegionEvent for region invalidation
*/
protected void invalidateAllEntries(RegionEvent rgnEvent) {
Operation operation = Operation.LOCAL_INVALIDATE;
if (rgnEvent.getOperation().isDistributed()) {
operation = Operation.INVALIDATE;
}
// region operation so it is ok to ignore tx state
for (Object keyObject : keySet()) {
try {
// EventID will not be generated by this constructor
@Released EntryEventImpl event = EntryEventImpl.create(this, operation, keyObject, null, null, rgnEvent.isOriginRemote(), rgnEvent.getDistributedMember());
try {
event.setLocalInvalid(!rgnEvent.getOperation().isDistributed());
basicInvalidate(event, false);
} finally {
event.release();
}
} catch (EntryNotFoundException ignore) {
// ignore
}
}
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class RemoveAllPRMessage method doLocalRemoveAll.
/**
* This method is called by both operateOnPartitionedRegion() when processing a remote msg or by
* sendMsgByBucket() when processing a msg targeted to local Jvm. PartitionedRegion Note: It is
* very important that this message does NOT cause any deadlocks as the sender will wait
* indefinitely for the acknowledgment
*
* @param r partitioned region
* @param eventSender the endpoint server who received request from client
* @param cacheWrite if true invoke cacheWriter before desrtoy
* @return If succeeds, return true, otherwise, throw exception
*/
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "IMSE_DONT_CATCH_IMSE")
public boolean doLocalRemoveAll(PartitionedRegion r, InternalDistributedMember eventSender, boolean cacheWrite) throws EntryExistsException, ForceReattemptException, DataLocationException {
boolean didRemove = false;
long clientReadTimeOut = PoolFactory.DEFAULT_READ_TIMEOUT;
if (r.hasServerProxy()) {
clientReadTimeOut = r.getServerProxy().getPool().getReadTimeout();
if (logger.isDebugEnabled()) {
logger.debug("RemoveAllPRMessage: doLocalRemoveAll: clientReadTimeOut is {}", clientReadTimeOut);
}
}
DistributedRemoveAllOperation op = null;
@Released EntryEventImpl baseEvent = null;
BucketRegion bucketRegion = null;
PartitionedRegionDataStore ds = r.getDataStore();
InternalDistributedMember myId = r.getDistributionManager().getDistributionManagerId();
try {
if (!notificationOnly) {
// bucketRegion is not null only when !notificationOnly
bucketRegion = ds.getInitializedBucketForId(null, bucketId);
this.versions = new VersionedObjectList(this.removeAllPRDataSize, true, bucketRegion.getAttributes().getConcurrencyChecksEnabled());
// create a base event and a DPAO for RemoveAllMessage distributed btw redundant buckets
baseEvent = EntryEventImpl.create(bucketRegion, Operation.REMOVEALL_DESTROY, null, null, this.callbackArg, true, eventSender, !skipCallbacks, true);
// set baseEventId to the first entry's event id. We need the thread id for DACE
baseEvent.setEventId(removeAllPRData[0].getEventID());
if (this.bridgeContext != null) {
baseEvent.setContext(this.bridgeContext);
}
baseEvent.setPossibleDuplicate(this.posDup);
if (logger.isDebugEnabled()) {
logger.debug("RemoveAllPRMessage.doLocalRemoveAll: eventSender is {}, baseEvent is {}, msg is {}", eventSender, baseEvent, this);
}
op = new DistributedRemoveAllOperation(baseEvent, removeAllPRDataSize, false);
}
// Fix the updateMsg misorder issue
// Lock the keys when doing postRemoveAll
Object[] keys = new Object[removeAllPRDataSize];
for (int i = 0; i < removeAllPRDataSize; ++i) {
keys[i] = removeAllPRData[i].getKey();
}
if (!notificationOnly) {
try {
if (removeAllPRData.length > 0) {
if (this.posDup && bucketRegion.getConcurrencyChecksEnabled()) {
if (logger.isDebugEnabled()) {
logger.debug("attempting to locate version tags for retried event");
}
// of the previous attempt
for (int i = 0; i < removeAllPRDataSize; i++) {
if (removeAllPRData[i].versionTag == null) {
removeAllPRData[i].versionTag = bucketRegion.findVersionTagForClientBulkOp(removeAllPRData[i].getEventID());
if (removeAllPRData[i].versionTag != null) {
removeAllPRData[i].versionTag.replaceNullIDs(bucketRegion.getVersionMember());
}
}
}
}
EventID eventID = removeAllPRData[0].getEventID();
ThreadIdentifier membershipID = new ThreadIdentifier(eventID.getMembershipID(), eventID.getThreadID());
bucketRegion.recordBulkOpStart(membershipID, eventID);
}
bucketRegion.waitUntilLocked(keys);
boolean lockedForPrimary = false;
final ArrayList<Object> succeeded = new ArrayList<Object>();
PutAllPartialResult partialKeys = new PutAllPartialResult(removeAllPRDataSize);
Object key = keys[0];
try {
bucketRegion.doLockForPrimary(false);
lockedForPrimary = true;
/*
* The real work to be synchronized, it will take long time. We don't worry about
* another thread to send any msg which has the same key in this request, because these
* request will be blocked by foundKey
*/
for (int i = 0; i < removeAllPRDataSize; i++) {
@Released EntryEventImpl ev = getEventFromEntry(r, myId, eventSender, i, removeAllPRData, notificationOnly, bridgeContext, posDup, skipCallbacks);
try {
key = ev.getKey();
ev.setRemoveAllOperation(op);
// then in basicPutPart3(), the ev is added into op
try {
r.getDataView().destroyOnRemote(ev, cacheWrite, null);
didRemove = true;
if (logger.isDebugEnabled()) {
logger.debug("RemoveAllPRMessage.doLocalRemoveAll:removeLocally success for " + ev);
}
} catch (EntryNotFoundException ignore) {
didRemove = true;
if (ev.getVersionTag() == null) {
if (logger.isDebugEnabled()) {
logger.debug("doLocalRemoveAll:RemoveAll encoutered EntryNotFoundException: event={}", ev);
}
}
} catch (ConcurrentCacheModificationException e) {
didRemove = true;
if (logger.isDebugEnabled()) {
logger.debug("RemoveAllPRMessage.doLocalRemoveAll:removeLocally encountered concurrent cache modification for " + ev);
}
}
removeAllPRData[i].setTailKey(ev.getTailKey());
if (!didRemove) {
// make sure the region hasn't gone away
r.checkReadiness();
ForceReattemptException fre = new ForceReattemptException("unable to perform remove in RemoveAllPR, but operation should not fail");
fre.setHash(ev.getKey().hashCode());
throw fre;
} else {
succeeded.add(removeAllPRData[i].getKey());
this.versions.addKeyAndVersion(removeAllPRData[i].getKey(), ev.getVersionTag());
}
} finally {
ev.release();
}
}
// for
} catch (IllegalMonitorStateException ex) {
ForceReattemptException fre = new ForceReattemptException("unable to get lock for primary, retrying... ");
throw fre;
} catch (CacheWriterException cwe) {
// encounter cacheWriter exception
partialKeys.saveFailedKey(key, cwe);
} finally {
try {
// Only RemoveAllPRMessage knows if the thread id is fake. Event has no idea.
// So we have to manually set useFakeEventId for this op
op.setUseFakeEventId(true);
r.checkReadiness();
bucketRegion.getDataView().postRemoveAll(op, this.versions, bucketRegion);
} finally {
if (lockedForPrimary) {
bucketRegion.doUnlockForPrimary();
}
}
}
if (partialKeys.hasFailure()) {
partialKeys.addKeysAndVersions(this.versions);
if (logger.isDebugEnabled()) {
logger.debug("RemoveAllPRMessage: partial keys applied, map to bucket {}'s keys:{}. Applied {}", bucketId, Arrays.toString(keys), succeeded);
}
throw new PutAllPartialResultException(partialKeys);
}
} catch (RegionDestroyedException e) {
ds.checkRegionDestroyedOnBucket(bucketRegion, true, e);
} finally {
bucketRegion.removeAndNotifyKeys(keys);
}
} else {
for (int i = 0; i < removeAllPRDataSize; i++) {
EntryEventImpl ev = getEventFromEntry(r, myId, eventSender, i, removeAllPRData, notificationOnly, bridgeContext, posDup, skipCallbacks);
try {
ev.setOriginRemote(true);
if (this.callbackArg != null) {
ev.setCallbackArgument(this.callbackArg);
}
r.invokeDestroyCallbacks(EnumListenerEvent.AFTER_DESTROY, ev, r.isInitialized(), true);
} finally {
ev.release();
}
}
}
} finally {
if (baseEvent != null)
baseEvent.release();
if (op != null)
op.freeOffHeapResources();
}
return true;
}
Aggregations