use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class GemFireCacheImpl method shutDownOnePRGracefully.
private void shutDownOnePRGracefully(PartitionedRegion partitionedRegion) {
boolean acquiredLock = false;
try {
partitionedRegion.acquireDestroyLock();
acquiredLock = true;
synchronized (partitionedRegion.getRedundancyProvider()) {
if (partitionedRegion.isDataStore() && partitionedRegion.getDataStore() != null && partitionedRegion.getDataPolicy() == DataPolicy.PERSISTENT_PARTITION) {
int numBuckets = partitionedRegion.getTotalNumberOfBuckets();
Map<InternalDistributedMember, PersistentMemberID>[] bucketMaps = new Map[numBuckets];
PartitionedRegionDataStore dataStore = partitionedRegion.getDataStore();
// lock all the primary buckets
Set<Entry<Integer, BucketRegion>> bucketEntries = dataStore.getAllLocalBuckets();
for (Entry e : bucketEntries) {
BucketRegion bucket = (BucketRegion) e.getValue();
if (bucket == null || bucket.isDestroyed) {
// bucket region could be destroyed in race condition
continue;
}
bucket.getBucketAdvisor().tryLockIfPrimary();
// get map <InternalDistributedMember, persistentID> for this bucket's
// remote members
bucketMaps[bucket.getId()] = bucket.getBucketAdvisor().adviseInitializedPersistentMembers();
if (logger.isDebugEnabled()) {
logger.debug("shutDownAll: PR {}: initialized persistent members for {}:{}", partitionedRegion.getName(), bucket.getId(), bucketMaps[bucket.getId()]);
}
}
if (logger.isDebugEnabled()) {
logger.debug("shutDownAll: All buckets for PR {} are locked.", partitionedRegion.getName());
}
// send lock profile update to other members
partitionedRegion.setShutDownAllStatus(PartitionedRegion.PRIMARY_BUCKETS_LOCKED);
new UpdateAttributesProcessor(partitionedRegion).distribute(false);
partitionedRegion.getRegionAdvisor().waitForProfileStatus(PartitionedRegion.PRIMARY_BUCKETS_LOCKED);
if (logger.isDebugEnabled()) {
logger.debug("shutDownAll: PR {}: all bucketLock profiles received.", partitionedRegion.getName());
}
// if async write, do flush
if (!partitionedRegion.getAttributes().isDiskSynchronous()) {
// several PRs might share the same diskStore, we will only flush once
// even flush is called several times.
partitionedRegion.getDiskStore().forceFlush();
// send flush profile update to other members
partitionedRegion.setShutDownAllStatus(PartitionedRegion.DISK_STORE_FLUSHED);
new UpdateAttributesProcessor(partitionedRegion).distribute(false);
partitionedRegion.getRegionAdvisor().waitForProfileStatus(PartitionedRegion.DISK_STORE_FLUSHED);
if (logger.isDebugEnabled()) {
logger.debug("shutDownAll: PR {}: all flush profiles received.", partitionedRegion.getName());
}
}
// async write
// persist other members to OFFLINE_EQUAL for each bucket region
// iterate through all the bucketMaps and exclude the items whose
// idm is no longer online
Set<InternalDistributedMember> membersToPersistOfflineEqual = partitionedRegion.getRegionAdvisor().adviseDataStore();
for (Entry e : bucketEntries) {
BucketRegion bucket = (BucketRegion) e.getValue();
if (bucket == null || bucket.isDestroyed) {
// bucket region could be destroyed in race condition
continue;
}
Map<InternalDistributedMember, PersistentMemberID> persistMap = getSubMapForLiveMembers(membersToPersistOfflineEqual, bucketMaps[bucket.getId()]);
if (persistMap != null) {
bucket.getPersistenceAdvisor().persistMembersOfflineAndEqual(persistMap);
if (logger.isDebugEnabled()) {
logger.debug("shutDownAll: PR {}: persisting bucket {}:{}", partitionedRegion.getName(), bucket.getId(), persistMap);
}
}
}
// send persisted profile update to other members, let all members to persist
// before close the region
partitionedRegion.setShutDownAllStatus(PartitionedRegion.OFFLINE_EQUAL_PERSISTED);
new UpdateAttributesProcessor(partitionedRegion).distribute(false);
partitionedRegion.getRegionAdvisor().waitForProfileStatus(PartitionedRegion.OFFLINE_EQUAL_PERSISTED);
if (logger.isDebugEnabled()) {
logger.debug("shutDownAll: PR {}: all offline_equal profiles received.", partitionedRegion.getName());
}
}
// dataStore
// after done all steps for buckets, close partitionedRegion
// close accessor directly
RegionEventImpl event = new RegionEventImpl(partitionedRegion, Operation.REGION_CLOSE, null, false, getMyId(), true);
try {
// not to acquire lock
partitionedRegion.basicDestroyRegion(event, false, false, true);
} catch (CacheWriterException e) {
// not possible with local operation, CacheWriter not called
throw new Error(LocalizedStrings.LocalRegion_CACHEWRITEREXCEPTION_SHOULD_NOT_BE_THROWN_IN_LOCALDESTROYREGION.toLocalizedString(), e);
} catch (TimeoutException e) {
// not possible with local operation, no distributed locks possible
throw new Error(LocalizedStrings.LocalRegion_TIMEOUTEXCEPTION_SHOULD_NOT_BE_THROWN_IN_LOCALDESTROYREGION.toLocalizedString(), e);
}
}
// synchronized
} catch (CacheClosedException cce) {
logger.debug("Encounter CacheClosedException when shutDownAll is closing PR: {}:{}", partitionedRegion.getFullPath(), cce.getMessage());
} catch (CancelException ce) {
logger.debug("Encounter CancelException when shutDownAll is closing PR: {}:{}", partitionedRegion.getFullPath(), ce.getMessage());
} catch (RegionDestroyedException rde) {
logger.debug("Encounter CacheDestroyedException when shutDownAll is closing PR: {}:{}", partitionedRegion.getFullPath(), rde.getMessage());
} finally {
if (acquiredLock) {
partitionedRegion.releaseDestroyLock();
}
}
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class MultiVMRegionTestCase method testCacheLoaderWithNetLoad.
@Test
public void testCacheLoaderWithNetLoad() throws Exception {
// replicated regions and partitioned regions make no sense for this
// test
assumeFalse(getRegionAttributes().getDataPolicy().withReplication());
assumeFalse(getRegionAttributes().getDataPolicy().isPreloaded());
assumeTrue(getRegionAttributes().getPartitionAttributes() == null);
final String name = this.getUniqueName();
final Object key = this.getUniqueName();
final Object value = new Integer(42);
Host host = Host.getHost(0);
// use vm on other gemfire system
VM vm1 = host.getVM(1);
vm1.invoke(new CacheSerializableRunnable("set up remote loader") {
@Override
public void run2() throws CacheException {
final TestCacheLoader remoteloader = new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
assertEquals(key, helper.getKey());
assertEquals(name, helper.getRegion().getName());
return value;
}
};
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
factory.setCacheLoader(remoteloader);
createRegion(name, factory.create());
}
});
final TestCacheLoader loader1 = new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
assertEquals(key, helper.getKey());
assertEquals(name, helper.getRegion().getName());
try {
helper.getRegion().getAttributes();
Object result = helper.netSearch(true);
assertEquals(value, result);
return result;
} catch (TimeoutException ex) {
fail("Why did I time out?", ex);
}
return null;
}
};
AttributesFactory f = new AttributesFactory(getRegionAttributes());
f.setCacheLoader(loader1);
Region region = createRegion(name, f.create());
loader1.wasInvoked();
Region.Entry entry = region.getEntry(key);
assertNull(entry);
region.create(key, null);
entry = region.getEntry(key);
assertNotNull(entry);
assertNull(entry.getValue());
assertEquals(value, region.get(key));
assertTrue(loader1.wasInvoked());
assertEquals(value, region.getEntry(key).getValue());
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class MultiVMRegionTestCase method testCacheLoaderWithNetSearch.
@Test
public void testCacheLoaderWithNetSearch() throws Exception {
assumeTrue(supportsNetLoad());
// some tests use mirroring by default (e.g. persistBackup regions)
// if so, then this test won't work right
assumeFalse(getRegionAttributes().getDataPolicy().withReplication());
assumeFalse(getRegionAttributes().getDataPolicy().isPreloaded());
final String name = this.getUniqueName();
final Object key = this.getUniqueName();
final Object value = new Integer(42);
Host host = Host.getHost(0);
// use vm on other gemfire system
VM vm1 = host.getVM(1);
vm1.invoke(new CacheSerializableRunnable("set remote value") {
@Override
public void run2() throws CacheException {
Region rgn = createRegion(name);
rgn.put(key, value);
flushIfNecessary(rgn);
}
});
final TestCacheLoader loader1 = new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
assertEquals(key, helper.getKey());
assertEquals(name, helper.getRegion().getName());
try {
helper.getRegion().getAttributes();
Object result = helper.netSearch(false);
assertEquals(value, result);
return result;
} catch (TimeoutException ex) {
fail("Why did I time out?", ex);
}
return null;
}
};
AttributesFactory f = new AttributesFactory(getRegionAttributes());
f.setCacheLoader(loader1);
Region region = createRegion(name, f.create());
loader1.wasInvoked();
Region.Entry entry = region.getEntry(key);
assertNull(entry);
region.create(key, null);
entry = region.getEntry(key);
assertNotNull(entry);
assertNull(entry.getValue());
// make sure value is still there in vm1
vm1.invoke(new CacheSerializableRunnable("verify remote value") {
@Override
public void run2() throws CacheException {
Region rgn = getRootRegion().getSubregion(name);
assertEquals(value, rgn.getEntry(key).getValue());
}
});
assertEquals(value, region.get(key));
// so we get the value but the loader is never invoked.
if (region.getAttributes().getScope().isGlobal()) {
assertTrue(!loader1.wasInvoked());
} else {
assertTrue(loader1.wasInvoked());
}
assertEquals(value, region.getEntry(key).getValue());
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class MultiVMRegionTestCase method testRemoteLoaderNetSearch.
/**
* Tests that invoking <code>netSearch</code> in a remote loader returns <code>null</code> instead
* of causing infinite recursion.
*/
@Test
public void testRemoteLoaderNetSearch() throws Exception {
assumeTrue(supportsNetLoad());
assertTrue(getRegionAttributes().getScope().isDistributed());
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("Get value") {
@Override
public void run2() throws CacheException {
Region region = createRegion(name);
assertEquals(value, region.get(key));
}
};
vm0.invoke(new CacheSerializableRunnable("Create Region") {
@Override
public void run2() throws CacheException {
Region region = createRegion(name);
region.getAttributesMutator().setCacheLoader(new TestCacheLoader() {
@Override
public Object load2(LoaderHelper helper) throws CacheLoaderException {
try {
assertNull(helper.netSearch(true));
} catch (TimeoutException ex) {
fail("Why did I time out?", ex);
}
return value;
}
});
}
});
vm1.invoke(create);
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class SearchAndLoadDUnitTest method testOneHopNetWriteRemoteWriter.
/** same as the previous test but the cache writer is in a third, non-replicated, vm */
@Test
public void testOneHopNetWriteRemoteWriter() throws CacheException, InterruptedException {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final String name = this.getUniqueName() + "Region";
final String objectName = "Object7";
final Integer value = new Integer(483);
final Integer updateValue = new Integer(484);
vm0.invoke(new SerializableRunnable("Create replicate Region") {
public void run() {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating empty region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("Create empty Region") {
public void run() {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.EMPTY);
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating empty region", ex);
}
}
});
vm2.invoke(new SerializableRunnable("Create replicated region with cacheWriter") {
public void run() {
netWriteInvoked = false;
operationWasCreate = false;
originWasRemote = false;
writerInvocationCount = 0;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.EMPTY);
factory.setCacheWriter(new CacheWriter() {
public void beforeCreate(EntryEvent e) throws CacheWriterException {
e.getRegion().getCache().getLogger().info("cache writer beforeCreate invoked for " + e);
netWriteInvoked = true;
operationWasCreate = true;
originWasRemote = e.isOriginRemote();
writerInvocationCount++;
return;
}
public void beforeUpdate(EntryEvent e) throws CacheWriterException {
e.getRegion().getCache().getLogger().info("cache writer beforeUpdate invoked for " + e);
netWriteInvoked = true;
operationWasCreate = false;
originWasRemote = e.isOriginRemote();
writerInvocationCount++;
return;
}
public void beforeDestroy(EntryEvent e) throws CacheWriterException {
}
public void beforeRegionDestroy(RegionEvent e) throws CacheWriterException {
}
public void beforeRegionClear(RegionEvent e) throws CacheWriterException {
}
public void close() {
}
});
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating replicated region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("do a put that should be proxied in the other vm and invoke its cache writer") {
public void run() {
try {
getRootRegion().getSubregion(name).put(objectName, value);
} catch (CacheWriterException cwe) {
} catch (TimeoutException te) {
}
}
});
vm2.invoke(new SerializableRunnable("ensure that cache writer was invoked with correct settings in event") {
public void run() {
assertTrue("expected cache writer to be invoked", netWriteInvoked);
assertTrue("expected originRemote to be true", originWasRemote);
assertTrue("expected event to be create", operationWasCreate);
assertEquals("expected only one cache writer invocation", 1, writerInvocationCount);
// set flags for the next test - updating the same key
netWriteInvoked = false;
writerInvocationCount = 0;
}
});
vm1.invoke(new SerializableRunnable("do an update that should be proxied in the other vm and invoke its cache writer") {
public void run() {
try {
getRootRegion().getSubregion(name).put(objectName, updateValue);
} catch (CacheWriterException cwe) {
} catch (TimeoutException te) {
}
}
});
vm2.invoke(new SerializableRunnable("ensure that cache writer was invoked with correct settings in event") {
public void run() {
assertTrue("expected cache writer to be invoked", netWriteInvoked);
assertTrue("expected originRemote to be true", originWasRemote);
assertTrue("expected event to be create", operationWasCreate);
assertEquals("expected only one cache writer invocation", 1, writerInvocationCount);
}
});
}
Aggregations