use of org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testReplaceOfflineMemberAndRestart.
@Test
public void testReplaceOfflineMemberAndRestart() throws Throwable {
SerializableRunnable createPRs = new SerializableRunnable("region1") {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
final CountDownLatch recoveryDone = new CountDownLatch(2);
ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {
@Override
public void recoveryFinished(Region region) {
recoveryDone.countDown();
}
};
InternalResourceManager.setResourceObserver(observer);
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
paf.setColocatedWith(PR_REGION_NAME);
af.setPartitionAttributes(paf.create());
cache.createRegion("region2", af.create());
try {
if (!recoveryDone.await(MAX_WAIT, TimeUnit.MILLISECONDS)) {
fail("timed out");
}
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
}
}
};
replaceOfflineMemberAndRestart(createPRs);
}
use of org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testReplaceOfflineMemberAndRestartTwoDiskStores.
/**
* Test that if we replace an offline member, even if colocated regions are in different disk
* stores, we still keep our metadata consistent.
*
* @throws Throwable
*/
@Test
public void testReplaceOfflineMemberAndRestartTwoDiskStores() throws Throwable {
SerializableRunnable createPRs = new SerializableRunnable("region1") {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
final CountDownLatch recoveryDone = new CountDownLatch(2);
ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {
@Override
public void recoveryFinished(Region region) {
recoveryDone.countDown();
}
};
InternalResourceManager.setResourceObserver(observer);
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
DiskStore ds2 = cache.findDiskStore("disk2");
if (ds2 == null) {
ds2 = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk2");
}
paf.setColocatedWith(PR_REGION_NAME);
af.setPartitionAttributes(paf.create());
af.setDiskStoreName("disk2");
cache.createRegion("region2", af.create());
try {
if (!recoveryDone.await(MAX_WAIT, TimeUnit.MILLISECONDS)) {
fail("timed out");
}
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
}
}
};
replaceOfflineMemberAndRestart(createPRs);
}
use of org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver in project geode by apache.
the class PersistentColocatedPartitionedRegionDUnitTest method testReplaceOfflineMemberAndRestartCreateColocatedPRLateTwoDiskStores.
@Test
public void testReplaceOfflineMemberAndRestartCreateColocatedPRLateTwoDiskStores() throws Throwable {
SerializableRunnable createParentPR = new SerializableRunnable() {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(0);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
}
};
SerializableRunnable createChildPR = new SerializableRunnable() {
public void run() {
Cache cache = getCache();
final CountDownLatch recoveryDone = new CountDownLatch(1);
ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {
@Override
public void recoveryFinished(Region region) {
if (region.getName().contains("region2")) {
recoveryDone.countDown();
}
}
};
InternalResourceManager.setResourceObserver(observer);
DiskStore ds2 = cache.findDiskStore("disk2");
if (ds2 == null) {
ds2 = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk2");
}
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(0);
paf.setColocatedWith(PR_REGION_NAME);
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk2");
af.setPartitionAttributes(paf.create());
cache.createRegion("region2", af.create());
try {
if (!recoveryDone.await(MAX_WAIT, TimeUnit.MILLISECONDS)) {
fail("timed out");
}
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
}
}
};
replaceOfflineMemberAndRestartCreateColocatedPRLate(createParentPR, createChildPR);
}
use of org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver in project geode by apache.
the class PersistentPartitionedRegionTestBase method createCoLocatedPR.
protected void createCoLocatedPR(VM vm, int setRedundantCopies, boolean setPersistenceAdvisorObserver) {
vm.invoke(() -> {
Cache cache = getCache();
// Wait for both nested PRs to be created
final CountDownLatch recoveryDone = new CountDownLatch(2);
ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {
@Override
public void recoveryFinished(Region region) {
recoveryDone.countDown();
}
};
InternalResourceManager.setResourceObserver(observer);
// Wait for parent and child region to be created.
// And throw exception while region is getting initialized.
final CountDownLatch childRegionCreated = new CountDownLatch(1);
if (setPersistenceAdvisorObserver) {
PersistenceAdvisorImpl.setPersistenceAdvisorObserver(new PersistenceAdvisorImpl.PersistenceAdvisorObserver() {
public void observe(String regionPath) {
if (regionPath.contains(PR_CHILD_REGION_NAME)) {
try {
childRegionCreated.await(MAX_WAIT, TimeUnit.MILLISECONDS);
} catch (Exception e) {
Assert.fail("Exception", e);
}
throw new ConflictingPersistentDataException("Testing Cache Close with ConflictingPersistentDataException for region." + regionPath);
}
}
});
}
// Create region.
try {
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
// Parent Region
PartitionAttributesFactory paf = new PartitionAttributesFactory().setRedundantCopies(setRedundantCopies);
AttributesFactory af = new AttributesFactory();
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
// Colocated region
paf = (new PartitionAttributesFactory()).setRedundantCopies(setRedundantCopies).setColocatedWith(PR_REGION_NAME);
af = new AttributesFactory();
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_CHILD_REGION_NAME, af.create());
// Count down on region create.
childRegionCreated.countDown();
try {
recoveryDone.await(MAX_WAIT, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
}
} finally {
PersistenceAdvisorImpl.setPersistenceAdvisorObserver(null);
}
});
}
use of org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver in project geode by apache.
the class PersistentPartitionedRegionTestBase method getNestedPRRunnable.
private SerializableRunnable getNestedPRRunnable() {
SerializableRunnable createPR = new SerializableRunnable("create pr") {
public void run() {
Cache cache = getCache();
// Wait for both nested PRs to be created
final CountDownLatch recoveryDone = new CountDownLatch(2);
ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {
@Override
public void recoveryFinished(Region region) {
recoveryDone.countDown();
}
};
InternalResourceManager.setResourceObserver(observer);
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
Region parent1;
{
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
parent1 = cache.createRegion("parent1", af.create());
}
Region parent2;
{
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
parent2 = cache.createRegion("parent2", af.create());
}
{
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
parent1.createSubregion(PR_REGION_NAME, af.create());
}
{
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
parent2.createSubregion(PR_REGION_NAME, af.create());
}
try {
recoveryDone.await(MAX_WAIT, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
}
}
};
return createPR;
}
Aggregations