Search in sources :

Example 46 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class GIIDeltaDUnitTest method waitForToVerifyRVV.

public void waitForToVerifyRVV(final VM vm, final DiskStoreID member, final long expectedRegionVersion, final long[] exceptionList, final long expectedGCVersion) {
    SerializableRunnable waitForVerifyRVV = new SerializableRunnable() {

        private boolean verifyExceptionList(final DiskStoreID member, final long regionversion, final RegionVersionVector rvv, final long[] exceptionList) {
            boolean exceptionListVerified = true;
            if (exceptionList != null) {
                for (long i : exceptionList) {
                    exceptionListVerified = !rvv.contains(member, i);
                    if (!exceptionListVerified) {
                        LogWriterUtils.getLogWriter().finer("DeltaGII:missing exception " + i + ":" + rvv);
                        break;
                    }
                }
            } else {
                // expect no exceptionlist
                for (long i = 1; i <= regionversion; i++) {
                    if (!rvv.contains(member, i)) {
                        exceptionListVerified = false;
                        LogWriterUtils.getLogWriter().finer("DeltaGII:unexpected exception " + i);
                        break;
                    }
                }
            }
            return exceptionListVerified;
        }

        public void run() {
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    RegionVersionVector rvv = ((LocalRegion) getCache().getRegion(REGION_NAME)).getVersionVector().getCloneForTransmission();
                    long regionversion = getRegionVersionForMember(rvv, member, false);
                    long gcversion = getRegionVersionForMember(rvv, member, true);
                    boolean exceptionListVerified = verifyExceptionList(member, regionversion, rvv, exceptionList);
                    LogWriterUtils.getLogWriter().info("DeltaGII:expected:" + expectedRegionVersion + ":" + expectedGCVersion);
                    LogWriterUtils.getLogWriter().info("DeltaGII:actual:" + regionversion + ":" + gcversion + ":" + exceptionListVerified + ":" + rvv);
                    boolean match = true;
                    if (expectedRegionVersion != -1) {
                        match = match && (regionversion == expectedRegionVersion);
                    }
                    if (expectedGCVersion != -1) {
                        match = match && (gcversion == expectedGCVersion);
                    }
                    return match && exceptionListVerified;
                }

                public String description() {
                    RegionVersionVector rvv = ((LocalRegion) getCache().getRegion(REGION_NAME)).getVersionVector().getCloneForTransmission();
                    long regionversion = getRegionVersionForMember(rvv, member, false);
                    long gcversion = getRegionVersionForMember(rvv, member, true);
                    return "expected (rv" + expectedRegionVersion + ", gc" + expectedGCVersion + ")" + " got (rv" + regionversion + ", gc" + gcversion + ")";
                }
            };
            Wait.waitForCriterion(ev, 10 * 1000, 200, true);
            RegionVersionVector rvv = ((LocalRegion) getCache().getRegion(REGION_NAME)).getVersionVector().getCloneForTransmission();
            long regionversion = getRegionVersionForMember(rvv, member, false);
            long gcversion = getRegionVersionForMember(rvv, member, true);
            if (expectedRegionVersion != -1) {
                assertEquals(expectedRegionVersion, regionversion);
            }
            if (expectedGCVersion != -1) {
                assertEquals(expectedGCVersion, gcversion);
            }
            boolean exceptionListVerified = verifyExceptionList(member, regionversion, rvv, exceptionList);
            assertTrue(exceptionListVerified);
        }
    };
    vm.invoke(waitForVerifyRVV);
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID)

Example 47 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class GIIDeltaDUnitTest method createUnfinishedOperationsR4R5.

private void createUnfinishedOperationsR4R5() {
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    final long[] exceptionlist = { 4, 5 };
    // let r6 to succeed, r4,r5 to be blocked
    R.invoke(() -> GIIDeltaDUnitTest.slowGII(exceptionlist));
    AsyncInvocation async1 = doOnePutAsync(R, 4, "key4");
    // P's rvv=r4, gc=0
    waitForToVerifyRVV(R, memberR, 4, null, 0);
    AsyncInvocation async2 = doOneDestroyAsync(R, 5, "key5");
    // P's rvv=r5, gc=0
    waitForToVerifyRVV(R, memberR, 5, null, 0);
    // r6 will pass
    doOnePut(R, 6, "key1");
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, null, 0);
    // P should have exception list R4,R5 now
    // P's rvv=r6(3-6), gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
}
Also used : DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID)

