use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.
the class GIIDeltaDUnitTest method waitForToVerifyRVV.
public void waitForToVerifyRVV(final VM vm, final DiskStoreID member, final long expectedRegionVersion, final long[] exceptionList, final long expectedGCVersion) {
SerializableRunnable waitForVerifyRVV = new SerializableRunnable() {
private boolean verifyExceptionList(final DiskStoreID member, final long regionversion, final RegionVersionVector rvv, final long[] exceptionList) {
boolean exceptionListVerified = true;
if (exceptionList != null) {
for (long i : exceptionList) {
exceptionListVerified = !rvv.contains(member, i);
if (!exceptionListVerified) {
LogWriterUtils.getLogWriter().finer("DeltaGII:missing exception " + i + ":" + rvv);
break;
}
}
} else {
// expect no exceptionlist
for (long i = 1; i <= regionversion; i++) {
if (!rvv.contains(member, i)) {
exceptionListVerified = false;
LogWriterUtils.getLogWriter().finer("DeltaGII:unexpected exception " + i);
break;
}
}
}
return exceptionListVerified;
}
public void run() {
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
RegionVersionVector rvv = ((LocalRegion) getCache().getRegion(REGION_NAME)).getVersionVector().getCloneForTransmission();
long regionversion = getRegionVersionForMember(rvv, member, false);
long gcversion = getRegionVersionForMember(rvv, member, true);
boolean exceptionListVerified = verifyExceptionList(member, regionversion, rvv, exceptionList);
LogWriterUtils.getLogWriter().info("DeltaGII:expected:" + expectedRegionVersion + ":" + expectedGCVersion);
LogWriterUtils.getLogWriter().info("DeltaGII:actual:" + regionversion + ":" + gcversion + ":" + exceptionListVerified + ":" + rvv);
boolean match = true;
if (expectedRegionVersion != -1) {
match = match && (regionversion == expectedRegionVersion);
}
if (expectedGCVersion != -1) {
match = match && (gcversion == expectedGCVersion);
}
return match && exceptionListVerified;
}
public String description() {
RegionVersionVector rvv = ((LocalRegion) getCache().getRegion(REGION_NAME)).getVersionVector().getCloneForTransmission();
long regionversion = getRegionVersionForMember(rvv, member, false);
long gcversion = getRegionVersionForMember(rvv, member, true);
return "expected (rv" + expectedRegionVersion + ", gc" + expectedGCVersion + ")" + " got (rv" + regionversion + ", gc" + gcversion + ")";
}
};
Wait.waitForCriterion(ev, 10 * 1000, 200, true);
RegionVersionVector rvv = ((LocalRegion) getCache().getRegion(REGION_NAME)).getVersionVector().getCloneForTransmission();
long regionversion = getRegionVersionForMember(rvv, member, false);
long gcversion = getRegionVersionForMember(rvv, member, true);
if (expectedRegionVersion != -1) {
assertEquals(expectedRegionVersion, regionversion);
}
if (expectedGCVersion != -1) {
assertEquals(expectedGCVersion, gcversion);
}
boolean exceptionListVerified = verifyExceptionList(member, regionversion, rvv, exceptionList);
assertTrue(exceptionListVerified);
}
};
vm.invoke(waitForVerifyRVV);
}
use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.
the class GIIDeltaDUnitTest method testHooks.
/*
* 1. after R5 becomes R4, regenrate another R5 2. verify stattic callback at provider 3. gii
* packing should wait for tombstone GC 4. gii packing should wait for other on-fly operations
*/
@Test
public void testHooks() 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);
// define test hooks
// 1
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myBeforeRequestRVV = new Mycallback(GIITestHookType.BeforeRequestRVV, REGION_NAME);
InitialImageOperation.setGIITestHook(myBeforeRequestRVV);
}
});
// 2
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myAfterRequestRVV = new Mycallback(GIITestHookType.AfterRequestRVV, REGION_NAME);
InitialImageOperation.setGIITestHook(myAfterRequestRVV);
}
});
// 3
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myAfterCalculatedUnfinishedOps = new Mycallback(GIITestHookType.AfterCalculatedUnfinishedOps, REGION_NAME);
InitialImageOperation.setGIITestHook(myAfterCalculatedUnfinishedOps);
}
});
// 4
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myBeforeSavedReceivedRVV = new Mycallback(GIITestHookType.BeforeSavedReceivedRVV, REGION_NAME);
InitialImageOperation.setGIITestHook(myBeforeSavedReceivedRVV);
}
});
// 5
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myAfterSavedReceivedRVV = new Mycallback(GIITestHookType.AfterSavedReceivedRVV, REGION_NAME);
InitialImageOperation.setGIITestHook(myAfterSavedReceivedRVV);
}
});
// 6
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myAfterSentRequestImage = new Mycallback(GIITestHookType.AfterSentRequestImage, REGION_NAME);
InitialImageOperation.setGIITestHook(myAfterSentRequestImage);
}
});
// 7
P.invoke(new SerializableRunnable() {
public void run() {
Mycallback myAfterReceivedRequestImage = new Mycallback(GIITestHookType.AfterReceivedRequestImage, REGION_NAME);
InitialImageOperation.setGIITestHook(myAfterReceivedRequestImage);
}
});
// 8
P.invoke(new SerializableRunnable() {
public void run() {
Mycallback myDuringPackingImage = new Mycallback(GIITestHookType.DuringPackingImage, REGION_NAME);
InitialImageOperation.setGIITestHook(myDuringPackingImage);
}
});
// 9
P.invoke(new SerializableRunnable() {
public void run() {
Mycallback myAfterSentImageReply = new Mycallback(GIITestHookType.AfterSentImageReply, REGION_NAME);
InitialImageOperation.setGIITestHook(myAfterSentImageReply);
}
});
// 10
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myAfterReceivedImageReply = new Mycallback(GIITestHookType.AfterReceivedImageReply, REGION_NAME);
InitialImageOperation.setGIITestHook(myAfterReceivedImageReply);
}
});
// 11
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myDuringApplyDelta = new Mycallback(GIITestHookType.DuringApplyDelta, REGION_NAME);
InitialImageOperation.setGIITestHook(myDuringApplyDelta);
}
});
// 12
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myBeforeCleanExpiredTombstones = new Mycallback(GIITestHookType.BeforeCleanExpiredTombstones, REGION_NAME);
InitialImageOperation.setGIITestHook(myBeforeCleanExpiredTombstones);
}
});
// 13
R.invoke(new SerializableRunnable() {
public void run() {
Mycallback myAfterSavedRVVEnd = new Mycallback(GIITestHookType.AfterSavedRVVEnd, REGION_NAME);
InitialImageOperation.setGIITestHook(myAfterSavedRVVEnd);
}
});
// shutdown R and restart
// R's rvv=p6, gc=0
waitForToVerifyRVV(R, memberP, 6, null, 0);
// R's rvv=r3, gc=0
waitForToVerifyRVV(R, memberR, 5, null, 0);
byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
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=r3, gc=0
waitForToVerifyRVV(P, memberR, 3, null, 0);
// now P's rvv=P7,R3, R's RVV=P6,R5
checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
AsyncInvocation async3 = createDistributedRegionAsync(R);
// 1
waitForCallbackStarted(R, GIITestHookType.BeforeRequestRVV);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.BeforeRequestRVV, true));
// 2
waitForCallbackStarted(R, GIITestHookType.AfterRequestRVV);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterRequestRVV, true));
// 3
waitForCallbackStarted(R, GIITestHookType.AfterCalculatedUnfinishedOps);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterCalculatedUnfinishedOps, true));
// 4
waitForCallbackStarted(R, GIITestHookType.BeforeSavedReceivedRVV);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.BeforeSavedReceivedRVV, true));
// 5
waitForCallbackStarted(R, GIITestHookType.AfterSavedReceivedRVV);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterSavedReceivedRVV, true));
// 6
waitForCallbackStarted(R, GIITestHookType.AfterSentRequestImage);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterSentRequestImage, true));
// 7
waitForCallbackStarted(P, GIITestHookType.AfterReceivedRequestImage);
P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterReceivedRequestImage, true));
// 8
waitForCallbackStarted(P, GIITestHookType.DuringPackingImage);
P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.DuringPackingImage, true));
// 9
waitForCallbackStarted(P, GIITestHookType.AfterSentImageReply);
P.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterSentImageReply, true));
// 10
waitForCallbackStarted(R, GIITestHookType.AfterReceivedImageReply);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterReceivedImageReply, true));
// 11
waitForCallbackStarted(R, GIITestHookType.DuringApplyDelta);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.DuringApplyDelta, true));
// 12
waitForCallbackStarted(R, GIITestHookType.BeforeCleanExpiredTombstones);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.BeforeCleanExpiredTombstones, true));
// 13
waitForCallbackStarted(R, GIITestHookType.AfterSavedRVVEnd);
R.invoke(() -> InitialImageOperation.resetGIITestHook(GIITestHookType.AfterSavedRVVEnd, true));
async3.join(MAX_WAIT);
// 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 entries: key1,2(tombstone),3,5
// delta gii has 2 entry: 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));
// 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);
P.invoke(() -> InitialImageOperation.resetAllGIITestHooks());
}
use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.
the class GIIDeltaDUnitTest method testDeltaGIIAfterClear.
/**
* 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. P8 is clear() operation. After that, R offline. Run P9 is a put. Restart R. R
* will do deltaGII to get P9 as delta
*/
@Test
public void testDeltaGIIAfterClear() 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");
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);
// R's rvv=P7, gc=0
waitForToVerifyRVV(R, memberP, 7, null, 0);
// R's rvv=r6, gc=0
waitForToVerifyRVV(R, memberR, 6, null, 0);
// Note: since R is still online, clear will do flush message which will be blocked by the
// test CDL (to create unfinished operation). So in this test, no exception
doOneClear(P, 8);
// clear() increased P's version with 1 to P8
// after clear, P and R's RVVGC == RVV
// P's rvv=p8, gc=8
waitForToVerifyRVV(P, memberP, 8, null, 8);
// P's rvv=r6, gc=6
waitForToVerifyRVV(P, memberR, 6, null, 6);
// R's rvv=p8, gc=8
waitForToVerifyRVV(R, memberP, 8, null, 8);
// R's rvv=r6, gc=6
waitForToVerifyRVV(R, memberR, 6, null, 6);
// shutdown R
byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
closeCache(R);
// 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, false);
// shutdown P and restart
closeCache(P);
createDistributedRegion(P);
waitForToVerifyRVV(P, memberP, 9, null, 8);
waitForToVerifyRVV(P, memberR, 6, null, 6);
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, 1);
}
use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.
the class GIIDeltaDUnitTest method getRVVByteArray.
protected byte[] getRVVByteArray(VM vm, final String regionName) throws IOException, ClassNotFoundException {
SerializableCallable getRVVByteArray = new SerializableCallable("getRVVByteArray") {
public Object call() throws Exception {
Cache cache = getCache();
LocalRegion region = (LocalRegion) cache.getRegion(regionName);
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(getRVVByteArray);
return result;
}
use of org.apache.geode.internal.cache.versions.RegionVersionVector in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method doTestPersistConflictOperations.
/**
* vm0 and vm1 are peers, each holds a DR. They do put to the same key for different value at the
* same time. Use DistributionMessageObserver.beforeSendMessage to hold on the distribution
* message. One of the member will persist the conflict version tag, while another member will
* persist both of the 2 operations. Overall, their RVV should match after the operations.
*/
public void doTestPersistConflictOperations(boolean diskSync) throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will disconnect the DS before sending a prepare message
SerializableRunnable addObserver = new SerializableRunnable() {
public void run() {
// System.setProperty("disk.TRACE_WRITES", "true");
// System.setProperty("disk.TRACE_RECOVERY", "true");
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof AbstractUpdateMessage) {
try {
Thread.sleep(2000);
getCache().getLogger().info("testPersistConflictOperations, beforeSendMessage");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof AbstractUpdateMessage) {
getCache().getLogger().info("testPersistConflictOperations, beforeSendMessage");
DistributionMessageObserver.setInstance(null);
}
}
});
}
};
vm0.invoke(addObserver);
vm1.invoke(addObserver);
AsyncInvocation future0 = createPersistentRegionAsync(vm0, diskSync);
AsyncInvocation future1 = createPersistentRegionAsync(vm1, diskSync);
future0.join(MAX_WAIT);
future1.join(MAX_WAIT);
// createPersistentRegion(vm0);
// createPersistentRegion(vm1);
AsyncInvocation ins0 = vm0.invokeAsync(new SerializableRunnable("change the entry") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
region.put("A", "vm0");
}
});
AsyncInvocation ins1 = vm1.invokeAsync(new SerializableRunnable("change the entry") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
region.put("A", "vm1");
}
});
ins0.join(MAX_WAIT);
ins1.join(MAX_WAIT);
RegionVersionVector rvv0 = getRVV(vm0);
RegionVersionVector rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
Object value0 = getEntry(vm0, "A");
Object value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
closeRegion(vm0);
closeRegion(vm1);
// recover
future1 = createPersistentRegionAsync(vm1, diskSync);
future0 = createPersistentRegionAsync(vm0, diskSync);
future1.join(MAX_WAIT);
future0.join(MAX_WAIT);
value0 = getEntry(vm0, "A");
value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
rvv0 = getRVV(vm0);
rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
// round 2: async disk write
vm0.invoke(addObserver);
vm1.invoke(addObserver);
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 < 1000; i++) {
region.put("A", "vm0-" + i);
}
}
});
ins1 = vm1.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 < 1000; i++) {
region.put("A", "vm1-" + i);
}
}
});
ins0.join(MAX_WAIT);
ins1.join(MAX_WAIT);
rvv0 = getRVV(vm0);
rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
value0 = getEntry(vm0, "A");
value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
closeCache(vm0);
closeCache(vm1);
// recover again
future1 = createPersistentRegionAsync(vm1, diskSync);
future0 = createPersistentRegionAsync(vm0, diskSync);
future1.join(MAX_WAIT);
future0.join(MAX_WAIT);
value0 = getEntry(vm0, "A");
value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
rvv0 = getRVV(vm0);
rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
}
Aggregations