use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class ClientServerTransactionDUnitTest method testTXStateCleanedUpIfJTABeforeCompletionFailedOnClient.
@Test
public void testTXStateCleanedUpIfJTABeforeCompletionFailedOnClient() {
int copies = 1;
int totalBuckets = 1;
Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM client1 = host.getVM(2);
String regionName = "aRegion";
final int port1 = createRegionsAndStartServer(server1, false);
// Create PR
server1.invoke(() -> {
createSubscriptionRegion(false, regionName, copies, totalBuckets);
Region r = getCache().getRegion(regionName);
r.put(key1, v1);
});
createRegionsAndStartServer(server2, false);
server2.invoke(() -> createSubscriptionRegion(false, regionName, copies, totalBuckets));
// Create client 1
client1.invoke(() -> createClient(port1, regionName));
client1.invoke(() -> verifyClientCacheData(regionName));
client1.invoke(new SerializableCallable() {
public Object call() throws Exception {
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
Thread t1 = new Thread(new Runnable() {
public void run() {
doJTATx1(regionName, latch1, latch2);
}
});
t1.start();
doJTATx2(regionName, latch1, latch2);
t1.join();
Region r = getClientRegion(regionName);
assertTrue("region data has been changed", r.get(key1).equals(v1));
return null;
}
});
final DistributedMember clientId = (DistributedMember) client1.invoke(getClientDM());
server1.invoke(() -> verifyTXStateEmpty(clientId));
server2.invoke(() -> verifyTXStateEmpty(clientId));
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class ClientServerTransactionDUnitTest method testCleanupAfterClientAndProxyFailure.
@Test
public void testCleanupAfterClientAndProxyFailure() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore = host.getVM(1);
final boolean cachingProxy = false;
// some other VMs seem to be hanging around and have the region this
disconnectAllFromDS();
// tests uses
final int port1 = createRegionsAndStartServerWithTimeout(accessor, true, 5);
createRegionOnServerWithTimeout(datastore, false, false, 5);
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true");
ClientCacheFactory ccf = new ClientCacheFactory();
setCCF(port1, ccf);
ClientCache cCache = getClientCache(ccf);
ClientRegionFactory<CustId, Customer> custrf = cCache.createClientRegionFactory(cachingProxy ? ClientRegionShortcut.CACHING_PROXY : ClientRegionShortcut.PROXY);
ClientRegionFactory<Integer, String> refrf = cCache.createClientRegionFactory(cachingProxy ? ClientRegionShortcut.CACHING_PROXY : ClientRegionShortcut.PROXY);
Region<Integer, String> r = refrf.create(D_REFERENCE);
Region<CustId, Customer> pr = custrf.create(CUSTOMER);
TXManagerImpl mgr = getGemfireCache().getTxManager();
mgr.begin();
doTxOps(r, pr);
final DistributedMember myId = cCache.getDistributedSystem().getDistributedMember();
SerializableCallable verifyExists = new SerializableCallable("verify txstate for client exists") {
public Object call() throws Exception {
TXManagerImpl txmgr = getGemfireCache().getTxManager();
Set states = txmgr.getTransactionsForClient((InternalDistributedMember) myId);
// only one in-progress transaction
assertEquals(1, states.size());
return null;
}
};
accessor.invoke(verifyExists);
datastore.invoke(verifyExists);
accessor.invoke(() -> closeCache());
accessor.invoke(() -> disconnectFromDS());
SerializableCallable verifyExpired = new SerializableCallable("verify txstate is expired") {
public Object call() throws Exception {
final TXManagerImpl txmgr = getGemfireCache().getTxManager();
return verifyTXStateExpired(myId, txmgr);
}
};
try {
datastore.invoke(verifyExpired);
} finally {
cCache.close();
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PartitionedRegionHAFailureAndRecoveryDUnitTest method testMetaDataCleanupOnSinglePRNodeFail.
/**
* Test for PartitionedRegion metadata cleanup for single node failure. <br>
* <u>This test does the following:<u></br>
* <br>
* (1)Creates 4 Vms </br>
* <br>
* (2)Randomly create different number of PartitionedRegion on all 4 VMs</br>
* <br>
* (3)Disconenct vm0 from the distributed system</br>
* <br>
* (4) Validate Failed node's config metadata </br>
* <br>
* (5) Validate Failed node's bucket2Node Region metadata. </br>
*/
@Test
public void testMetaDataCleanupOnSinglePRNodeFail() throws Exception {
// create the VM's
createVMs();
// create the partitionedRegion on diffrent nodes.
final int startIndexForRegion = 0;
final int endIndexForRegion = 4;
final int localMaxMemory = 200;
final int redundancy = 1;
createPartitionRegionAsynch("testMetaDataCleanupOnSinglePRNodeFail_", startIndexForRegion, endIndexForRegion, localMaxMemory, redundancy, -1);
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnSinglePRNodeFail() - PartitionedRegion's created at all VM nodes");
// Add a listener to the config meta data
addConfigListeners();
// disconnect vm0.
DistributedMember dsMember = (DistributedMember) vmArr[0].invoke(() -> disconnectMethod());
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnSinglePRNodeFail() - VM = " + dsMember + " disconnected from the distributed system ");
// validate that the metadata clean up is done at all the VM's.
vmArr[1].invoke(validateNodeFailMetaDataCleanUp(dsMember));
vmArr[2].invoke(validateNodeFailMetaDataCleanUp(dsMember));
vmArr[3].invoke(validateNodeFailMetaDataCleanUp(dsMember));
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnSinglePRNodeFail() - Validation of Failed node config metadata complete");
// validate that bucket2Node clean up is done at all the VM's.
vmArr[1].invoke(validateNodeFailbucket2NodeCleanUp(dsMember));
vmArr[2].invoke(validateNodeFailbucket2NodeCleanUp(dsMember));
vmArr[3].invoke(validateNodeFailbucket2NodeCleanUp(dsMember));
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnSinglePRNodeFail() - Validation of Failed node bucket2Node Region metadata complete");
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnSinglePRNodeFail() Completed Successfully ..........");
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PartitionedRegionHAFailureAndRecoveryDUnitTest method testMetaDataCleanupOnMultiplePRNodeFail.
/**
* Test for PartitionedRegion metadata cleanup for multiple node failure. <br>
* <u>This test does the following:<u></br>
* <br>
* (1)Creates 4 Vms </br>
* <br>
* (2)Randomly create different number of PartitionedRegion on all 4 VMs</br>
* <br>
* (3) Disconenct vm0 and vm1 from the distributed system</br>
* <br>
* (4) Validate all Failed node's config metadata </br>
* <br>
* (5) Validate all Failed node's bucket2Node Region metadata. </br>
*/
@Test
public void testMetaDataCleanupOnMultiplePRNodeFail() throws Exception {
// create the VM's
createVMs();
// create the partitionedRegion on diffrent nodes.
final int startIndexForRegion = 0;
final int endIndexForRegion = 4;
final int localMaxMemory = 200;
final int redundancy = 1;
createPartitionRegionAsynch("testMetaDataCleanupOnMultiplePRNodeFail_", startIndexForRegion, endIndexForRegion, localMaxMemory, redundancy, -1);
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnMultiplePRNodeFail() - PartitionedRegion's created at all VM nodes");
addConfigListeners();
// disconnect vm0
DistributedMember dsMember = (DistributedMember) vmArr[0].invoke(() -> disconnectMethod());
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnMultiplePRNodeFail() - VM = " + dsMember + " disconnected from the distributed system ");
// validate that the metadata clean up is done at all the VM's for first
// failed node.
vmArr[1].invoke(validateNodeFailMetaDataCleanUp(dsMember));
vmArr[2].invoke(validateNodeFailMetaDataCleanUp(dsMember));
vmArr[3].invoke(validateNodeFailMetaDataCleanUp(dsMember));
// validate that bucket2Node clean up is done at all the VM's for all failed
// nodes.
vmArr[1].invoke(validateNodeFailbucket2NodeCleanUp(dsMember));
vmArr[2].invoke(validateNodeFailbucket2NodeCleanUp(dsMember));
vmArr[3].invoke(validateNodeFailbucket2NodeCleanUp(dsMember));
// Clear state of listener, skipping the vmArr[0] which was disconnected
VM[] vmsToClear = new VM[] { vmArr[1], vmArr[2], vmArr[3] };
clearConfigListenerState(vmsToClear);
// disconnect vm1
DistributedMember dsMember2 = (DistributedMember) vmArr[1].invoke(() -> disconnectMethod());
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnMultiplePRNodeFail() - VM = " + dsMember2 + " disconnected from the distributed system ");
// validate that the metadata clean up is done at all the VM's for first
// failed node.
vmArr[2].invoke(validateNodeFailMetaDataCleanUp(dsMember));
vmArr[3].invoke(validateNodeFailMetaDataCleanUp(dsMember));
// validate that the metadata clean up is done at all the VM's for second
// failed node.
vmArr[2].invoke(validateNodeFailMetaDataCleanUp(dsMember2));
vmArr[3].invoke(validateNodeFailMetaDataCleanUp(dsMember2));
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnMultiplePRNodeFail() - Validation of Failed nodes config metadata complete");
vmArr[2].invoke(validateNodeFailbucket2NodeCleanUp(dsMember2));
vmArr[3].invoke(validateNodeFailbucket2NodeCleanUp(dsMember2));
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnMultiplePRNodeFail() - Validation of Failed nodes bucket2Node Region metadata complete");
LogWriterUtils.getLogWriter().info("testMetaDataCleanupOnMultiplePRNodeFail() Completed Successfully ..........");
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class RollbackFunction method execute.
public void execute(FunctionContext context) {
Cache cache = CacheFactory.getAnyInstance();
TXId txId = null;
try {
txId = (TXId) context.getArguments();
} catch (ClassCastException e) {
logger.info("RollbackFunction should be invoked with a TransactionId as an argument i.e. setArguments(txId).execute(function)");
throw e;
}
DistributedMember member = txId.getMemberId();
Boolean result = false;
final boolean isDebugEnabled = logger.isDebugEnabled();
if (cache.getDistributedSystem().getDistributedMember().equals(member)) {
if (isDebugEnabled) {
logger.debug("RollbackFunction: for transaction: {} rolling back locally", txId);
}
CacheTransactionManager txMgr = cache.getCacheTransactionManager();
if (txMgr.tryResume(txId)) {
if (isDebugEnabled) {
logger.debug("RollbackFunction: resumed transaction: {}", txId);
}
txMgr.rollback();
result = true;
}
} else {
ArrayList args = new ArrayList();
args.add(txId);
args.add(NestedTransactionFunction.ROLLBACK);
Execution ex = FunctionService.onMember(member).setArguments(args);
if (isDebugEnabled) {
logger.debug("RollbackFunction: for transaction: {} executing NestedTransactionFunction on member: {}", txId, member);
}
try {
List list = (List) ex.execute(new NestedTransactionFunction()).getResult();
result = (Boolean) list.get(0);
} catch (FunctionException fe) {
throw new TransactionDataNodeHasDepartedException("Could not Rollback on member:" + member);
}
}
if (isDebugEnabled) {
logger.debug("RollbackFunction: for transaction: {} returning result: {}", txId, result);
}
context.getResultSender().lastResult(result);
}
Aggregations