Example 48 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class GIIDeltaDUnitTest method testHooks.

/*
   * 1. after R5 becomes R4, regenrate another R5 2. verify stattic callback at provider 3. gii
   * packing should wait for tombstone GC 4. gii packing should wait for other on-fly operations
   */
@Test
public void testHooks() throws Throwable {
    prepareForEachTest();
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    assertEquals(0, DistributedCacheOperation.SLOW_DISTRIBUTION_MS);
    prepareCommonTestData(6);
    VersionTag expect_tag = getVersionTag(R, "key5");
    final long[] exceptionlist = { 4, 5 };
    R.invoke(() -> GIIDeltaDUnitTest.slowGII(exceptionlist));
    AsyncInvocation async1 = doOnePutAsync(R, 4, "key4");
    // P's rvv=r4, gc=0
    waitForToVerifyRVV(R, memberR, 4, null, 0);
    AsyncInvocation async2 = doOneDestroyAsync(R, 5, "key5");
    // P's rvv=r5, gc=0
    waitForToVerifyRVV(R, memberR, 5, null, 0);
    // P should have unfinished ops R4,R5, but they did not show up in exception list
    // P's rvv=r3, gc=0
    waitForToVerifyRVV(P, memberR, 3, null, 0);
    // define test hooks
    // 1
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myBeforeRequestRVV = new Mycallback(GIITestHookType.BeforeRequestRVV, REGION_NAME);
            InitialImageOperation.setGIITestHook(myBeforeRequestRVV);
        }
    });
    // 2
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterRequestRVV = new Mycallback(GIITestHookType.AfterRequestRVV, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterRequestRVV);
        }
    });
    // 3
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterCalculatedUnfinishedOps = new Mycallback(GIITestHookType.AfterCalculatedUnfinishedOps, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterCalculatedUnfinishedOps);
        }
    });
    // 4
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myBeforeSavedReceivedRVV = new Mycallback(GIITestHookType.BeforeSavedReceivedRVV, REGION_NAME);
            InitialImageOperation.setGIITestHook(myBeforeSavedReceivedRVV);
        }
    });
    // 5
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterSavedReceivedRVV = new Mycallback(GIITestHookType.AfterSavedReceivedRVV, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterSavedReceivedRVV);
        }
    });
    // 6
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterSentRequestImage = new Mycallback(GIITestHookType.AfterSentRequestImage, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterSentRequestImage);
        }
    });
    // 7
    P.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterReceivedRequestImage = new Mycallback(GIITestHookType.AfterReceivedRequestImage, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterReceivedRequestImage);
        }
    });
    // 8
    P.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myDuringPackingImage = new Mycallback(GIITestHookType.DuringPackingImage, REGION_NAME);
            InitialImageOperation.setGIITestHook(myDuringPackingImage);
        }
    });
    // 9
    P.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterSentImageReply = new Mycallback(GIITestHookType.AfterSentImageReply, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterSentImageReply);
        }
    });
    // 10
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterReceivedImageReply = new Mycallback(GIITestHookType.AfterReceivedImageReply, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterReceivedImageReply);
        }
    });
    // 11
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myDuringApplyDelta = new Mycallback(GIITestHookType.DuringApplyDelta, REGION_NAME);
            InitialImageOperation.setGIITestHook(myDuringApplyDelta);
        }
    });
    // 12
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myBeforeCleanExpiredTombstones = new Mycallback(GIITestHookType.BeforeCleanExpiredTombstones, REGION_NAME);
            InitialImageOperation.setGIITestHook(myBeforeCleanExpiredTombstones);
        }
    });
    // 13
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterSavedRVVEnd = new Mycallback(GIITestHookType.AfterSavedRVVEnd, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterSavedRVVEnd);
        }
    });
    // shutdown R and restart
    // R's rvv=p6, gc=0
    waitForToVerifyRVV(R, memberP, 6, null, 0);
    // R's rvv=r3, gc=0
    waitForToVerifyRVV(R, memberR, 5, null, 0);
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    // let p7 to succeed
    doOnePut(P, 7, "key1");
    // P's rvv=p7, gc=0
    waitForToVerifyRVV(P, memberP, 7, null, 0);
    // P's rvv=r3, gc=0
    waitForToVerifyRVV(P, memberR, 3, null, 0);
    // now P's rvv=P7,R3, R's RVV=P6,R5
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    AsyncInvocation async3 = createDistributedRegionAsync(R);
    // 1
    waitForCallbackStarted(R, GIITestHookType.BeforeRequestRVV);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.BeforeRequestRVV, true));
    // 2
    waitForCallbackStarted(R, GIITestHookType.AfterRequestRVV);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterRequestRVV, true));
    // 3
    waitForCallbackStarted(R, GIITestHookType.AfterCalculatedUnfinishedOps);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterCalculatedUnfinishedOps, true));
    // 4
    waitForCallbackStarted(R, GIITestHookType.BeforeSavedReceivedRVV);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.BeforeSavedReceivedRVV, true));
    // 5
    waitForCallbackStarted(R, GIITestHookType.AfterSavedReceivedRVV);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterSavedReceivedRVV, true));
    // 6
    waitForCallbackStarted(R, GIITestHookType.AfterSentRequestImage);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterSentRequestImage, true));
    // 7
    waitForCallbackStarted(P, GIITestHookType.AfterReceivedRequestImage);
    P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterReceivedRequestImage, true));
    // 8
    waitForCallbackStarted(P, GIITestHookType.DuringPackingImage);
    P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.DuringPackingImage, true));
    // 9
    waitForCallbackStarted(P, GIITestHookType.AfterSentImageReply);
    P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterSentImageReply, true));
    // 10
    waitForCallbackStarted(R, GIITestHookType.AfterReceivedImageReply);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterReceivedImageReply, true));
    // 11
    waitForCallbackStarted(R, GIITestHookType.DuringApplyDelta);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.DuringApplyDelta, true));
    // 12
    waitForCallbackStarted(R, GIITestHookType.BeforeCleanExpiredTombstones);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.BeforeCleanExpiredTombstones, true));
    // 13
    waitForCallbackStarted(R, GIITestHookType.AfterSavedRVVEnd);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterSavedRVVEnd, true));
    async3.join(MAX_WAIT);
    // P's rvv=p7, gc=0
    waitForToVerifyRVV(R, memberP, 7, null, 0);
    // P's rvv=r3, gc=0
    waitForToVerifyRVV(R, memberR, 3, exceptionlist, 0);
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    // after gii, rvv should be the same
    assertSameRVV(p_rvv, r_rvv);
    // full gii chunk has 4 entries: key1,2(tombstone),3,5
    // delta gii has 2 entry: p7 (key1) and (key5(T) which is unfinished operation)
    verifyDeltaSizeFromStats(R, 2, 1);
    // verify unfinished op for key5 is revoked
    waitToVerifyKey(R, "key5", generateValue(R));
    VersionTag tag = getVersionTag(R, "key5");
    assertTrue(expect_tag.equals(tag));
    // P will receive R6 and have exception R6(3-6)
    // r6 will pass
    doOnePut(R, 6, "key1");
    // R's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, exceptionlist, 0);
    // P's rvv=r6(3-6), gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
    P.invoke(() -> InitialImageOperation.resetAllGIITestHooks());
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 49 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class GIIDeltaDUnitTest method testFullGIITriggeredByTooManyUnfinishedOps.

