Search in sources :

Example 26 with VersionTag

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

the class GIIDeltaDUnitTest method testUnfinishedOpsWithoutExceptionList.

/**
   * Let R4, R5 unfinish, but R5 is the last operation from R. So P's RVV is still P:x,R3, without
   * exception list. But actually R4, R5 are unfinished ops by all means.
   */
@Test
public void testUnfinishedOpsWithoutExceptionList() 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);
    // 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);
    // R's rvv=p7, gc=0
    waitForToVerifyRVV(R, memberP, 7, null, 0);
    // R's rvv=r3, gc=0
    waitForToVerifyRVV(R, memberR, 5, null, 0);
    // now P's rvv=P7,R3, R's RVV=P7,R5
    // shutdown R and restart
    byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
    closeCache(R);
    checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
    createDistributedRegion(R);
    // 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 keys: key1,2(tombstone),3,5
    // delta GII chunk has 1 key, i.e. (key5(T) which is unfinished operation)
    verifyDeltaSizeFromStats(R, 1, 1);
    // verify unfinished op for key5 is revoked
    waitToVerifyKey(R, "key5", generateValue(R));
    VersionTag tag = getVersionTag(R, "key5");
    assertTrue(expect_tag.equals(tag));
    // shutdown R again and restart, to verify localVersion=5 will be saved and recovered
    closeCache(R);
    createDistributedRegion(R);
    // 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);
}
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 27 with VersionTag

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

the class GIIDeltaDUnitTest method testDeltaGIIWithOnlyUnfinishedOp.

/**
   * 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 operation R4,R5
   */
@Test
public void testDeltaGIIWithOnlyUnfinishedOp() 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();
    // 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);
    createDistributedRegion(R);
    // P's rvv=p6, gc=4
    waitForToVerifyRVV(P, memberP, 6, null, 4);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
    // R's rvv=p6, gc=4
    waitForToVerifyRVV(R, memberP, 6, 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 1 (key5(T) which is unfinished operation)
    verifyDeltaSizeFromStats(R, 1, 1);
    // verify unfinished op for key5 is revoked
    waitToVerifyKey(R, "key5", generateValue(R));
    VersionTag tag = getVersionTag(R, "key5");
    assertTrue(expect_tag.equals(tag));
    // restart P, since R has received exceptionlist R4,R5 from P
    closeCache(P);
    createDistributedRegion(P);
    // P's rvv=p6, gc=4
    waitForToVerifyRVV(P, memberP, 6, null, 4);
    // P's rvv=r6, gc=0
    waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
    // If fullGII, the key size in gii chunk is 3, i.e. key1,key3,key5. key4 is removed as
    // unfinished op
    // If deltaGII, the key size should be 0
    verifyDeltaSizeFromStats(P, 0, 1);
    // restart R, to make sure the unfinished op is handled correctly
    // for bug 47616
    forceGC(R, 1);
    // P's rvv=R6, gc=5
    waitForToVerifyRVV(P, memberR, 6, null, 5);
    // P's rvv=R6, gc=5
    waitForToVerifyRVV(R, memberR, 6, null, 5);
    closeCache(R);
    createDistributedRegion(R);
    // If fullGII, the key size in gii chunk is 3, i.e. key1,key3,key5. key4 is removed as
    // unfinished op
    // If deltaGII, the key size should be 0
    verifyDeltaSizeFromStats(R, 0, 1);
    // verify unfinished op for key5 is revoked
    waitToVerifyKey(R, "key5", generateValue(R));
    tag = getVersionTag(R, "key5");
    assertTrue(expect_tag.equals(tag));
}
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 28 with VersionTag

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

the class UpdateVersionJUnitTest method testUpdateVersionAfterCreate.

/**
   * Tests for LocalRegion.
   */
@Test
public void testUpdateVersionAfterCreate() {
    Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
    Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
    try {
        region.create("key-1", "value-1");
        Entry entry = region.getEntry("key-1");
        assertTrue(entry instanceof NonTXEntry);
        RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
        VersionStamp stamp = regionEntry.getVersionStamp();
        // Create a duplicate entry version tag from stamp with newer time-stamp.
        VersionTag tag = VersionTag.create(stamp.getMemberID());
        int entryVersion = stamp.getEntryVersion();
        VersionSource member = stamp.getMemberID();
        int dsid = stamp.getDistributedSystemId();
        long time = System.currentTimeMillis() + 1;
        tag.setEntryVersion(entryVersion);
        tag.setDistributedSystemId(dsid);
        tag.setVersionTimeStamp(time);
        tag.setIsGatewayTag(true);
        assertTrue(region instanceof LocalRegion);
        EntryEventImpl event = createNewEvent((LocalRegion) region, tag, entry.getKey());
        ((LocalRegion) region).basicUpdateEntryVersion(event);
        // Verify the new stamp
        entry = region.getEntry("key-1");
        assertTrue(entry instanceof NonTXEntry);
        regionEntry = ((NonTXEntry) entry).getRegionEntry();
        stamp = regionEntry.getVersionStamp();
        assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
        assertEquals(++entryVersion, stamp.getEntryVersion());
        assertEquals(member, stamp.getMemberID());
        assertEquals(dsid, stamp.getDistributedSystemId());
    } finally {
        region.destroyRegion();
        cache.close();
    }
}
Also used : NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) Entry(org.apache.geode.cache.Region.Entry) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 29 with VersionTag

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

