use of org.apache.geode.internal.cache.DistTXPrecommitMessage.DistTxPrecommitResponse in project geode by apache.
the class DistTXStateProxyImplOnCoordinator method doPrecommit.
private boolean doPrecommit() {
boolean finalResult = true;
final GemFireCacheImpl cache = GemFireCacheImpl.getExisting("Applying Dist TX Precommit");
final DM dm = cache.getDistributionManager();
Set<DistributedMember> txRemoteParticpants = getTxRemoteParticpants(dm);
// create processor and precommit message
DistTXPrecommitMessage.DistTxPrecommitReplyProcessor processor = new DistTXPrecommitMessage.DistTxPrecommitReplyProcessor(this.getTxId(), dm, txRemoteParticpants, target2realDeals);
// TODO [DISTTX} whats ack threshold?
processor.enableSevereAlertProcessing();
final DistTXPrecommitMessage precommitMsg = new DistTXPrecommitMessage(this.getTxId(), this.onBehalfOfClientMember, processor);
// send precommit message to remote nodes
for (DistributedMember remoteNode : txRemoteParticpants) {
DistTXCoordinatorInterface remoteTXStateStub = target2realDeals.get(remoteNode);
if (remoteTXStateStub.isTxState()) {
throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistPeerTXStateStub", remoteTXStateStub.getClass().getSimpleName()));
}
try {
remoteTXStateStub.setPrecommitMessage(precommitMsg, dm);
remoteTXStateStub.precommit();
} finally {
remoteTXStateStub.setPrecommitMessage(null, null);
}
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit Sent Message to target = " + remoteNode);
}
}
// Do precommit on local node
TreeSet<String> sortedRegionName = new TreeSet<>();
DistTXCoordinatorInterface localTXState = target2realDeals.get(dm.getId());
if (localTXState != null) {
if (!localTXState.isTxState()) {
throw new UnsupportedOperationInTransactionException(LocalizedStrings.DISTTX_TX_EXPECTED.toLocalizedString("DistTXStateOnCoordinator", localTXState.getClass().getSimpleName()));
}
localTXState.precommit();
boolean localResult = localTXState.getPreCommitResponse();
TreeMap<String, ArrayList<DistTxThinEntryState>> entryStateSortedMap = new TreeMap<String, ArrayList<DistTxThinEntryState>>();
ArrayList<ArrayList<DistTxThinEntryState>> entryEventList = null;
if (localResult) {
localResult = ((DistTXStateOnCoordinator) localTXState).populateDistTxEntryStateList(entryStateSortedMap);
if (localResult) {
entryEventList = new ArrayList<ArrayList<DistTxThinEntryState>>(entryStateSortedMap.values());
populateEntryEventMap(dm.getId(), entryEventList, sortedRegionName);
}
}
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit local = " + dm.getId() + " ,entryEventList=" + printEntryEventList(entryEventList) + " ,txRegionVersionsMap=" + printEntryEventMap(this.txEntryEventMap) + " ,result= " + localResult + " ,finalResult-old= " + finalResult);
}
finalResult = finalResult && localResult;
}
/*
* [DISTTX] TODO Any test hooks
*/
// if (internalAfterIndividualSend != null) {
// internalAfterIndividualSend.run();
// }
/*
* [DISTTX] TODO see how to handle exception
*/
/*
* [DISTTX] TODO Any test hooks
*/
// if (internalAfterIndividualCommitProcess != null) {
// // Testing callback
// internalAfterIndividualCommitProcess.run();
// }
{
// Wait for results
dm.getCancelCriterion().checkCancelInProgress(null);
processor.waitForPrecommitCompletion();
// [DISTTX} TODO Handle stats
// dm.getStats().incCommitWaits();
Map<DistributedMember, DistTxPrecommitResponse> remoteResults = processor.getCommitResponseMap();
for (Entry<DistributedMember, DistTxPrecommitResponse> e : remoteResults.entrySet()) {
DistributedMember target = e.getKey();
DistTxPrecommitResponse remoteResponse = e.getValue();
ArrayList<ArrayList<DistTxThinEntryState>> entryEventList = remoteResponse.getDistTxEntryEventList();
populateEntryEventMap(target, entryEventList, sortedRegionName);
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit got reply from target = " + target + " ,sortedRegions" + sortedRegionName + " ,entryEventList=" + printEntryEventList(entryEventList) + " ,txEntryEventMap=" + printEntryEventMap(this.txEntryEventMap) + " ,result= " + remoteResponse.getCommitState() + " ,finalResult-old= " + finalResult);
}
finalResult = finalResult && remoteResponse.getCommitState();
}
}
if (logger.isDebugEnabled()) {
logger.debug("DistTXStateProxyImplOnCoordinator.doPrecommit finalResult= " + finalResult);
}
return finalResult;
}
Aggregations