/**
   * vm0 and vm1 are peers, each holds a DR. create some exception list. Before GII, P's RVV is
   * P7,R6(3-6), R's RVV is P6,R6, RVVGC are both P4,R0 By changing MAX_UNFINISHED_OPERATIONS to be
   * 1, 2. It should be fullGII then deltaGII.
   */
// GEODE-686: time sensitive, SLOW_DISTRIBUTION_MS, forceGC
@Category(FlakyTest.class)
@Test
public void testFullGIITriggeredByTooManyUnfinishedOps() throws Throwable {
    prepareForEachTest();
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    final long[] exceptionlist = { 4, 5 };
    assertEquals(0, DistributedCacheOperation.SLOW_DISTRIBUTION_MS);
    prepareCommonTestData(6);
    // force tombstone GC to let RVVGC to become P4:R0
    forceGC(P, 2);
    // P's rvv=p6, gc=4
    waitForToVerifyRVV(P, memberP, 6, null, 4);
    // P's rvv=r3, gc=0
    waitForToVerifyRVV(P, memberR, 3, null, 0);
    createUnfinishedOperationsR4R5();
    // now P's cache still only has key1, key3, key5
    closeCache(R);
    // p7 only apply at P
    doOnePut(P, 7, "key1");
    // restart and gii, it should be fullGII because number of unfinished operations exceeds limit
    changeUnfinishedOperationLimit(R, 1);
    createDistributedRegion(R);
    // If fullGII, the key size in gii chunk is 3, i.e. key1,key3,key5. key2 is GCed.
    // If delta GII, the key size should be 1, i.e. P7(key1)
    verifyDeltaSizeFromStats(R, 3, 0);
}
Also used : DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) 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)

