Search in sources :

Example 11 with DistributionMessageObserver

use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.

the class PersistentColocatedPartitionedRegionDUnitTest method testCrashDuringRedundancySatisfaction.

/**
   * Test what happens when we crash in the middle of satisfying redundancy for a colocated bucket.
   * 
   * @throws Throwable
   */
// This test method is disabled because it is failing
// periodically and causing cruise control failures
// See bug #46748
@Test
public void testCrashDuringRedundancySatisfaction() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    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");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            // Workaround for 44414 - disable recovery delay so we shutdown
            // vm1 at a predictable point.
            paf.setRecoveryDelay(-1);
            paf.setStartupRecoveryDelay(-1);
            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());
        }
    };
    // Create the PR on vm0
    vm0.invoke(createPRs);
    // Create some buckets.
    createData(vm0, 0, NUM_BUCKETS, "a");
    createData(vm0, 0, NUM_BUCKETS, "a", "region2");
    vm1.invoke(createPRs);
    // We shouldn't have created any buckets in vm1 yet.
    assertEquals(Collections.emptySet(), getBucketList(vm1));
    // Add an observer that will disconnect before allowing the peer to
    // GII a colocated bucket. This should leave the peer with only the parent
    // bucket
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        if (((RequestImageMessage) message).regionPath.contains("region2")) {
                            DistributionMessageObserver.setInstance(null);
                            disconnectFromDS();
                        }
                    }
                }
            });
        }
    });
    IgnoredException ex = IgnoredException.addIgnoredException("PartitionOfflineException", vm1);
    try {
        // as we satisfy redundancy with vm1.
        try {
            RebalanceResults rr = rebalance(vm1);
        } catch (Exception expected) {
            // disconnect
            if (!(expected.getCause() instanceof PartitionOfflineException)) {
                throw expected;
            }
        }
        // Wait for vm0 to be closed by the callback
        vm0.invoke(new SerializableCallable() {

            public Object call() throws Exception {
                Wait.waitForCriterion(new WaitCriterion() {

                    public boolean done() {
                        InternalDistributedSystem ds = basicGetSystem();
                        return ds == null || !ds.isConnected();
                    }

                    public String description() {
                        return "DS did not disconnect";
                    }
                }, MAX_WAIT, 100, true);
                return null;
            }
        });
        // close the cache in vm1
        SerializableCallable disconnectFromDS = new SerializableCallable() {

            public Object call() throws Exception {
                disconnectFromDS();
                return null;
            }
        };
        vm1.invoke(disconnectFromDS);
        // Make sure vm0 is disconnected. This avoids a race where we
        // may still in the process of disconnecting even though the our async listener
        // found the system was disconnected
        vm0.invoke(disconnectFromDS);
    } finally {
        ex.remove();
    }
    // Create the cache and PRs on both members
    AsyncInvocation async0 = vm0.invokeAsync(createPRs);
    AsyncInvocation async1 = vm1.invokeAsync(createPRs);
    async0.getResult(MAX_WAIT);
    async1.getResult(MAX_WAIT);
    // Make sure the data was recovered correctly
    checkData(vm0, 0, NUM_BUCKETS, "a");
    // Workaround for bug 46748.
    checkData(vm0, 0, NUM_BUCKETS, "a", "region2");
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) 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) IOException(java.io.IOException) DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 12 with DistributionMessageObserver

use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.

the class PersistentPartitionedRegionDUnitTest method testCrashDuringBucketGII.

/**
   * A test for bug 41436. If the GII source crashes before the GII is complete, we need to make
   * sure that later we can recover redundancy.
   */
@Test
public void testCrashDuringBucketGII() {
    IgnoredException.addIgnoredException("PartitionOfflineException");
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    createPR(vm0, 1);
    createData(vm0, 0, 1, "value");
    // Add an observer which will close the cache when the GII starts
    vm0.invoke(new SerializableRunnable("Set crashing observer") {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        RequestImageMessage rim = (RequestImageMessage) message;
                        if (rim.regionPath.contains("_0")) {
                            DistributionMessageObserver.setInstance(null);
                            getCache().close();
                        }
                    }
                }
            });
        }
    });
    createPR(vm1, 1);
    // Make sure vm1 didn't create the bucket
    assertEquals(Collections.emptySet(), getBucketList(vm1));
    createPR(vm0, 1, 0);
    // Make sure vm0 recovers the bucket
    assertEquals(Collections.singleton(0), getBucketList(vm0));
    // vm1 should satisfy redundancy for the bucket as well
    assertEquals(Collections.singleton(0), getBucketList(vm1));
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 13 with DistributionMessageObserver

use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testCrashDuringPreparePersistentId.

