Search in sources :

Example 6 with DiskStoreID

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

the class GIIDeltaDUnitTest method testClearAfterChunkEntries.

/**
   * P and R are peers, each holds a DR. Each does a few operations to make RVV=P6,R6, RVVGC=P0,R0
   * for both members. R off line, then run P7. Restart R. It will trigger deltaGII to chunk entry
   * P7(key1). After that, do clear(). Make sure R should not contain key1 after GII.
   */
// GEODE-1068: time sensitive, SLOW_DISTRIBUTION_MS, waitForCriterion,
@Category(FlakyTest.class)
// possible thread unsafe test hooks, async actions, depends on stats
@Test
public void testClearAfterChunkEntries() 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");
    // P's rvv=p6, gc=0
    waitForToVerifyRVV(P, memberP, 6, null, 0);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
    // R's rvv=P6, gc=0
    waitForToVerifyRVV(R, memberP, 6, null, 0);
    // R's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, null, 0);
    // set tesk hook
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterReceivedImageReply = new Mycallback(GIITestHookType.AfterReceivedImageReply, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterReceivedImageReply);
        }
    });
    // shutdown R
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    // key1 will be the delta
    doOnePut(P, 7, "key1");
    // retart R
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    AsyncInvocation async3 = createDistributedRegionAsync(R);
    // when chunk arrived, do clear()
    waitForCallbackStarted(R, GIITestHookType.AfterReceivedImageReply);
    doOneClear(P, 8);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterReceivedImageReply, true));
    async3.getResult(MAX_WAIT);
    // clear() increased P's version with 1 to P8
    // after clear, P and R's RVVGC == RVV
    // P's rvv=r8, gc=8
    waitForToVerifyRVV(P, memberP, 8, null, 8);
    // P's rvv=r6, gc=6
    waitForToVerifyRVV(P, memberR, 6, null, 6);
    // retart R again to do fullGII
    closeCache(R);
    createDistributedRegion(R);
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    // after gii, rvv should be the same
    assertSameRVV(p_rvv, r_rvv);
    // R's rvv=r8, gc=8
    waitForToVerifyRVV(R, memberP, 8, null, 8);
    // R's rvv=r6, gc=6
    waitForToVerifyRVV(R, memberR, 6, null, 6);
    waitToVerifyKey(P, "key1", null);
    waitToVerifyKey(R, "key1", null);
    verifyDeltaSizeFromStats(R, 0, 1);
}
Also used : 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 7 with DiskStoreID

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

the class GIIDeltaDUnitTest method testDeltaGIIWithOnlyUnfinishedOp_GCAtR.

/**
   * This is to test a race condition for bug#47616 vm0 and vm1 are peers, each holds a DR. create
   * some exception list. Before GII, P's RVV is P6,R6(3-6), R's RVV is P6,R6, RVVGC are both P4,R0
   * vm1 becomes offline then restarts. The deltaGII should send delta which only contains
   * unfinished opeation R4,R5
   */
@Test
public void testDeltaGIIWithOnlyUnfinishedOp_GCAtR() 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);
    VersionTag expect_tag = getVersionTag(R, "key5");
    // 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();
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
    // 2
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterRequestRVV = new Mycallback(GIITestHookType.AfterRequestRVV, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterRequestRVV);
        }
    });
    // now P's cache still only has key1, key3, key5
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    // restart and gii
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    AsyncInvocation async3 = createDistributedRegionAsync(R);
    // 2
    waitForCallbackStarted(R, GIITestHookType.AfterRequestRVV);
    forceGC(R, 1);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterRequestRVV, true));
    async3.join(MAX_WAIT);
    // verify unfinished op for key5 is revoked
    waitToVerifyKey(R, "key5", generateValue(R));
    VersionTag tag = getVersionTag(R, "key5");
    assertTrue(expect_tag.equals(tag));
    verifyTombstoneExist(R, "key5", false, false);
    // 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 (key5(T) which is unfinished operation)
    verifyDeltaSizeFromStats(R, 3, 0);
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag) 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 8 with DiskStoreID

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

the class GIIDeltaDUnitTest method testRequesterHasHigherRVVGC.

/**
   * vm0 and vm1 are peers, each holds a DR. Each does a few operations to make RVV=P7,R6,
   * RVVGC=P4,R0 for both members. vm1 becomes offline then restarts. The deltaGII should only
   * exchange RVV. No need to send data from vm0 to vm1.
   */
