Search in sources :

Example 41 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class GIIDeltaDUnitTest method testExpiredTombstoneSkippedAtProviderOnly.

/**
   * vm0 and vm1 are peers, each holds a DR. Let P and R have the same RVV and RVVGC: P7,R6, RVVGC
   * is P0,R0. vm1 becomes offline then restarts. Use testHook to pause the GII, then do tombstone
   * GC triggered by expireBatch (not by forceGC) at R only. The tombstone GC will be executed at R,
   * but igored at P. The deltaGII should send nothing to R since the RVVs are the same. So after
   * GII, P and R will have different tombstone number. But P's tombstones should be expired.
   */
@Test
public void testExpiredTombstoneSkippedAtProviderOnly() throws Throwable {
    prepareForEachTest();
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    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");
    // P's rvv=p6, gc=0
    waitForToVerifyRVV(R, memberP, 6, null, 0);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, null, 0);
    // now the rvv and rvvgc at P and R should be the same
    // save R's rvv in byte array, check if it will be fullGII
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    // shutdown R and restart
    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=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
    // add test hook
    P.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myDuringPackingImage = new Mycallback(GIITestHookType.DuringPackingImage, REGION_NAME);
            InitialImageOperation.setGIITestHook(myDuringPackingImage);
        }
    });
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    // restart R and gii, it will be blocked at test hook
    AsyncInvocation async3 = createDistributedRegionAsync(R);
    // 8
    waitForCallbackStarted(P, GIITestHookType.DuringPackingImage);
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            int count = getDeltaGIICount(P);
            return (count == 1);
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 30000, 200, true);
    int count = getDeltaGIICount(P);
    assertEquals(1, count);
    // let tombstone expired at R to trigger tombstoneGC.
    // Wait for tombstone is GCed at R, but still exists in P
    changeTombstoneTimout(R, MAX_WAIT);
    changeTombstoneTimout(P, MAX_WAIT);
    Wait.pause((int) MAX_WAIT);
    forceGC(R, 3);
    forceGC(P, 3);
    // let GII continue
    P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.DuringPackingImage, true));
    async3.join(MAX_WAIT * 2);
    count = getDeltaGIICount(P);
    assertEquals(0, count);
    // deltaGII, key1 in delta
    verifyDeltaSizeFromStats(R, 1, 1);
    // tombstone key2, key5 should be GCed at R
    verifyTombstoneExist(R, "key2", false, false);
    verifyTombstoneExist(R, "key5", false, false);
    // tombstone key2, key5 should still exist and expired at P
    verifyTombstoneExist(P, "key2", true, true);
    verifyTombstoneExist(P, "key5", true, true);
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    System.out.println("GGG:p_rvv=" + p_rvv.fullToString() + ":r_rvv=" + r_rvv.fullToString());
    // R's rvv=p7, gc=4
    waitForToVerifyRVV(R, memberP, 7, null, 4);
    // R's rvv=r6, gc=5
    waitForToVerifyRVV(R, memberR, 6, null, 5);
    // P's rvv=p7, gc=0
    waitForToVerifyRVV(P, memberP, 7, null, 0);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
}
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)

Example 42 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class GIIDeltaDUnitTest method testFullGIIAfterClear.

/**
   * 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. R offline, then P8 is clear() operation. Run P9 is a put. Restart R. R will
   * do fullGII since R missed a clear
   */
@Test
public void testFullGIIAfterClear() 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);
    createUnfinishedOperationsR4R5();
    doOnePut(P, 7, "key1");
    // P's rvv=p6, gc=0
    waitForToVerifyRVV(P, memberP, 7, null, 0);
    // P's rvv=r6(3-6), gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 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);
    // shutdown R before clear
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    doOneClear(P, 8);
    // clear() increased P's version with 1 to P8
    // after clear, P and R's RVVGC == RVV, no more exception
    // P's rvv=r6, gc=8
    waitForToVerifyRVV(P, memberP, 8, null, 8);
    // P's rvv=r6, gc=6
    waitForToVerifyRVV(P, memberR, 6, null, 6);
    // 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, true);
    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, 0);
}
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)

Example 43 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class GIIDeltaDUnitTest method testDeltaGIIWithDifferentRVVGC.

/**
   * vm0 and vm1 are peers, each holds a DR. create some exception list. Then shutdown R. Do
   * tombstone GC at P only. Before GII, P's RVV is P7,R6(3-6), RVVGC is P4,R0; R's RVV is P6,R6,
   * RVVGC are both P0,R0 vm1 becomes offline then restarts.
   * https://wiki.gemstone.com/display/gfepersistence/DeltaGII+Spec+for+8.0 The deltaGII should send
   * delta to R, revoke unfinished opeation R4,R5
   */
