use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class EntryEventImpl method setOldValueFromRegion.
/** @return false if entry doesn't exist */
public boolean setOldValueFromRegion() {
try {
RegionEntry re = this.region.getRegionEntry(getKey());
if (re == null)
return false;
ReferenceCountHelper.skipRefCountTracking();
Object v = re._getValueRetain(this.region, true);
ReferenceCountHelper.unskipRefCountTracking();
try {
return setOldValue(v);
} finally {
if (mayHaveOffHeapReferences()) {
OffHeapHelper.releaseWithNoTracking(v);
}
}
} catch (EntryNotFoundException ignore) {
return false;
}
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class RemoteRemoveAllMessage method doLocalRemoveAll.
/* we need a event with content for waitForNodeOrCreateBucket() */
/**
* This method is called by both operateOnLocalRegion() when processing a remote msg or by
* sendMsgByBucket() when processing a msg targeted to local Jvm. LocalRegion 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
* @return If succeeds, return true, otherwise, throw exception
*/
public boolean doLocalRemoveAll(final LocalRegion r, final InternalDistributedMember eventSender) throws EntryExistsException, RemoteOperationException {
final DistributedRegion dr = (DistributedRegion) r;
// create a base event and a op for RemoveAllMessage distributed btw redundant buckets
@Released EntryEventImpl baseEvent = EntryEventImpl.create(r, Operation.REMOVEALL_DESTROY, null, null, this.callbackArg, false, eventSender, true);
try {
baseEvent.setCausedByMessage(this);
// set baseEventId to the first entry's event id. We need the thread id for DACE
baseEvent.setEventId(this.eventId);
if (this.bridgeContext != null) {
baseEvent.setContext(this.bridgeContext);
}
baseEvent.setPossibleDuplicate(this.posDup);
if (logger.isDebugEnabled()) {
logger.debug("RemoteRemoveAllMessage.doLocalRemoveAll: eventSender is {}, baseEvent is {}, msg is {}", eventSender, baseEvent, this);
}
final DistributedRemoveAllOperation op = new DistributedRemoveAllOperation(baseEvent, removeAllDataCount, false);
try {
final VersionedObjectList versions = new VersionedObjectList(removeAllDataCount, true, dr.concurrencyChecksEnabled);
dr.syncBulkOp(new Runnable() {
@SuppressWarnings("synthetic-access")
public void run() {
InternalDistributedMember myId = r.getDistributionManager().getDistributionManagerId();
for (int i = 0; i < removeAllDataCount; ++i) {
@Released EntryEventImpl ev = RemoveAllPRMessage.getEventFromEntry(r, myId, eventSender, i, removeAllData, false, bridgeContext, posDup, false);
try {
ev.setRemoveAllOperation(op);
if (logger.isDebugEnabled()) {
logger.debug("invoking basicDestroy with {}", ev);
}
try {
dr.basicDestroy(ev, true, null);
} catch (EntryNotFoundException ignore) {
}
removeAllData[i].versionTag = ev.getVersionTag();
versions.addKeyAndVersion(removeAllData[i].key, ev.getVersionTag());
} finally {
ev.release();
}
}
}
}, baseEvent.getEventId());
if (getTXUniqId() != TXManagerImpl.NOTX || dr.getConcurrencyChecksEnabled()) {
dr.getDataView().postRemoveAll(op, versions, dr);
}
RemoveAllReplyMessage.send(getSender(), this.processorId, getReplySender(r.getDistributionManager()), versions, this.removeAllData, this.removeAllDataCount);
return false;
} finally {
op.freeOffHeapResources();
}
} finally {
baseEvent.release();
}
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class RemoteInvalidateMessage method distribute.
public static boolean distribute(EntryEventImpl event, boolean onlyPersistent) {
boolean successful = false;
DistributedRegion r = (DistributedRegion) event.getRegion();
Collection replicates = onlyPersistent ? r.getCacheDistributionAdvisor().adviseInitializedPersistentMembers().keySet() : r.getCacheDistributionAdvisor().adviseInitializedReplicates();
if (replicates.isEmpty()) {
return false;
}
if (replicates.size() > 1) {
ArrayList l = new ArrayList(replicates);
Collections.shuffle(l);
replicates = l;
}
int attempts = 0;
for (Iterator<InternalDistributedMember> it = replicates.iterator(); it.hasNext(); ) {
InternalDistributedMember replicate = it.next();
try {
attempts++;
final boolean posDup = (attempts > 1);
InvalidateResponse processor = send(replicate, event.getRegion(), event, DistributionManager.SERIAL_EXECUTOR, false, posDup);
processor.waitForCacheException();
VersionTag versionTag = processor.getVersionTag();
if (versionTag != null) {
event.setVersionTag(versionTag);
if (event.getRegion().getVersionVector() != null) {
event.getRegion().getVersionVector().recordVersion(versionTag.getMemberID(), versionTag);
}
}
event.setInhibitDistribution(true);
return true;
} catch (TransactionDataNotColocatedException enfe) {
throw enfe;
} catch (CancelException e) {
event.getRegion().getCancelCriterion().checkCancelInProgress(e);
} catch (EntryNotFoundException e) {
throw new EntryNotFoundException("" + event.getKey());
} catch (CacheException e) {
if (logger.isDebugEnabled()) {
logger.debug("RemoteDestroyMessage caught CacheException during distribution", e);
}
// not a cancel-exception, so don't complain any more about it
successful = true;
} catch (RemoteOperationException e) {
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "RemoteDestroyMessage caught an unexpected exception during distribution", e);
}
}
}
return successful;
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class DiskRegionTestImpl method testBackupFillValues.
/**
* Tests fillValues on backup regions.
*
* Note: The regions in the following description all have the same unique name. 1) Create backup
* region in VM0 and add some values so they get backed up 2) Close that region 3) Create
* non-mirrored distributed region in VM1 and populate with over 1M of data 4) Create a mirrored
* KEYS region in VM2. This will cause VM2 to have all the keys but no values. 5) Re-create the
* backup region in VM0 with mirroring KEY_VALUES. This will get the keys from VM2 and the values
* from VM1 using fillValues. The region should end up with the keys created in step 1, and they
* should not be faulted into the VM.
*/
public void testBackupFillValues() throws CacheException {
RegionAttributes attrs = this.rtc.getRegionAttributes();
assertTrue("This test not appropriate for non-backup regions", attrs.getPersistBackup());
final String name = this.rtc.getUniqueName();
final String key1 = "KEY1";
final String key2 = "KEY2";
final String value1 = "VALUE1";
final String value2 = "VALUE2";
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// VM vm2 = host.getVM(2);
vm0.invoke(new CacheSerializableRunnable("Create backup Region in VM0") {
public void run2() throws CacheException {
Region rgn = DiskRegionTestImpl.this.rtc.createRegion(name);
rgn.create(key1, value1);
rgn.create(key2, value2);
// create entries that will be overwritten by getInitialImage below
rgn.create(new Integer(0), "TEMP-0");
rgn.create(new Integer(1), "TEMP-1");
// no longer to close cache in 6.5, otherwise the 2 vms will splitbrain
// CacheTestCase.closeCache();
}
});
vm1.invoke(new CacheSerializableRunnable("Create & Populate non-mirrored in VM1") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
// set scope to be same as test region
Scope scope = DiskRegionTestImpl.this.rtc.getRegionAttributes().getScope();
factory.setScope(scope);
DataPolicy dataPolicy = DiskRegionTestImpl.this.rtc.getRegionAttributes().getDataPolicy();
factory.setDataPolicy(dataPolicy);
RegionAttributes attrs2 = factory.create();
Region rgn = DiskRegionTestImpl.this.rtc.createRegion(name, attrs2);
// Fill the region with some keys.
for (int i = 0; i < NUM_ENTRIES; i++) {
byte[] value = new byte[VALUE_SIZE];
Arrays.fill(value, (byte) 0xAB);
rgn.put(new Integer(i), value);
}
// just for sanity:
assertEquals(NUM_ENTRIES + 2, rgn.keySet().size());
}
});
vm0.invoke(new CacheSerializableRunnable("Close Cache in VM0") {
public void run2() throws CacheException {
CacheTestCase.closeCache();
}
});
// vm2.invoke(new CacheSerializableRunnable("Create mirrored KEYS region in VM2") {
// public void run2() throws CacheException {
// AttributesFactory factory = new AttributesFactory();
// // set scope to be same as test region
// Scope scope = DiskRegionTestImpl.this.rtc.getRegionAttributes().getScope();
// factory.setScope(scope);
// // set mirror KEYS
// factory.setMirrorType(MirrorType.KEYS);
// RegionAttributes attrs2 = factory.create();
// Region rgn = DiskRegionTestImpl.this.rtc.createRegion(name, attrs2);
// }
// });
String runnableName = "Re-create backup region in VM0 with mirror " + "KEYS_VALUES and Do Verification";
vm0.invoke(new CacheSerializableRunnable(runnableName) {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory(DiskRegionTestImpl.this.rtc.getRegionAttributes());
factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
RegionAttributes attrs2 = factory.create();
// DebuggerSupport.waitForJavaDebugger(rtc.getLogWriter(), "About to create region...");
Region rgn = DiskRegionTestImpl.this.rtc.createRegion(name, attrs2);
// verify
assertEquals(NUM_ENTRIES + 2, rgn.keySet().size());
boolean RECOVER_VALUES = true;
if (RECOVER_VALUES) {
assertEquals(value1, rgn.getEntry(key1).getValue());
assertEquals(value2, rgn.getEntry(key2).getValue());
} else {
assertNull(valueInVM(rgn, key1));
assertNull(valueInVM(rgn, key2));
}
assertEquals(value1, valueOnDisk(rgn, key1));
assertEquals(value2, valueOnDisk(rgn, key2));
// The following also verifies TEMP values were overwritten
for (int i = 0; i < NUM_ENTRIES; i++) {
Region.Entry entry = rgn.getEntry(new Integer(i));
assertNotNull("No entry for key " + i, entry);
byte[] v = (byte[]) entry.getValue();
assertNotNull("Null value for key " + i, v);
assertEquals(VALUE_SIZE, v.length);
// test a byte
assertEquals((byte) 0xAB, v[i % VALUE_SIZE]);
}
rgn.close();
rgn = DiskRegionTestImpl.this.rtc.createRegion(name, attrs2);
// verify
assertEquals(NUM_ENTRIES + 2, rgn.keySet().size());
if (RECOVER_VALUES) {
assertEquals(value1, rgn.getEntry(key1).getValue());
assertEquals(value2, rgn.getEntry(key2).getValue());
} else {
assertNull(valueInVM(rgn, key1));
assertNull(valueInVM(rgn, key2));
}
assertEquals(value1, valueOnDisk(rgn, key1));
assertEquals(value2, valueOnDisk(rgn, key2));
// The following also verifies TEMP values were overwritten
for (int i = 0; i < NUM_ENTRIES; i++) {
Region.Entry entry = rgn.getEntry(new Integer(i));
assertNotNull("No entry for key " + i, entry);
byte[] v = (byte[]) entry.getValue();
assertNotNull("Null value for key " + i, v);
assertEquals(VALUE_SIZE, v.length);
// test a byte
assertEquals((byte) 0xAB, v[i % VALUE_SIZE]);
}
}
private Object valueInVM(Region rgn, Object key) throws EntryNotFoundException {
org.apache.geode.internal.cache.LocalRegion lrgn = (org.apache.geode.internal.cache.LocalRegion) rgn;
return lrgn.getValueInVM(key);
}
private Object valueOnDisk(Region rgn, Object key) throws EntryNotFoundException {
org.apache.geode.internal.cache.LocalRegion lrgn = (org.apache.geode.internal.cache.LocalRegion) rgn;
return lrgn.getValueOnDisk(key);
}
});
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class PartitionedRegion method destroyInBucket.
/**
* @param expectedOldValue only succeed if current value is equal to expectedOldValue
* @throws EntryNotFoundException if entry not found or if expectedOldValue not null and current
* value was not equal to expectedOldValue
*/
public void destroyInBucket(final EntryEventImpl event, Object expectedOldValue) throws EntryNotFoundException, CacheWriterException {
// Get the bucket id for the key
final Integer bucketId = event.getKeyInfo().getBucketId();
assert bucketId != KeyInfo.UNKNOWN_BUCKET;
// check in bucket2Node region
final InternalDistributedMember targetNode = getOrCreateNodeForBucketWrite(bucketId, null);
if (logger.isDebugEnabled()) {
logger.debug("destroyInBucket: key={} ({}) in node {} to bucketId={} retry={} ms", event.getKey(), event.getKey().hashCode(), targetNode, bucketStringForLogs(bucketId), retryTimeout);
}
// retry the put remotely until it finds the right node managing the bucket
RetryTimeKeeper retryTime = null;
InternalDistributedMember currentTarget = targetNode;
long timeOut = 0;
int count = 0;
for (; ; ) {
switch(count) {
case 0:
// First time, keep going
break;
case 1:
// First failure
this.cache.getCancelCriterion().checkCancelInProgress(null);
timeOut = System.currentTimeMillis() + this.retryTimeout;
break;
default:
this.cache.getCancelCriterion().checkCancelInProgress(null);
// test for timeout
long timeLeft = timeOut - System.currentTimeMillis();
if (timeLeft < 0) {
PRHARedundancyProvider.timedOut(this, null, null, "destroy an entry", this.retryTimeout);
// NOTREACHED
}
// Didn't time out. Sleep a bit and then continue
boolean interrupted = Thread.interrupted();
try {
Thread.sleep(PartitionedRegionHelper.DEFAULT_WAIT_PER_RETRY_ITERATION);
} catch (InterruptedException ignore) {
interrupted = true;
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
break;
}
count++;
if (currentTarget == null) {
// pick target
checkReadiness();
if (retryTime == null) {
retryTime = new RetryTimeKeeper(this.retryTimeout);
}
if (retryTime.overMaximum()) {
// }
if (getRegionAdvisor().getBucket(bucketId).getBucketAdvisor().basicGetPrimaryMember() == null) {
throw new EntryNotFoundException(LocalizedStrings.PartitionedRegion_ENTRY_NOT_FOUND_FOR_KEY_0.toLocalizedString(event.getKey()));
}
TimeoutException e = new TimeoutException(LocalizedStrings.PartitionedRegion_TIME_OUT_LOOKING_FOR_TARGET_NODE_FOR_DESTROY_WAITED_0_MS.toLocalizedString(retryTime.getRetryTime()));
if (logger.isDebugEnabled()) {
logger.debug(e.getMessage(), e);
}
checkReadiness();
throw e;
}
currentTarget = getOrCreateNodeForBucketWrite(bucketId, retryTime);
// No storage found for bucket, early out preventing hot loop, bug 36819
if (currentTarget == null) {
checkEntryNotFound(event.getKey());
}
continue;
}
// pick target
final boolean isLocal = (this.localMaxMemory > 0) && currentTarget.equals(getMyId());
try {
DistributedRemoveAllOperation savedOp = event.setRemoveAllOperation(null);
if (savedOp != null) {
savedOp.addEntry(event, bucketId);
return;
}
if (isLocal) {
// doCacheWriteBeforeDestroy(event);
event.setInvokePRCallbacks(true);
this.dataStore.destroyLocally(bucketId, event, expectedOldValue);
} else {
if (event.isBridgeEvent()) {
setNetworkHopType(bucketId, currentTarget);
}
destroyRemotely(currentTarget, bucketId, event, expectedOldValue);
}
return;
// NOTREACHED (success)
} catch (ConcurrentCacheModificationException e) {
if (logger.isDebugEnabled()) {
logger.debug("destroyInBucket: caught concurrent cache modification exception", e);
}
event.isConcurrencyConflict(true);
if (logger.isTraceEnabled()) {
logger.trace("ConcurrentCacheModificationException received for destroyInBucket for bucketId: {}{}{} for event: {} No reattempt is done, returning from here", getPRId(), BUCKET_ID_SEPARATOR, bucketId, event);
}
return;
} catch (ForceReattemptException e) {
e.checkKey(event.getKey());
// We don't know if the destroy took place or not at this point.
// Assume that if the next destroy throws EntryDestroyedException, the
// previous destroy attempt was a success
checkReadiness();
InternalDistributedMember lastNode = currentTarget;
if (retryTime == null) {
retryTime = new RetryTimeKeeper(this.retryTimeout);
}
currentTarget = getOrCreateNodeForBucketWrite(bucketId, retryTime);
event.setPossibleDuplicate(true);
if (lastNode.equals(currentTarget)) {
if (retryTime.overMaximum()) {
PRHARedundancyProvider.timedOut(this, null, null, "destroy an entry", retryTime.getRetryTime());
}
retryTime.waitToRetryNode();
}
} catch (PrimaryBucketException notPrimary) {
if (logger.isDebugEnabled()) {
logger.debug("destroyInBucket: {} on Node {} not primary", notPrimary.getLocalizedMessage(), currentTarget);
}
getRegionAdvisor().notPrimary(bucketId, currentTarget);
if (retryTime == null) {
retryTime = new RetryTimeKeeper(this.retryTimeout);
}
currentTarget = getOrCreateNodeForBucketWrite(bucketId, retryTime);
}
// If we get here, the attempt failed.
if (count == 1) {
this.prStats.incDestroyOpsRetried();
}
this.prStats.incDestroyRetries();
if (logger.isDebugEnabled()) {
logger.debug("destroyInBucket: Attempting to resend destroy to node {} after {} failed attempts", currentTarget, count);
}
}
// for
}
Aggregations