@Test
public void testRequesterHasHigherRVVGC() 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");
    // let P pretends to be doing GII, to skip gcTombstone
    forceAddGIICount(P);
    changeTombstoneTimout(R, MAX_WAIT);
    changeTombstoneTimout(P, MAX_WAIT);
    Wait.pause((int) MAX_WAIT);
    forceGC(R, 3);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
    // P's rvv=p6, gc=4
    waitForToVerifyRVV(R, memberP, 6, null, 4);
    // R's rvv=r6, gc=5
    waitForToVerifyRVV(R, memberR, 6, null, 5);
    verifyTombstoneExist(R, "key5", false, false);
    verifyTombstoneExist(P, "key5", true, true);
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    // let p7 to succeed
    doOnePut(P, 7, "key1");
    // shutdown R and restart
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    createDistributedRegion(R);
    // P's rvv=p7, gc=4
    waitForToVerifyRVV(R, memberP, 7, null, 4);
    // P's rvv=r6, gc=5
    waitForToVerifyRVV(R, memberR, 6, null, 5);
    // P's rvv=r7, gc still 0
    waitForToVerifyRVV(P, memberP, 7, null, 0);
    // P's rvv=r6, gc still 0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
    // If fullGII, the key size in gii chunk is 5, i.e. key1,key2(T),key3,key4,key5(T).
    // If deltaGII, the key size is 1, i.e. P7 (key1)
    verifyDeltaSizeFromStats(R, 1, 1);
    verifyTombstoneExist(R, "key5", false, false);
    verifyTombstoneExist(P, "key5", true, true);
}
Also used : 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 9 with DiskStoreID

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

the class GIIDeltaDUnitTest method testDeltaGIIWithSameRVV.

/**
   * vm0 and vm1 are peers, each holds a DR. Each does a few operations to make RVV=P7,R6,
   * RVVGC=P4,R0 for both members. vm1 becomes offline then restarts. The deltaGII should only
   * exchange RVV. No need to send data from vm0 to vm1.
   */
@Test
public void testDeltaGIIWithSameRVV() throws Throwable {
    prepareForEachTest();
    final DiskStoreID memberP = getMemberID(P);
    final DiskStoreID memberR = getMemberID(R);
    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);
    // let r4,r5,r6 to succeed
    doOnePut(R, 4, "key4");
    doOneDestroy(R, 5, "key5");
    doOnePut(R, 6, "key1");
    // let p7 to succeed
    doOnePut(P, 7, "key1");
    // P's rvv=p7, gc=4
    waitForToVerifyRVV(P, memberP, 7, null, 4);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
    // P's rvv=p7, gc=4
    waitForToVerifyRVV(R, memberP, 7, null, 4);
    // 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);
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    createDistributedRegion(R);
    // P's rvv=p7, gc=4
    waitForToVerifyRVV(R, memberP, 7, null, 4);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, null, 0);
    RegionVersionVector p_rvv = getRVV(P);
    RegionVersionVector r_rvv = getRVV(R);
    // after gii, rvv should be the same
    assertSameRVV(p_rvv, r_rvv);
    // If fullGII, the key size in gii chunk is 4, i.e. key1,key3,key4,key5(tombstone). key2 is
    // GCed.
    // If delta GII, the key size should be 0
    verifyDeltaSizeFromStats(R, 0, 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)

Example 10 with DiskStoreID

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

the class GIIDeltaDUnitTest method testClearAfterSavedRVV.

/**
   * P and R are peers, each holds a DR. Each does a few operations to make RVV=P6,R6, RVVGC=P0,R0
   * for both members. R off line, then run P7. Restart R. When P's RVV arrives, do clear(). It
   * should trigger fullGII. Make sure R should not contain key1 after GII.
   */
@Test
public void testClearAfterSavedRVV() 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");
    // P's rvv=p6, gc=0
    waitForToVerifyRVV(P, memberP, 6, null, 0);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, null, 0);
    // R's rvv=P6, gc=0
    waitForToVerifyRVV(R, memberP, 6, null, 0);
    // R's rvv=r6, gc=0
    waitForToVerifyRVV(R, memberR, 6, null, 0);
    // set tesk hook
    R.invoke(new SerializableRunnable() {

        public void run() {
            Mycallback myAfterSavedReceivedRVV = new Mycallback(GIITestHookType.AfterSavedReceivedRVV, REGION_NAME);
            InitialImageOperation.setGIITestHook(myAfterSavedReceivedRVV);
        }
    });
    // shutdown R
    closeCache(R);
    // key1 will be the delta
    doOnePut(P, 7, "key1");
    // retart R
    AsyncInvocation async3 = createDistributedRegionAsync(R);
    // when chunk arrived, do clear()
    waitForCallbackStarted(R, GIITestHookType.AfterSavedReceivedRVV);
    doOneClear(P, 8);
    R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterSavedReceivedRVV, true));
    async3.join(MAX_WAIT);
    // clear() increased P's version with 1 to P8
    // after clear, P and R's RVVGC == RVV
    // P's rvv=r8, gc=8
    waitForToVerifyRVV(P, memberP, 8, null, 8);
    // P's rvv=r6, gc=6
    waitForToVerifyRVV(P, 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);
    // R's rvv=r8, gc=8
    waitForToVerifyRVV(R, memberP, 8, null, 8);
    // R's rvv=r6, gc=6
    waitForToVerifyRVV(R, memberR, 6, null, 6);
    waitToVerifyKey(P, "key1", null);
    waitToVerifyKey(R, "key1", null);
    verifyDeltaSizeFromStats(R, 0, 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

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