use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.
the class MultiVMRegionTestCase method getCCRegionVersionVector.
/**
* Since version vectors aren't java.io.Serializable we use DataSerializer to return a serialized
* form of the vector
*/
public static byte[] getCCRegionVersionVector() throws Exception {
Object id = getMemberId();
int vm = VM.getCurrentVMNum();
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("vm" + vm + " with id " + id + " copying " + CCRegion.getVersionVector().fullToString());
RegionVersionVector vector = CCRegion.getVersionVector().getCloneForTransmission();
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("clone is " + vector);
HeapDataOutputStream dos = new HeapDataOutputStream(3000, Version.CURRENT);
DataSerializer.writeObject(vector, dos);
byte[] bytes = dos.toByteArray();
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("serialized size is " + bytes.length);
return bytes;
}
use of org.apache.geode.internal.cache.versions.RegionVersionVector 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);
}
use of org.apache.geode.internal.cache.versions.RegionVersionVector 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));
}
use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.
the class PersistentRVVRecoveryDUnitTest method getRVV.
protected RegionVersionVector getRVV(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.getVersionVector();
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));
}
use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.
the class PersistentRVVRecoveryDUnitTest method testUpdateRVVWithAsyncPersistence.
/**
* Test that with concurrent updates to an async disk region, we correctly update the RVV On disk
*/
@Test
public void testUpdateRVVWithAsyncPersistence() throws Throwable {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(1);
SerializableRunnable createRegion = new SerializableRunnable("Create persistent region") {
public void run() {
Cache cache = getCache();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
File dir = getDiskDirForVM(vm0);
dir.mkdirs();
dsf.setDiskDirs(new File[] { dir });
dsf.setMaxOplogSize(1);
dsf.setQueueSize(100);
dsf.setTimeInterval(1000);
DiskStore ds = dsf.create(REGION_NAME);
RegionFactory rf = new RegionFactory();
rf.setDiskStoreName(ds.getName());
rf.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
rf.setScope(Scope.DISTRIBUTED_ACK);
rf.setDiskSynchronous(false);
rf.create(REGION_NAME);
}
};
// Create a region with async persistence
vm0.invoke(createRegion);
// In two different threads, perform updates to the same key on the same region
AsyncInvocation ins0 = vm0.invokeAsync(new SerializableRunnable("change the entry at vm0") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 500; i++) {
region.put("A", "vm0-" + i);
}
}
});
AsyncInvocation ins1 = vm0.invokeAsync(new SerializableRunnable("change the entry at vm1") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 500; i++) {
region.put("A", "vm1-" + i);
}
}
});
// Wait for the update threads to finish.
ins0.getResult(MAX_WAIT);
ins1.getResult(MAX_WAIT);
// Make sure the async queue is flushed to disk
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore(REGION_NAME);
ds.flush();
}
});
// Assert that the disk has seen all of the updates
RegionVersionVector rvv = getRVV(vm0);
RegionVersionVector diskRVV = getDiskRVV(vm0);
assertSameRVV(rvv, diskRVV);
// Bounce the cache and make the same assertion
closeCache(vm0);
vm0.invoke(createRegion);
// Assert that the recovered RVV is the same as before the restart
RegionVersionVector rvv2 = getRVV(vm0);
assertSameRVV(rvv, rvv2);
// The disk RVV should also match.
RegionVersionVector diskRVV2 = getDiskRVV(vm0);
assertSameRVV(rvv2, diskRVV2);
}
Aggregations