// GEODE-1703: fails assertion: Region not created within30000
@Category(FlakyTest.class)
@Test
public void testCrashDuringPreparePersistentId() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Add a hook which will disconnect from the distributed
    // system when the initial image message shows up.
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof PrepareNewPersistentMemberMessage) {
                        DistributionMessageObserver.setInstance(null);
                        disconnectFromDS();
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    createPersistentRegion(vm0);
    putAnEntry(vm0);
    updateTheEntry(vm0);
    AsyncInvocation async1 = createPersistentRegionAsync(vm1);
    // Wait for vm 1 to get stuck waiting for vm0, because vm0 has crashed
    waitForBlockedInitialization(vm1);
    // closeCache(vm0);
    closeCache(vm1);
    try {
        async1.getResult();
        fail("Should have seen a CacheClosedException");
    } catch (AssertionError e) {
        if (!CacheClosedException.class.isInstance(getRootCause(e))) {
            throw e;
        }
    }
    createPersistentRegion(vm0);
    createPersistentRegion(vm1);
    ;
    checkForEntry(vm0);
    checkForEntry(vm1);
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 14 with DistributionMessageObserver

use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.

the class DistributedLockServiceDUnitTest method testDestroyLockServiceAfterGrantResponse.

@Test
public void testDestroyLockServiceAfterGrantResponse() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    final String serviceName = getUniqueName();
    vm0.invoke(new SerializableRunnable("Create the grantor") {

        public void run() {
            connectDistributedSystem();
            final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
            // lock and unlock to make sure this vm is grantor
            assertTrue(service.lock("obj", -1, -1));
            service.unlock("obj");
        }
    });
    DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

        @Override
        public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
            if (message instanceof DLockResponseMessage) {
                DistributedLockService.destroy(serviceName);
            }
        }
    });
    connectDistributedSystem();
    final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
    try {
        service.lock("obj", -1, -1);
        fail("The lock service should have been destroyed");
    } catch (LockServiceDestroyedException expected) {
    // Do nothing
    }
    vm0.invoke(new SerializableRunnable("check to make sure the lock is not orphaned") {

        public void run() {
            final DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
            // lock and unlock to make sure this vm is grantor
            assertTrue(service.lock("obj", -1, -1));
            service.unlock("obj");
        }
    });
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) DLockResponseMessage(org.apache.geode.distributed.internal.locks.DLockRequestProcessor.DLockResponseMessage) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) DLockTest(org.apache.geode.test.junit.categories.DLockTest)

Example 15 with DistributionMessageObserver

use of org.apache.geode.distributed.internal.DistributionMessageObserver in project geode by apache.

the class GIIDeltaDUnitTest method testTombstoneGCDuringFullGII.

/**
   * Test case to make sure that if a tombstone GC occurs during a full GII, we still have the
   * correct RVV on the GII recipient at the end.
   * 
   * @throws Throwable
   */
// GEODE-1137: orphaned AsyncInvocations, time sensitive, GC,
@Category(FlakyTest.class)
// waitForCriterion, thread unsafe test hooks/observers, expiration
@Test
public void testTombstoneGCDuringFullGII() throws Throwable {
    prepareForEachTest();
    // Create the region in 1 more VM to to a tombstone GC.
    VM vm2 = Host.getHost(0).getVM(2);
    createDistributedRegion(vm2);
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    assertEquals(0, DistributedCacheOperation.SLOW_DISTRIBUTION_MS);
    prepareCommonTestData(6);
    // All members should have "key5" at this point
    // shutdown R
    closeCache(R);
    final VM vmR = R;
    // Destroy key5, this will leave a tombstone
    doOneDestroy(P, 7, "key5");
    // Set tesk hook so that R will pause GII after getting the RVV
    R.invoke(new SerializableRunnable() {

        public void run() {
            // Add hooks before and after receiving the RVV
            Mycallback myAfterSavedReceivedRVV = new Mycallback(GIITestHookType.AfterCalculatedUnfinishedOps, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterSavedReceivedRVV);
        }
    });
    // Set a trigger in vm2 so that it will start up R after determining
    // the recipients for a tombstone GC message. vm2 will wait until
    // R has already received the RVV before sending the message.
    vm2.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof TombstoneMessage && ((TombstoneMessage) message).regionPath.contains(REGION_NAME)) {
                        System.err.println("DAN DEBUG  about to send tombstone message, starting up R - " + message.getSender());
                        AsyncInvocation async3 = createDistributedRegionAsync(vmR);
                        // Wait for R to finish requesting the RVV before letting the tombstone GC proceeed.
                        waitForCallbackStarted(vmR, GIITestHookType.AfterCalculatedUnfinishedOps);
                        System.err.println("DAN DEBUG  R has received the RVV, sending tombstone message");
                        DistributionMessageObserver.setInstance(null);
                    }
                }
            });
        }
    });
    P.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof TombstoneMessage && ((TombstoneMessage) message).regionPath.contains(REGION_NAME)) {
                        System.err.println("DAN DEBUG  P has processed the tombstone message, allowing R to proceed with the GII");
                        vmR.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterCalculatedUnfinishedOps, true));
                        DistributionMessageObserver.setInstance(null);
                    }
                }
            });
        }
    });
    // Force tombstone GC, this will trigger the R to be started, etc.
    vm2.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            try {
                cache.getTombstoneService().forceBatchExpirationForTests(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    // Wait for P to perform the tombstone GC
    waitForToVerifyRVV(P, memberP, 7, null, 7);
    System.err.println("DAN DEBUG P has finished the tombstone GC, waiting for R to get the correct RVV");
    // Make sure that Rs RVV now reflects the update from P
    // P's rvv=r7, gc=7
    waitForToVerifyRVV(R, memberP, 7, null, 7);
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) TombstoneMessage(org.apache.geode.internal.cache.DistributedTombstoneOperation.TombstoneMessage) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DistributionManager (org.apache.geode.distributed.internal.DistributionManager)29 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)29 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)29 VM (org.apache.geode.test.dunit.VM)28 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)28 Test (org.junit.Test)28 Host (org.apache.geode.test.dunit.Host)27 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)22 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)11 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)11 Cache (org.apache.geode.cache.Cache)9 IgnoredException (org.apache.geode.test.dunit.IgnoredException)9 Region (org.apache.geode.cache.Region)7 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)6 IOException (java.io.IOException)5 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)5 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 DiskRegion (org.apache.geode.internal.cache.DiskRegion)4