the class UpdateVersionJUnitTest method testUpdateVersionAfterDestroyOnPR.

@Test
public void testUpdateVersionAfterDestroyOnPR() {
    Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
    Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
    try {
        region.create("key-1", "value-1");
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
        }
        region.destroy("key-1");
        assertTrue(region instanceof PartitionedRegion);
        Entry entry = ((PartitionedRegion) region).getEntry("key-1", true);
        assertTrue(entry instanceof EntrySnapshot);
        RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
        VersionStamp stamp = regionEntry.getVersionStamp();
        // Create a duplicate entry version tag from stamp with newer time-stamp.
        VersionTag tag = VersionTag.create(stamp.getMemberID());
        int entryVersion = stamp.getEntryVersion();
        VersionSource member = stamp.getMemberID();
        int dsid = stamp.getDistributedSystemId();
        long time = System.currentTimeMillis();
        tag.setEntryVersion(entryVersion);
        tag.setDistributedSystemId(dsid);
        tag.setVersionTimeStamp(time);
        tag.setIsGatewayTag(true);
        assertTrue(region instanceof PartitionedRegion);
        EntryEventImpl event = createNewEvent((PartitionedRegion) region, tag, "key-1");
        ((PartitionedRegion) region).basicUpdateEntryVersion(event);
        // Verify the new stamp
        entry = ((PartitionedRegion) region).getEntry("key-1", true);
        assertTrue(entry instanceof EntrySnapshot);
        regionEntry = ((EntrySnapshot) entry).getRegionEntry();
        stamp = regionEntry.getVersionStamp();
        assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
        assertEquals(++entryVersion, stamp.getEntryVersion());
        assertEquals(member, stamp.getMemberID());
        assertEquals(dsid, stamp.getDistributedSystemId());
    } finally {
        region.destroyRegion();
        cache.close();
    }
}
Also used : VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) NonTXEntry(org.apache.geode.internal.cache.LocalRegion.NonTXEntry) Entry(org.apache.geode.cache.Region.Entry) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 30 with VersionTag

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

the class PersistentRVVRecoveryDUnitTest method testSkipConflictChecksForConcurrentOps.

/**
   * Test that we skip conflict checks with entries that are on disk compared to entries that come
   * in as part of a concurrent operation
   */
@Test
public void testSkipConflictChecksForConcurrentOps() throws Throwable {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Create the region in few members to test recovery
    createPersistentRegion(vm0);
    createPersistentRegion(vm1);
    // Create an update some entries in vm0 and vm1.
    createData(vm0, 0, 1, "value1");
    createData(vm0, 0, 1, "value2");
    createData(vm0, 0, 1, "value2");
    closeCache(vm1);
    // Update the keys in vm0 until the entry version rolls over.
    // This means that if we did a conflict check, vm0's key will have
    // a lower entry version than vm1, which would cause us to prefer vm1's
    // value
    SerializableRunnable createData = new SerializableRunnable("rollEntryVersion") {

        public void run() {
            Cache cache = getCache();
            LocalRegion region = (LocalRegion) cache.getRegion(REGION_NAME);
            region.put(0, "value3");
            RegionEntry entry = region.getRegionEntry(0);
            entry = region.getRegionEntry(0);
            // Sneak in and change the version number for an entry to generate
            // a conflict.
            VersionTag tag = entry.getVersionStamp().asVersionTag();
            tag.setEntryVersion(tag.getEntryVersion() - 2);
            entry.getVersionStamp().setVersions(tag);
        }
    };
    vm0.invoke(createData);
    // Add an observer to vm0 which will perform a concurrent operation during
    // the GII. If we do a conflict check, this operation will be rejected
    // because it will have a lower entry version that what vm1 recovered from
    // disk
    vm0.invoke(new SerializableRunnable() {

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

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage msg) {
                    if (msg instanceof InitialImageOperation.RequestImageMessage) {
                        if (((InitialImageOperation.RequestImageMessage) msg).regionPath.contains(REGION_NAME)) {
                            createData(vm0, 0, 1, "value4");
                            DistributionMessageObserver.setInstance(null);
                        }
                    }
                }
            });
        }
    });
    // Create vm1, doing a GII
    createPersistentRegion(vm1);
    // If we did a conflict check, this would be value2
    checkData(vm0, 0, 1, "value4");
    checkData(vm1, 0, 1, "value4");
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) RegionEntry(org.apache.geode.internal.cache.RegionEntry) InitialImageOperation(org.apache.geode.internal.cache.InitialImageOperation) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

VersionTag (org.apache.geode.internal.cache.versions.VersionTag)225 Test (org.junit.Test)43 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 VM (org.apache.geode.test.dunit.VM)24 CacheException (org.apache.geode.cache.CacheException)22 LocalRegion (org.apache.geode.internal.cache.LocalRegion)22 Region (org.apache.geode.cache.Region)21 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)19 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)19 Host (org.apache.geode.test.dunit.Host)19 IOException (java.io.IOException)17 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)16 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)16 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)16 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)16 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)16 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)15 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)15 ArrayList (java.util.ArrayList)14 CancelException (org.apache.geode.CancelException)14