Search in sources :

Example 6 with ResourceObserver

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);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CountDownLatch(java.util.concurrent.CountDownLatch) Cache(org.apache.geode.cache.Cache) ResourceObserver(org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 7 with ResourceObserver

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);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CountDownLatch(java.util.concurrent.CountDownLatch) Cache(org.apache.geode.cache.Cache) ResourceObserver(org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 8 with ResourceObserver

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);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CountDownLatch(java.util.concurrent.CountDownLatch) Cache(org.apache.geode.cache.Cache) ResourceObserver(org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 9 with ResourceObserver

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);
        }
    });
}
Also used : PersistenceAdvisorImpl(org.apache.geode.internal.cache.persistence.PersistenceAdvisorImpl) CountDownLatch(java.util.concurrent.CountDownLatch) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IOException(java.io.IOException) ResourceObserver(org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver) DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) Cache(org.apache.geode.cache.Cache)

Example 10 with ResourceObserver

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;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) CountDownLatch(java.util.concurrent.CountDownLatch) Cache(org.apache.geode.cache.Cache) ResourceObserver(org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)11 Region (org.apache.geode.cache.Region)11 ResourceObserver (org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver)11 Cache (org.apache.geode.cache.Cache)10 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)10 AttributesFactory (org.apache.geode.cache.AttributesFactory)9 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 DiskStore (org.apache.geode.cache.DiskStore)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Test (org.junit.Test)5 DiskRegion (org.apache.geode.internal.cache.DiskRegion)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 AdminException (org.apache.geode.admin.AdminException)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 ConflictingPersistentDataException (org.apache.geode.cache.persistence.ConflictingPersistentDataException)1