Example 50 with DiskStoreID

use of org.apache.geode.internal.cache.persistence.DiskStoreID in project geode by apache.

the class GIIDeltaDUnitTest method testDeltaGIIAfterClear.

/**
   * P and R are peers, each holds a DR. Each does a few operations to make RVV=P7,R6, RVVGC=P0,R0
   * for both members. P8 is clear() operation. After that, R offline. Run P9 is a put. Restart R. R
   * will do deltaGII to get P9 as delta
   */
@Test
public void testDeltaGIIAfterClear() throws Throwable {
    prepareForEachTest();
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    final long[] exceptionlist = { 4, 5 };
    assertEquals(0, DistributedCacheOperation.SLOW_DISTRIBUTION_MS);
    prepareCommonTestData(6);
    // let r4,r5,r6 to succeed
    doOnePut(R, 4, "key4");
    doOneDestroy(R, 5, "key5");
    doOnePut(R, 6, "key1");
    doOnePut(P, 7, "key1");
    // P's rvv=p7, gc=0
    waitForToVerifyRVV(P, memberP, 7, null, 0);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
    // R's rvv=P7, gc=0
    waitForToVerifyRVV(R, memberP, 7, null, 0);
    // R's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, null, 0);
    // Note: since R is still online, clear will do flush message which will be blocked by the
    // test CDL (to create unfinished operation). So in this test, no exception
    doOneClear(P, 8);
    // clear() increased P's version with 1 to P8
    // after clear, P and R's RVVGC == RVV
    // P's rvv=p8, gc=8
    waitForToVerifyRVV(P, memberP, 8, null, 8);
    // P's rvv=r6, gc=6
    waitForToVerifyRVV(P, memberR, 6, null, 6);
    // R's rvv=p8, gc=8
    waitForToVerifyRVV(R, memberP, 8, null, 8);
    // R's rvv=r6, gc=6
    waitForToVerifyRVV(R, memberR, 6, null, 6);
    // shutdown R
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    // do a put at P to get some delta
    doOnePut(P, 9, "key3");
    waitForToVerifyRVV(P, memberP, 9, null, 8);
    waitForToVerifyRVV(P, memberR, 6, null, 6);
    // restart R to deltaGII
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    // shutdown P and restart
    closeCache(P);
    createDistributedRegion(P);
    waitForToVerifyRVV(P, memberP, 9, null, 8);
    waitForToVerifyRVV(P, memberR, 6, null, 6);
    createDistributedRegion(R);
    waitForToVerifyRVV(R, memberP, 9, null, 8);
    waitForToVerifyRVV(R, memberR, 6, null, 6);
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    // after gii, rvv should be the same
    assertSameRVV(p_rvv, r_rvv);
    verifyDeltaSizeFromStats(R, 1, 1);
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) DiskStoreID(org.apache.geode.internal.cache.persistence.DiskStoreID) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DiskStoreID (org.apache.geode.internal.cache.persistence.DiskStoreID)53 Test (org.junit.Test)38 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)26 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)26 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)19 UnitTest (org.apache.geode.test.junit.categories.UnitTest)11 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)10 HashMap (java.util.HashMap)5 Category (org.junit.experimental.categories.Category)4 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 DiskAccessException (org.apache.geode.cache.DiskAccessException)3 PersistentMemberID (org.apache.geode.internal.cache.persistence.PersistentMemberID)3 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)2 PersistentMemberPattern (org.apache.geode.internal.cache.persistence.PersistentMemberPattern)2