@Test
public void testDeltaGIIWithDifferentRVVGC() throws Throwable {
    final String testcase = "testDeltaGIIWithExceptionList";
    prepareForEachTest();
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    final long[] exceptionlist = { 4, 5 };
    assertEquals(0, DistributedCacheOperation.SLOW_DISTRIBUTION_MS);
    prepareCommonTestData(6);
    // P's rvv=p6, gc=0
    waitForToVerifyRVV(P, memberP, 6, null, 0);
    VersionTag expect_tag = getVersionTag(R, "key5");
    createUnfinishedOperationsR4R5();
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    // force tombstone GC to let RVVGC to become P4:R0
    changeTombstoneTimout(R, MAX_WAIT);
    changeTombstoneTimout(P, MAX_WAIT);
    Wait.pause((int) MAX_WAIT);
    forceGC(P, 2);
    // P's rvv=p6, gc=4
    waitForToVerifyRVV(P, memberP, 6, null, 4);
    // p7 only apply at P
    doOnePut(P, 7, "key1");
    // P's rvv=p7, gc=4
    waitForToVerifyRVV(P, memberP, 7, null, 4);
    verifyTombstoneExist(P, "key2", false, false);
    // restart R and gii
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    createDistributedRegion(R);
    // R's rvv=p7, gc=4
    waitForToVerifyRVV(R, memberP, 7, null, 4);
    // R's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, exceptionlist, 0);
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    assertSameRVV(p_rvv, r_rvv);
    // 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 2, i.e. 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));
    verifyTombstoneExist(R, "key2", false, false);
    verifyTombstoneExist(P, "key2", false, false);
}
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 44 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class GIIDeltaDUnitTest method testTombstoneGCInMiddleOfGII.

/**
   * vm0 and vm1 are peers, each holds a DR. create some exception list. Then shutdown R. Before
   * GII, P's RVV is P7,R6(3-6), RVVGC is P0,R0; R's RVV is P3,R6, RVVGC is P0,R0 vm1 becomes
   * offline then restarts. Use testHook to pause the GII, then do tombstone GC at P only. The
   * deltaGII should send correct tombstonedelta to R, revoke unfinished opeation R4,R5
   * 
   * There's member T doing GII from P at the same time.
   * 
   * In this test, GII thread will get the GIILock before tombstone GC, so tombstone GC should wait
   * for all GIIs to finish
   */
