Search in sources :

Example 1 with DistTxPrecommitResponse

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;
}
Also used : ArrayList(java.util.ArrayList) DM(org.apache.geode.distributed.internal.DM) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) DistTxPrecommitResponse(org.apache.geode.internal.cache.DistTXPrecommitMessage.DistTxPrecommitResponse) TreeSet(java.util.TreeSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) DistTxThinEntryState(org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 UnsupportedOperationInTransactionException (org.apache.geode.cache.UnsupportedOperationInTransactionException)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 DM (org.apache.geode.distributed.internal.DM)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 DistTxPrecommitResponse (org.apache.geode.internal.cache.DistTXPrecommitMessage.DistTxPrecommitResponse)1 DistTxThinEntryState (org.apache.geode.internal.cache.TXEntryState.DistTxThinEntryState)1