Search in sources :

Example 6 with ConflictingPersistentDataException

use of org.apache.geode.cache.persistence.ConflictingPersistentDataException in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testCleanupAfterConflict.

@Test
public void testCleanupAfterConflict() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    createPR(vm0, 0);
    // create some buckets
    createData(vm0, 0, 2, "a");
    closePR(vm0);
    createPR(vm1, 0);
    // create an overlapping bucket
    createData(vm1, 1, 2, "a");
    IgnoredException[] expectVm0 = { IgnoredException.addIgnoredException("ConflictingPersistentDataException", vm0), IgnoredException.addIgnoredException("CacheClosedException", vm0) };
    try {
        // This results in ConflictingPersistentDataException. As part of
        // GEODE-2918, the cache is closed, when ConflictingPersistentDataException
        // is encountered.
        createPR(vm0, 0);
        fail("should have seen a conflicting data exception");
    } catch (Exception ex) {
        boolean expectedException = false;
        if (ex.getCause() instanceof CacheClosedException) {
            CacheClosedException cce = (CacheClosedException) ex.getCause();
            if (cce.getCause() instanceof ConflictingPersistentDataException) {
                expectedException = true;
            }
        }
        if (!expectedException) {
            throw ex;
        }
    } finally {
        for (IgnoredException ie : expectVm0) {
            ie.remove();
        }
    }
    IgnoredException expectVm1 = IgnoredException.addIgnoredException("PartitionOfflineException", vm1);
    try {
        createData(vm1, 0, 1, "a");
    } catch (Exception e) {
        // restart.
        if (!(e.getCause() instanceof PartitionOfflineException)) {
            throw e;
        }
    } finally {
        expectVm1.remove();
    }
    closePR(vm1);
    // This should succeed, vm0 should not have persisted any view
    // information from vm1
    createPR(vm0, 0);
    checkData(vm0, 0, 2, "a");
    checkData(vm0, 2, 3, null);
}
Also used : PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) VM(org.apache.geode.test.dunit.VM) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) RevokeFailedException(org.apache.geode.cache.persistence.RevokeFailedException) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) DiskAccessException(org.apache.geode.cache.DiskAccessException) ConcurrentModificationException(java.util.ConcurrentModificationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) RMIException(org.apache.geode.test.dunit.RMIException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) QueryException(org.apache.geode.cache.query.QueryException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 7 with ConflictingPersistentDataException

use of org.apache.geode.cache.persistence.ConflictingPersistentDataException in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testDiskConflictWithRedundancy.

@Test
public void testDiskConflictWithRedundancy() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    createPR(vm0, 1);
    // create some buckets
    createData(vm0, 0, 2, "a");
    closePR(vm0);
    createPR(vm1, 1);
    // create an overlapping bucket
    createData(vm1, 1, 2, "a");
    IgnoredException[] expectVm0 = { IgnoredException.addIgnoredException("ConflictingPersistentDataException", vm0), IgnoredException.addIgnoredException("CacheClosedException", vm0) };
    try {
        createPR(vm0, 1);
        fail("should have seen a conflicting data exception");
    } catch (Exception ex) {
        boolean expectedException = false;
        if (ex.getCause() instanceof CacheClosedException) {
            CacheClosedException cce = (CacheClosedException) ex.getCause();
            if (cce.getCause() instanceof ConflictingPersistentDataException) {
                expectedException = true;
            }
        }
        if (!expectedException) {
            throw ex;
        }
    } finally {
        for (IgnoredException ie : expectVm0) {
            ie.remove();
        }
    }
    closePR(vm1);
}
Also used : VM(org.apache.geode.test.dunit.VM) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) RevokeFailedException(org.apache.geode.cache.persistence.RevokeFailedException) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) DiskAccessException(org.apache.geode.cache.DiskAccessException) ConcurrentModificationException(java.util.ConcurrentModificationException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) RMIException(org.apache.geode.test.dunit.RMIException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) QueryException(org.apache.geode.cache.query.QueryException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 8 with ConflictingPersistentDataException

use of org.apache.geode.cache.persistence.ConflictingPersistentDataException 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)

Aggregations

ConflictingPersistentDataException (org.apache.geode.cache.persistence.ConflictingPersistentDataException)8 Host (org.apache.geode.test.dunit.Host)5 IgnoredException (org.apache.geode.test.dunit.IgnoredException)5 VM (org.apache.geode.test.dunit.VM)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 RevokedPersistentDataException (org.apache.geode.cache.persistence.RevokedPersistentDataException)4 ConcurrentModificationException (java.util.ConcurrentModificationException)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 DiskAccessException (org.apache.geode.cache.DiskAccessException)3 PartitionedRegionStorageException (org.apache.geode.cache.PartitionedRegionStorageException)3 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)3 PartitionOfflineException (org.apache.geode.cache.persistence.PartitionOfflineException)3 RevokeFailedException (org.apache.geode.cache.persistence.RevokeFailedException)3 QueryException (org.apache.geode.cache.query.QueryException)3 ReplyException (org.apache.geode.distributed.internal.ReplyException)3 RMIException (org.apache.geode.test.dunit.RMIException)3 CountDownLatch (java.util.concurrent.CountDownLatch)1