use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class PartitionedRegion method updateEntryVersionInBucket.
public void updateEntryVersionInBucket(EntryEventImpl event) {
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) {
this.dataStore.updateEntryVersionLocally(bucketId, event);
} else {
updateEntryVersionRemotely(retryNode, bucketId, event);
}
return;
} catch (ConcurrentCacheModificationException e) {
if (isDebugEnabled) {
logger.debug("updateEntryVersionInBucket: caught concurrent cache modification exception", e);
}
event.isConcurrencyConflict(true);
if (isDebugEnabled) {
logger.debug("ConcurrentCacheModificationException received for updateEntryVersionInBucket 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("updateEntryVersionInBucket: 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();
}
} catch (PrimaryBucketException notPrimary) {
if (isDebugEnabled) {
logger.debug("updateEntryVersionInBucket {} on Node {} not primary", notPrimary.getLocalizedMessage(), retryNode);
}
getRegionAdvisor().notPrimary(bucketId, retryNode);
retryNode = getOrCreateNodeForBucketWrite(bucketId, retryTime);
}
count++;
if (isDebugEnabled) {
logger.debug("updateEntryVersionInBucket: Attempting to resend update version to node {} after {} failed attempts", retryNode, count);
}
}
// while
// No target was found
PartitionedRegionDistributionException e = new PartitionedRegionDistributionException(LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_UPDATE_ENTRY_VERSION_IN_0_ATTEMPTS.toLocalizedString(// Fix for bug 36014
count));
if (!isDebugEnabled) {
logger.warn(LocalizedMessage.create(LocalizedStrings.PartitionedRegion_NO_VM_AVAILABLE_FOR_UPDATE_ENTRY_VERSION_IN_0_ATTEMPTS, count));
} else {
logger.warn(e.getMessage(), e);
}
throw e;
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class PartitionedRegion method getBucketKeys.
/**
* Fetch the keys for the given bucket identifier, if the bucket is local or remote. This version
* of the method allows you to retrieve Tombstone entries as well as undestroyed entries.
*
* @param allowTombstones whether to include destroyed entries in the result
* @return A set of keys from bucketNum or {@link Collections#EMPTY_SET}if no keys can be found.
*/
public Set getBucketKeys(int bucketNum, boolean allowTombstones) {
Integer buck = bucketNum;
final int retryAttempts = calcRetry();
Set ret = null;
int count = 0;
InternalDistributedMember nod = getOrCreateNodeForBucketRead(bucketNum);
RetryTimeKeeper snoozer = null;
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 (nod == null) {
if (snoozer == null) {
snoozer = new RetryTimeKeeper(this.retryTimeout);
}
nod = getOrCreateNodeForBucketRead(bucketNum);
// No storage found for bucket, early out preventing hot loop, bug 36819
if (nod == null) {
checkShutdown();
break;
}
count++;
continue;
}
try {
if (nod.equals(getMyId())) {
ret = this.dataStore.getKeysLocally(buck, allowTombstones);
} else {
FetchKeysResponse r = FetchKeysMessage.send(nod, this, buck, allowTombstones);
ret = r.waitForKeys();
}
if (ret != null) {
return ret;
}
} catch (PRLocallyDestroyedException ignore) {
if (logger.isDebugEnabled()) {
logger.debug("getBucketKeys: Encountered PRLocallyDestroyedException");
}
checkReadiness();
} catch (ForceReattemptException prce) {
if (logger.isDebugEnabled()) {
logger.debug("getBucketKeys: attempt:{}", (count + 1), prce);
}
checkReadiness();
if (snoozer == null) {
snoozer = new RetryTimeKeeper(this.retryTimeout);
}
InternalDistributedMember oldNode = nod;
nod = getNodeForBucketRead(buck);
if (nod != null && nod.equals(oldNode)) {
if (snoozer.overMaximum()) {
checkReadiness();
throw new TimeoutException(LocalizedStrings.PartitionedRegion_ATTEMPT_TO_ACQUIRE_PRIMARY_NODE_FOR_READ_ON_BUCKET_0_TIMED_OUT_IN_1_MS.toLocalizedString(new Object[] { getBucketName(buck), snoozer.getRetryTime() }));
}
snoozer.waitToRetryNode();
}
}
count++;
}
if (logger.isDebugEnabled()) {
logger.debug("getBucketKeys: no keys found returning empty set");
}
return Collections.emptySet();
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class GlobalRegionDUnitTest method testPutGetTimeout.
/**
* Tests that {@link Region#put} and {@link Region#get} timeout when another VM holds the
* distributed lock on the entry in question.
*/
@Test
public void testPutGetTimeout() {
assertEquals(Scope.GLOBAL, getRegionAttributes().getScope());
final String name = this.getUniqueName();
final Object key = "KEY";
final Object value = "VALUE";
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
SerializableRunnable create = new CacheSerializableRunnable("Create Region") {
public void run2() throws CacheException {
createRegion(name);
}
};
vm0.invoke(create);
vm1.invoke(create);
vm0.invoke(new CacheSerializableRunnable("Lock entry") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
Lock lock = region.getDistributedLock(key);
lock.lock();
}
});
vm1.invoke(new CacheSerializableRunnable("Attempt get/put") {
public void run2() throws CacheException {
Cache cache = getCache();
cache.setLockTimeout(1);
cache.setSearchTimeout(1);
Region region = getRootRegion().getSubregion(name);
try {
region.put(key, value);
fail("Should have thrown a TimeoutException on put");
} catch (TimeoutException ex) {
// pass..
}
// With a loader, should try to lock and time out
region.getAttributesMutator().setCacheLoader(new TestCacheLoader() {
public Object load2(LoaderHelper helper) {
return null;
}
});
try {
region.get(key);
fail("Should have thrown a TimeoutException on get");
} catch (TimeoutException ex) {
// pass..
}
// Without a loader, should succeed
region.getAttributesMutator().setCacheLoader(null);
region.get(key);
}
});
vm0.invoke(new CacheSerializableRunnable("Unlock entry") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
Lock lock = region.getDistributedLock(key);
lock.unlock();
}
});
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class GlobalLockingDUnitTest method testPutLockTimeout.
/**
* get the lock in one VM, try to put() in other
*/
@Test
public void testPutLockTimeout() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final String name = this.getUniqueName();
final Object key = new Integer(5);
vm0.invoke(new CacheSerializableRunnable("Get lock") {
public void run2() throws CacheException {
Region r = getOrCreateRootRegion().createSubregion(name, getGlobalAttrs());
Lock lock = r.getDistributedLock(key);
lock.lock();
}
});
vm1.invoke(new CacheSerializableRunnable("Lock timeout putting entry") {
public void run2() throws CacheException {
getOrCreateRootRegion().getCache().setLockTimeout(2);
Region r = getOrCreateRootRegion().createSubregion(name, getGlobalAttrs());
try {
r.put(key, "the value");
fail("put() should have thrown TimeoutException");
} catch (TimeoutException ex) {
// pass
}
}
});
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class GlobalLockingDUnitTest method testInvalidateLockTimeout.
/**
* get lock in one VM, try to invalidate in other
*/
@Test
public void testInvalidateLockTimeout() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final String name = this.getUniqueName();
final Object key = new Integer(5);
vm0.invoke(new CacheSerializableRunnable("Get lock") {
public void run2() throws CacheException {
Region r = getOrCreateRootRegion().createSubregion(name, getGlobalAttrs());
Lock lock = r.getDistributedLock(key);
lock.lock();
}
});
vm1.invoke(new CacheSerializableRunnable("Lock timeout invalidating entry") {
public void run2() throws CacheException {
getOrCreateRootRegion().getCache().setLockTimeout(2);
Region r = getOrCreateRootRegion().createSubregion(name, getGlobalAttrs());
try {
r.invalidate(key);
fail("invalidate() should have thrown TimeoutException");
} catch (TimeoutException ex) {
// pass
}
}
});
}
Aggregations