use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class PersistentRVVRecoveryDUnitTest method testSkipConflictChecksForGIIdEntries.
/**
* Test that we skip conflict checks with entries that are on disk compared to entries that come
* in as part of a GII
*/
@Test
public void testSkipConflictChecksForGIIdEntries() throws Throwable {
Host host = Host.getHost(0);
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, 2, "value2");
closeCache(vm1);
// Reset the entry version in vm0.
// 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);
// Create vm1, doing a GII
createPersistentRegion(vm1);
checkData(vm0, 0, 1, "value3");
// If we did a conflict check, this would be value2
checkData(vm1, 0, 1, "value3");
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class PersistentRVVRecoveryDUnitTest method getTombstoneCount.
private int getTombstoneCount(LocalRegion region) {
int regionCount = region.getTombstoneCount();
int actualCount = 0;
for (RegionEntry entry : region.entries.regionEntries()) {
if (entry.isTombstone()) {
actualCount++;
}
}
assertEquals(actualCount, regionCount);
return actualCount;
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class DistributedTransactionDUnitTest method testRegionAndEntryVersionsRR.
@Test
public void testRegionAndEntryVersionsRR() throws Exception {
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
createRR(new VM[] { server1, server2 });
execute(server2, new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
getGemfireCache().getLoggerI18n().fine("TEST:DISTTX=" + mgr.isDistributed());
getGemfireCache().getLoggerI18n().fine("TEST:TX BEGIN");
mgr.begin();
Region<CustId, Customer> region = getCache().getRegion(CUSTOMER_RR);
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1", "addr1");
getGemfireCache().getLoggerI18n().fine("TEST:TX PUT 1");
region.put(custIdOne, customerOne);
LocalRegion lr = (LocalRegion) region;
assertEquals(0L, lr.getVersionVector().getCurrentVersion());
getGemfireCache().getLoggerI18n().fine("TEST:TX COMMIT 1");
mgr.commit();
// Verify region version on the region
assertEquals(1L, lr.getVersionVector().getCurrentVersion());
RegionEntry re = lr.getRegionEntry(custIdOne);
getGemfireCache().getLoggerI18n().fine("TEST:VERSION-STAMP:" + re.getVersionStamp());
// Verify region version on the region entry
assertEquals(1L, re.getVersionStamp().getRegionVersion());
// Verify entry version
assertEquals(1, re.getVersionStamp().getEntryVersion());
mgr.begin();
region.put(custIdOne, new Customer("name1_1", "addr1"));
getGemfireCache().getLoggerI18n().fine("TEST:TX COMMIT 2");
assertEquals(1L, lr.getVersionVector().getCurrentVersion());
mgr.commit();
// Verify region version on the region
assertEquals(2L, lr.getVersionVector().getCurrentVersion());
re = lr.getRegionEntry(custIdOne);
getGemfireCache().getLoggerI18n().fine("TEST:VERSION-STAMP:" + re.getVersionStamp());
// Verify region version on the region entry
assertEquals(2L, re.getVersionStamp().getRegionVersion());
// Verify entry version
assertEquals(2, re.getVersionStamp().getEntryVersion());
return null;
}
});
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> region = getCache().getRegion(CUSTOMER_RR);
CustId custIdOne = new CustId(1);
LocalRegion lr = (LocalRegion) region;
// Verify region version on the region
assertEquals(2L, lr.getVersionVector().getCurrentVersion());
// Verify region version ont the region entry
RegionEntry re = lr.getRegionEntry(custIdOne);
assertEquals(2L, re.getVersionStamp().getRegionVersion());
// Verify entry version
assertEquals(2, re.getVersionStamp().getEntryVersion());
return null;
}
});
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class DistributedTransactionDUnitTest method testConcurrentTXAndNonTXOperations.
/*
* Test to reproduce a scenario where: 1. On primary, the tx op is applied first followed by
* non-tx 2. On secondary, non-tx op is applied first followed by tx.
*/
@Ignore
@Test
public void testConcurrentTXAndNonTXOperations() throws Exception {
Host host = Host.getHost(0);
final VM server1 = host.getVM(0);
final VM server2 = host.getVM(1);
createPersistentPR(new VM[] { server1 });
execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1", "addr1");
prRegion.put(custIdOne, customerOne);
BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custIdOne);
String primaryMember = br.getBucketAdvisor().getPrimary().toString();
getGemfireCache().getLoggerI18n().fine("TEST:PRIMARY:" + primaryMember);
String memberId = getGemfireCache().getDistributedSystem().getMemberId();
getGemfireCache().getLoggerI18n().fine("TEST:MEMBERID:" + memberId);
return null;
}
});
createPersistentPR(new VM[] { server2 });
Boolean isPrimary = (Boolean) execute(server1, new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custIdOne = new CustId(1);
BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custIdOne);
String primaryMember = br.getBucketAdvisor().getPrimary().toString();
getGemfireCache().getLoggerI18n().fine("TEST:PRIMARY:" + primaryMember);
String memberId = getGemfireCache().getDistributedSystem().getMemberId();
getGemfireCache().getLoggerI18n().fine("TEST:MEMBERID:" + memberId);
return memberId.equals(primaryMember);
}
});
final VM primary = isPrimary.booleanValue() ? server1 : server2;
final VM secondary = !isPrimary.booleanValue() ? server1 : server2;
System.out.println("TEST:SERVER-1:VM-" + server1.getPid());
System.out.println("TEST:SERVER-2:VM-" + server2.getPid());
System.out.println("TEST:PRIMARY=VM-" + primary.getPid());
System.out.println("TEST:SECONDARY=VM-" + secondary.getPid());
class WaitRelease implements Runnable {
CountDownLatch cdl;
String op;
public WaitRelease(CountDownLatch cdl, String member) {
this.cdl = cdl;
}
@Override
public void run() {
try {
GemFireCacheImpl.getExisting().getLoggerI18n().fine("TEST:TX WAITING - " + op);
cdl.await();
GemFireCacheImpl.getExisting().getLoggerI18n().fine("TEST:TX END WAITING");
} catch (InterruptedException e) {
}
}
public void release() {
GemFireCacheImpl.getExisting().getLoggerI18n().fine("TEST:TX COUNTDOWN - " + op);
cdl.countDown();
}
}
// Install TX hook
SerializableCallable txHook = new SerializableCallable() {
@Override
public Object call() throws Exception {
CountDownLatch cdl = new CountDownLatch(1);
DistTXState.internalBeforeApplyChanges = new WaitRelease(cdl, "TX OP");
return null;
}
};
execute(secondary, txHook);
// Install non-TX hook
SerializableCallable nontxHook = new SerializableCallable() {
@Override
public Object call() throws Exception {
CountDownLatch cdl = new CountDownLatch(1);
DistTXState.internalBeforeNonTXBasicPut = new WaitRelease(cdl, "NON TX OP");
return null;
}
};
// Install the wait-release hook on the secondary
execute(secondary, nontxHook);
// Start a tx operation on primary
execute(primary, new SerializableCallable() {
@Override
public Object call() throws Exception {
// The reason this is run in a separate thread instead of controller thread
// is that this is going to block because the secondary is going to wait.
new Thread() {
public void run() {
CacheTransactionManager mgr = getGemfireCache().getTxManager();
mgr.setDistributed(true);
getGemfireCache().getLoggerI18n().fine("TEST:DISTTX=" + mgr.isDistributed());
mgr.begin();
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1_tx", "addr1");
getGemfireCache().getLoggerI18n().fine("TEST:TX UPDATE");
prRegion.put(custIdOne, customerOne);
getGemfireCache().getLoggerI18n().fine("TEST:TX COMMIT");
mgr.commit();
}
}.start();
return null;
}
});
// Let the TX op be applied on primary first
Thread.currentThread().sleep(200);
// Perform a non-tx op on the same key on primary
execute(primary, new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custIdOne = new CustId(1);
Customer customerOne = new Customer("name1_nontx", "addr1");
getGemfireCache().getLoggerI18n().fine("TEST:TX NONTXUPDATE");
prRegion.put(custIdOne, customerOne);
return null;
}
});
// Wait for a few milliseconds
Thread.currentThread().sleep(200);
// Release the waiting non-tx op first, on secondary
execute(secondary, new SerializableCallable() {
@Override
public Object call() throws Exception {
Runnable r = DistTXState.internalBeforeNonTXBasicPut;
assert (r != null && r instanceof WaitRelease);
WaitRelease e = (WaitRelease) r;
e.release();
return null;
}
});
// Now release the waiting commit on secondary
execute(secondary, new SerializableCallable() {
@Override
public Object call() throws Exception {
Runnable r = DistTXState.internalBeforeApplyChanges;
assert (r != null && r instanceof WaitRelease);
WaitRelease e = (WaitRelease) r;
e.release();
return null;
}
});
// Verify region and entry versions on primary and secondary
SerializableCallable verifyPrimary = new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custId = new CustId(1);
Customer customer = prRegion.get(custId);
BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custId);
RegionEntry re = br.getRegionEntry(custId);
getGemfireCache().getLoggerI18n().fine("TEST:TX PRIMARY CUSTOMER=" + customer);
getGemfireCache().getLoggerI18n().fine("TEST:TX PRIMARY REGION VERSION=" + re.getVersionStamp().getRegionVersion());
getGemfireCache().getLoggerI18n().fine("TEST:TX PRIMARY ENTRY VERSION=" + re.getVersionStamp().getEntryVersion());
return null;
}
};
execute(primary, verifyPrimary);
SerializableCallable verifySecondary = new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<CustId, Customer> prRegion = getCache().getRegion(PERSISTENT_CUSTOMER_PR);
CustId custId = new CustId(1);
Customer customer = prRegion.get(custId);
BucketRegion br = ((PartitionedRegion) prRegion).getBucketRegion(custId);
RegionEntry re = br.getRegionEntry(custId);
getGemfireCache().getLoggerI18n().fine("TEST:TX SECONDARY CUSTOMER=" + customer);
getGemfireCache().getLoggerI18n().fine("TEST:TX SECONDARY REGION VERSION=" + re.getVersionStamp().getRegionVersion());
getGemfireCache().getLoggerI18n().fine("TEST:TX SECONDARY ENTRY VERSION=" + re.getVersionStamp().getEntryVersion());
return null;
}
};
execute(secondary, verifySecondary);
}
use of org.apache.geode.internal.cache.RegionEntry in project geode by apache.
the class ClientsWithVersioningRetryDUnitTest method testRetryPutAll.
/**
* Test that we can successfully retry a distributed put all and get the version information. bug
* #45059
*/
@Test
public void testRetryPutAll() {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
final VM vm3 = host.getVM(3);
createServerRegion(vm0, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
// Make sure the bucket 0 is primary in this member.
Region region = getCache().getRegion("region");
region.put(0, "value");
// Add a listener to close vm1 when we send a distributed put all operation
// this will cause a retry after we have applied the original put all to
// the cache, causing a retry
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage msg) {
if (msg instanceof DistributedPutAllOperation.PutAllMessage) {
DistributionMessageObserver.setInstance(null);
disconnectFromDS(vm1);
}
}
});
}
});
int port1 = createServerRegion(vm1, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
int port2 = createServerRegion(vm2, RegionShortcut.PARTITION_REDUNDANT_PERSISTENT);
createClientRegion(vm3, port1, port2);
// This will be a put all to bucket 0
// Here's the expected sequence
// client->vm1 (accessor0)
// vm1->vm0
// vm0 will kill vm1
// vm0->vm2
// client will retry the putall
vm3.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region region = getCache().getRegion("region");
Map map = new HashMap();
map.put(0, "a");
map.put(113, "b");
region.putAll(map);
RegionEntry entry = ((LocalRegion) region).getRegionEntry(0);
assertNotNull(entry);
assertNotNull(entry.getVersionStamp());
assertEquals(2, entry.getVersionStamp().getEntryVersion());
return null;
}
});
// Verify the observer was triggered
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
// if the observer was triggered, it would have cleared itself
assertNull(DistributionMessageObserver.getInstance());
}
});
// Make sure vm1 did in fact shut down
vm1.invoke(new SerializableRunnable() {
@Override
public void run() {
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
assertTrue(cache == null || cache.isClosed());
}
});
}
Aggregations