use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class NewWANConcurrencyCheckForDestroyDUnitTest method testConflictChecksBasedOnDsidAndTimeStamp.
/**
* Tests if conflict checks are happening based on DSID and timestamp even if version tag is
* generated in local distributed system.
*/
@Test
public void testConflictChecksBasedOnDsidAndTimeStamp() {
// create two distributed systems with each having a cache containing
// a Replicated Region with one entry and concurrency checks enabled.
// Site 1
Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
createCacheInVMs(lnPort, vm1);
Integer lnRecPort = (Integer) vm1.invoke(() -> WANTestBase.createReceiver());
// Site 2
Integer nyPort = (Integer) vm2.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
createCacheInVMs(nyPort, vm3);
Integer nyRecPort = (Integer) vm3.invoke(() -> WANTestBase.createReceiver());
LogWriterUtils.getLogWriter().info("Created locators and receivers in 2 distributed systems");
// Site 1
vm1.invoke(() -> WANTestBase.createSender("ln1", 2, false, 10, 1, false, false, null, true));
vm1.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ln1", isOffHeap()));
vm1.invoke(() -> WANTestBase.startSender("ln1"));
vm1.invoke(() -> WANTestBase.waitForSenderRunningState("ln1"));
// Site 2
vm3.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ny1", isOffHeap()));
vm4.invoke(() -> WANTestBase.createCache(nyPort));
vm4.invoke(() -> WANTestBase.createSender("ny1", 1, false, 10, 1, false, false, null, true));
vm4.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ny1", isOffHeap()));
vm4.invoke(() -> WANTestBase.startSender("ny1"));
vm4.invoke(() -> WANTestBase.waitForSenderRunningState("ny1"));
Wait.pause(2000);
// Perform a put in vm1
vm1.invoke(new CacheSerializableRunnable("Putting an entry in ds1") {
@Override
public void run2() throws CacheException {
assertNotNull(cache);
Region region = cache.getRegion("/repRegion");
region.put("testKey", "testValue1");
assertEquals(1, region.size());
}
});
// wait for vm4 to have later timestamp before sending operation to vm1
Wait.pause(300);
AsyncInvocation asynch = vm4.invokeAsync(new CacheSerializableRunnable("Putting an entry in ds2 in vm4") {
@Override
public void run2() throws CacheException {
assertNotNull(cache);
Region region = cache.getRegion("/repRegion");
region.put("testKey", "testValue2");
assertEquals(1, region.size());
assertEquals("testValue2", region.get("testKey"));
}
});
try {
asynch.join(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Wait for all local ds events be received by vm3.
Wait.pause(1000);
vm3.invoke(new CacheSerializableRunnable("Check dsid") {
@Override
public void run2() throws CacheException {
Region region = cache.getRegion("repRegion");
Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
true);
// commented while merging revision 43582
RegionEntry re = null;
if (entry instanceof EntrySnapshot) {
re = ((EntrySnapshot) entry).getRegionEntry();
} else if (entry instanceof NonTXEntry) {
re = ((NonTXEntry) entry).getRegionEntry();
}
VersionTag tag = re.getVersionStamp().asVersionTag();
assertEquals(2, tag.getDistributedSystemId());
}
});
// Check vm3 has latest timestamp from vm4.
long putAllTimeStampVm1 = (Long) vm4.invoke(() -> NewWANConcurrencyCheckForDestroyDUnitTest.getVersionTimestampAfterPutAllOp());
long putAllTimeStampVm3 = (Long) vm3.invoke(() -> NewWANConcurrencyCheckForDestroyDUnitTest.getVersionTimestampAfterPutAllOp());
assertEquals(putAllTimeStampVm1, putAllTimeStampVm3);
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class NewWANConcurrencyCheckForDestroyDUnitTest method verifyTimestampAfterOp.
/*
* For VM 5 in ds 3.
*/
public static void verifyTimestampAfterOp(long timestamp, int memberid) {
Region region = cache.getRegion("repRegion");
assertEquals(0, region.size());
Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
true);
RegionEntry re = ((EntrySnapshot) entry).getRegionEntry();
assertTrue(re.getValueInVM((LocalRegion) region) instanceof Tombstone);
VersionTag tag = re.getVersionStamp().asVersionTag();
assertEquals(timestamp, tag.getVersionTimeStamp());
assertEquals(memberid, tag.getDistributedSystemId());
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class ClientServerTransactionCCEDUnitTest method verifyVersionTags.
public void verifyVersionTags(VM client, VM server1, VM server2, VM server3) {
Map<Object, VersionTag> clientTags = getVersionTagsForRegion(client, D_REFERENCE);
Map<Object, VersionTag> serverTags = getVersionTagsForRegion(server1, D_REFERENCE);
InternalDistributedMember serverId = getMemberId(server1);
for (Object key : clientTags.keySet()) {
VersionTag serverTag = serverTags.get(key);
serverTag.setMemberID(serverId);
LogWriterUtils.getLogWriter().fine("SWAP:key:" + key + " clientVersion:" + clientTags.get(key) + " serverVersion:" + serverTag);
assertEquals(clientTags.get(key), serverTags.get(key));
serverTags.remove(key);
}
assertTrue(serverTags.isEmpty());
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class GIIDeltaDUnitTest method testDeltaGIIWithExceptionList.
/**
* vm0 and vm1 are peers, each holds a DR. create some exception list. Before GII, P's RVV is
* P7,R6(3-6), R's RVV is P6,R6, RVVGC are both P4,R0 vm1 becomes offline then restarts.
* https://wiki.gemstone.com/display/gfepersistence/DeltaGII+Spec+for+8.0 The deltaGII should send
* delta to R, revoke unfinished opeation R4,R5
*/
@Test
public void testDeltaGIIWithExceptionList() 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);
// p7 only apply at P
doOnePut(P, 7, "key1");
// restart and gii
checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
createDistributedRegion(R);
// P's rvv=p7, gc=4
waitForToVerifyRVV(P, memberP, 7, null, 4);
// P's rvv=r6, gc=0
waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
// R's rvv=p7, gc=4
waitForToVerifyRVV(R, memberP, 7, 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 2, i.e. 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));
// restart P, since R has received exceptionlist R4,R5 from P
closeCache(P);
createDistributedRegion(P);
// P's rvv=p7, gc=4
waitForToVerifyRVV(P, memberP, 7, 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);
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class GIIDeltaDUnitTest method testDeltaGIIWithoutRVVGC.
/**
* vm0 and vm1 are peers, each holds a DR. create some exception list. Not to do any tombstone GC
* Before GII, P's RVV is P7,R6(3-6), R's RVV is P6,R6, RVVGC are both P0,R0 vm1 becomes offline
* then restarts. https://wiki.gemstone.com/display/gfepersistence/DeltaGII+Spec+for+8.0 The
* deltaGII should send delta to R, revoke unfinished opeation R4,R5
*/
@Test
public void testDeltaGIIWithoutRVVGC() 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);
// P's rvv=p6, gc=0
waitForToVerifyRVV(P, memberP, 6, null, 0);
// P's rvv=r3, gc=0
waitForToVerifyRVV(P, memberR, 3, null, 0);
VersionTag expect_tag = getVersionTag(R, "key5");
createUnfinishedOperationsR4R5();
// now P's cache still only has key1, key3
byte[] R_rvv_bytes = getRVVByteArray(R, REGION_NAME);
closeCache(R);
// p7 only apply at P
doOnePut(P, 7, "key1");
// restart R and gii
checkIfFullGII(P, REGION_NAME, R_rvv_bytes, false);
createDistributedRegion(R);
// P's rvv=p7, gc=0
waitForToVerifyRVV(P, memberP, 7, null, 0);
// P's rvv=r6, gc=0
waitForToVerifyRVV(P, memberR, 6, exceptionlist, 0);
// R's rvv=p7, gc=0
waitForToVerifyRVV(R, memberP, 7, null, 0);
// 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 4.
// tombstone counts in deltaSize, so without rvvgc, it's 4: key1, key2(tombstone), key3, key5
// In delta GII, it should be 1, i.e. 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));
}
Aggregations