Search in sources :

Example 51 with RegionVersionVector

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

the class PersistentRVVRecoveryDUnitTest method getDiskRVV.

protected RegionVersionVector getDiskRVV(VM vm) throws IOException, ClassNotFoundException {
    SerializableCallable createData = new SerializableCallable("getRVV") {

        public Object call() throws Exception {
            Cache cache = getCache();
            LocalRegion region = (LocalRegion) cache.getRegion(REGION_NAME);
            RegionVersionVector rvv = region.getDiskRegion().getRegionVersionVector();
            rvv = rvv.getCloneForTransmission();
            HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
            // Using gemfire serialization because
            // RegionVersionVector is not java serializable
            DataSerializer.writeObject(rvv, hdos);
            return hdos.toByteArray();
        }
    };
    byte[] result = (byte[]) vm.invoke(createData);
    ByteArrayInputStream bais = new ByteArrayInputStream(result);
    return DataSerializer.readObject(new DataInputStream(bais));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DataInputStream(java.io.DataInputStream) Cache(org.apache.geode.cache.Cache)

Example 52 with RegionVersionVector

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

the class PersistentRVVRecoveryDUnitTest method doTestRecovery.

public void doTestRecovery(Runnable doWhileOffline) throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    // Create the region in few members to test recovery
    createPersistentRegion(vm0);
    createPersistentRegion(vm1);
    createPersistentRegion(vm2);
    // Create and delete some keys (to update the RVV)
    createData(vm0, 0, 5, "value1");
    createData(vm1, 3, 8, "value2");
    createData(vm2, 6, 11, "value3");
    delete(vm1, 0, 1);
    delete(vm0, 10, 11);
    // Make sure the RVVs are the same in the members
    RegionVersionVector vm0RVV = getRVV(vm0);
    RegionVersionVector vm1RVV = getRVV(vm1);
    RegionVersionVector vm2RVV = getRVV(vm2);
    assertSameRVV(vm0RVV, vm1RVV);
    assertSameRVV(vm0RVV, vm2RVV);
    // Closing the cache will ensure the disk store is closed
    closeCache(vm2);
    closeCache(vm1);
    closeCache(vm0);
    doWhileOffline.run();
    // Make sure we can recover the RVV
    createPersistentRegion(vm0);
    RegionVersionVector new0RVV = getRVV(vm0);
    assertSameRVV(vm0RVV, new0RVV);
    assertEquals(vm0RVV.getOwnerId(), new0RVV.getOwnerId());
    createData(vm0, 12, 15, "value");
    // Make sure we can GII the RVV
    new0RVV = getRVV(vm0);
    assertSameRVV(new0RVV, getDiskRVV(vm0));
    createPersistentRegion(vm1);
    assertSameRVV(new0RVV, getRVV(vm1));
    assertSameRVV(new0RVV, getDiskRVV(vm1));
    closeCache(vm0);
    closeCache(vm1);
    doWhileOffline.run();
    // Make the sure member that GII'd the RVV can also recover it
    createPersistentRegion(vm1);
    RegionVersionVector new1RVV = getRVV(vm1);
    assertSameRVV(new0RVV, getRVV(vm1));
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector)

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