// GEODE-633: SLOW_DISTRIBUTION_MS, non-thread safe test hook, async
@Category(FlakyTest.class)
// actions, time sensitive, waitForCriterion, thread joins, forceGC
@Test
public void testTombstoneGCInMiddleOfGII() throws Throwable {
    prepareForEachTest();
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    final long[] exceptionlist = { 4, 5 };
    Host host = Host.getHost(0);
    VM T = host.getVM(2);
    createDistributedRegion(T);
    final DiskStoreID memberT = getMemberID(T);
    closeCache(T);
    assertEquals(0, DistributedCacheOperation.SLOW_DISTRIBUTION_MS);
    prepareCommonTestData(3);
    // P's rvv=p3, gc=0
    waitForToVerifyRVV(P, memberP, 3, null, 0);
    VersionTag expect_tag = getVersionTag(R, "key5");
    createUnfinishedOperationsR4R5();
    // R's rvv=p3, gc=0
    waitForToVerifyRVV(R, memberP, 3, null, 0);
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    // p4-7 only apply at P
    doOneDestroy(P, 4, "key2");
    doOnePut(P, 5, "key1");
    doOnePut(P, 6, "key3");
    doOnePut(P, 7, "key1");
    // add test hook
    // 8
    P.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myDuringPackingImage = new Mycallback(GIITestHookType.DuringPackingImage, REGION_NAME);
            InitialImageOperation.setGIITestHook(myDuringPackingImage);
        }
    });
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    // restart R and gii, it will be blocked at test hook
    AsyncInvocation async3 = createDistributedRegionAsync(R);
    // restart R and gii, it will be blocked at test hook
    AsyncInvocation async4 = createDistributedRegionAsync(T);
    // 8
    waitForCallbackStarted(P, GIITestHookType.DuringPackingImage);
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            int count = getDeltaGIICount(P);
            return (count == 2);
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 30000, 200, true);
    int count = getDeltaGIICount(P);
    assertEquals(2, count);
    // force tombstone GC to let RVVGC to become P4:R0, but R already sent its old RVV/RVVGC over
    // this tombstone GC happens AFTER GII thread got the GIILock, so it will be ignored since GII
    // is ongoing
    changeTombstoneTimout(R, MAX_WAIT);
    changeTombstoneTimout(P, MAX_WAIT);
    changeTombstoneTimout(T, MAX_WAIT);
    Wait.pause((int) MAX_WAIT);
    forceGC(P, 2);
    // P's rvv=p7, gc=0
    waitForToVerifyRVV(P, memberP, 7, null, 0);
    // let GII continue
    P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.DuringPackingImage, false));
    P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.DuringPackingImage, true));
    WaitCriterion ev2 = new WaitCriterion() {

        public boolean done() {
            int count = getDeltaGIICount(P);
            return (count == 0);
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev2, 30000, 200, true);
    count = getDeltaGIICount(P);
    assertEquals(0, count);
    // expect key2 is still tombstone during and after
    verifyTombstoneExist(P, "key2", true, true);
    // GIIs
    // expect key2 is still tombstone during and after
    verifyTombstoneExist(R, "key2", true, true);
    // GIIs
    // expect key2 is still tombstone during and after
    verifyTombstoneExist(T, "key2", true, true);
    // GIIs
    // trigger to GC the tombstones in expired queue
    forceGC(P, 1);
    async3.join(MAX_WAIT);
    async4.join(MAX_WAIT);
    // after GII, tombstone GC happened
    // P's rvv=p6, gc=4
    waitForToVerifyRVV(P, memberP, 7, null, 4);
    // P's rvv=r6(3-6), gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
    // R's rvv=p7, gc=4
    waitForToVerifyRVV(R, memberP, 7, null, 4);
    // R's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, exceptionlist, 0);
    // expect tombstone key2 is GCed at P
    verifyTombstoneExist(P, "key2", false, true);
    // expect tombstone key2 is GCed at R
    verifyTombstoneExist(R, "key2", false, true);
    // T got everything from P
    verifyTombstoneExist(T, "key2", false, true);
    // do a put from T
    doOnePut(T, 1, "key1");
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    RegionVersionVector t_rvv = getRVV(R);
    assertSameRVV(p_rvv, r_rvv);
    assertSameRVV(t_rvv, r_rvv);
    // If fullGII, the key size in gii chunk is 4, i.e. key1,key3,key5,key2 is a tombstone.
    // If delta GII, it should be 4, (key1, key2, key3) and (key5(T) which is unfinished operation)
    verifyDeltaSizeFromStats(R, 4, 1);
    // verify unfinished op for key5 is revoked
    waitToVerifyKey(R, "key5", generateValue(R));
    VersionTag tag = getVersionTag(R, "key5");
    assertTrue(expect_tag.equals(tag));
// 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) 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 45 with RegionVersionVector

use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.

the class GIIDeltaDUnitTest method testFullGIINotDorminatedByProviderRVVGC.

/**
   * vm0 and vm1 are peers, each holds a DR. unifinished P8: destroy(key1), finished P9: put(key3).
   * Shutdown R, then GC tombstones at P. P's RVV=P9,R6(3-6), RVVGC=P8,R0, R's RVV=P9(7-9),R6, RVV
   * It should trigger fullGII
   */
@Test
public void testFullGIINotDorminatedByProviderRVVGC() 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(3);
    createUnfinishedOperationsR4R5();
    // P's rvv=p3, gc=0
    waitForToVerifyRVV(P, memberP, 3, null, 0);
    // P's rvv=r6(3-6), gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
    // R's rvv=p3, gc=0
    waitForToVerifyRVV(R, memberP, 3, null, 0);
    // R's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, null, 0);
    // p4-7 only apply at P
    doOneDestroy(P, 4, "key2");
    doOnePut(P, 5, "key1");
    doOnePut(P, 6, "key3");
    doOnePut(P, 7, "key1");
    final long[] exceptionlist2 = { 8 };
    // let p9 to succeed, p8 to be blocked
    P.invoke(() -> GIIDeltaDUnitTest.slowGII(exceptionlist2));
    AsyncInvocation async1 = doOneDestroyAsync(P, 8, "key1");
    waitForToVerifyRVV(P, memberP, 8, null, 0);
    doOnePut(P, 9, "key3");
    waitForToVerifyRVV(P, memberP, 9, null, 0);
    waitForToVerifyRVV(R, memberP, 9, exceptionlist2, 0);
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    forceGC(P, 3);
    // now P's RVV=P9,R6(3-6), RVVGC=P8,R0, R's RVV=P9(7-9), R6
    // P's rvv=p9, gc=8
    waitForToVerifyRVV(P, memberP, 9, null, 8);
    // P's rvv=r6(3-6), gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
    P.invoke(() -> GIIDeltaDUnitTest.resetSlowGII());
    // restart and gii, R's rvv should be the same as P's
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, true);
    createDistributedRegion(R);
    // R's rvv=p9, gc=8
    waitForToVerifyRVV(R, memberP, 9, null, 8);
    // R's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, exceptionlist, 0);
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    // after gii, rvv should be the same
    assertSameRVV(p_rvv, r_rvv);
    // In fullGII, the key size in gii chunk is 2. They are: key3, key5
    verifyDeltaSizeFromStats(R, 2, 0);
}
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

RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)52 DiskStoreID (org.apache.geode.internal.cache.persistence.DiskStoreID)19 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)17 Test (org.junit.Test)17 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)16 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)15 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataInputStream (java.io.DataInputStream)6 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)6 Cache (org.apache.geode.cache.Cache)5 LocalRegion (org.apache.geode.internal.cache.LocalRegion)5 Host (org.apache.geode.test.dunit.Host)4 VM (org.apache.geode.test.dunit.VM)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CacheClosedException (org.apache.geode.cache.CacheClosedException)3 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3 IOException (java.io.IOException)2